Move category management back into the view manager
svn: r16137
This commit is contained in:
parent
b19e7ad8a0
commit
43d97cbd44
@ -79,9 +79,9 @@ def url(link, uistate=None):
|
||||
Open the specified URL in a browser.
|
||||
"""
|
||||
if uistate and config.get('htmlview.url-handler'):
|
||||
if 'Web' in uistate.viewmanager.get_categories():
|
||||
uistate.viewmanager.goto_category('Web')
|
||||
page = uistate.viewmanager.get_category_page('Web')
|
||||
cat_num = uistate.viewmanager.get_category('Web')
|
||||
if cat_num is not None:
|
||||
page = uistate.viewmanager.goto_page(cat_num, None)
|
||||
page.open(link)
|
||||
return
|
||||
if not run_file(link):
|
||||
|
@ -110,19 +110,12 @@ class Sidebar(object):
|
||||
menu_item.connect('activate', self.cb_menu_activate, index)
|
||||
menu_item.show()
|
||||
|
||||
def loaded(self):
|
||||
"""
|
||||
Called after all the sidebar plugins have been loaded.
|
||||
"""
|
||||
for page in self.pages:
|
||||
page[1].loaded()
|
||||
|
||||
def view_changed(self, page_num):
|
||||
def view_changed(self, cat_num, view_num):
|
||||
"""
|
||||
Called when a Gramps view is changed.
|
||||
"""
|
||||
for page in self.pages:
|
||||
page[1].view_changed(page_num)
|
||||
page[1].view_changed(cat_num, view_num)
|
||||
|
||||
def __menu_button_pressed(self, button, event):
|
||||
"""
|
||||
|
@ -266,14 +266,17 @@ class ViewManager(CLIManager):
|
||||
|
||||
#set pluginmanager to GUI one
|
||||
self._pmgr = GuiPluginManager.get_instance()
|
||||
self.active_page = None
|
||||
self.pages = []
|
||||
self.merge_ids = []
|
||||
self.toolactions = None
|
||||
self.tool_menu_ui_id = None
|
||||
self.reportactions = None
|
||||
self.report_menu_ui_id = None
|
||||
self.category_manager = None
|
||||
|
||||
self.active_page = None
|
||||
self.pages = []
|
||||
self.page_lookup = {}
|
||||
self.views = None
|
||||
self.current_views = [] # The current view in each category
|
||||
|
||||
self.show_sidebar = config.get('interface.view')
|
||||
self.show_toolbar = config.get('interface.toolbar-on')
|
||||
@ -519,7 +522,7 @@ class ViewManager(CLIManager):
|
||||
|
||||
self.notebook = gtk.Notebook()
|
||||
self.notebook.set_scrollable(True)
|
||||
self.notebook.set_show_tabs(False)
|
||||
self.notebook.set_show_tabs(True)
|
||||
self.notebook.show()
|
||||
self.__init_lists()
|
||||
self.__build_ui_manager()
|
||||
@ -641,13 +644,6 @@ class ViewManager(CLIManager):
|
||||
self.window.connect('delete-event', self.quit)
|
||||
self.notebook.connect('switch-page', self.view_changed)
|
||||
|
||||
def view_changed(self, notebook, page, page_num):
|
||||
"""
|
||||
Called when the notebook page is changed.
|
||||
"""
|
||||
self.sidebar.view_changed(page_num)
|
||||
self.__change_page(page_num)
|
||||
|
||||
def __init_lists(self):
|
||||
"""
|
||||
Initialize the actions lists for the UIManager
|
||||
@ -803,8 +799,9 @@ class ViewManager(CLIManager):
|
||||
|
||||
def init_interface(self):
|
||||
"""
|
||||
Initialize the interface, creating the pages as given in vieworder
|
||||
Initialize the interface.
|
||||
"""
|
||||
self.__init_views()
|
||||
self.__load_sidebar_plugins()
|
||||
|
||||
if not self.file_loaded:
|
||||
@ -840,7 +837,6 @@ class ViewManager(CLIManager):
|
||||
Showing the main window is deferred so that
|
||||
ArgHandler can work without it always shown
|
||||
"""
|
||||
self.sidebar.loaded()
|
||||
self.window.show()
|
||||
if not self.dbstate.db.is_open() and show_manager:
|
||||
self.__open_activate(None)
|
||||
@ -1040,7 +1036,53 @@ class ViewManager(CLIManager):
|
||||
config.set('interface.fullscreen', False)
|
||||
config.save()
|
||||
|
||||
def create_page(self, pdata, page_def, show_page=True):
|
||||
def __init_views(self):
|
||||
"""
|
||||
Read the view definitions and display the default view.
|
||||
"""
|
||||
self.views = get_available_views()
|
||||
defaults = views_to_show(self.views,
|
||||
config.get('preferences.use-last-view'))
|
||||
self.current_views = defaults[2]
|
||||
self.goto_page(defaults[0], defaults[1])
|
||||
|
||||
def get_views(self):
|
||||
"""
|
||||
Return the view definitions.
|
||||
"""
|
||||
return self.views
|
||||
|
||||
def goto_page(self, cat_num, view_num):
|
||||
"""
|
||||
Create the page if it doesn't exist and make it the current page.
|
||||
"""
|
||||
if view_num is None:
|
||||
view_num = self.current_views[cat_num]
|
||||
else:
|
||||
self.current_views[cat_num] = view_num
|
||||
|
||||
page_num = self.page_lookup.get((cat_num, view_num))
|
||||
if page_num is None:
|
||||
page_def = self.views[cat_num][view_num]
|
||||
self.page_lookup[(cat_num, view_num)] = self.notebook.get_n_pages()
|
||||
self.__create_page(page_def[0], page_def[1])
|
||||
else:
|
||||
self.notebook.set_current_page(page_num)
|
||||
|
||||
if page_num:
|
||||
return self.pages[page_num]
|
||||
|
||||
def get_category(self, cat_name):
|
||||
"""
|
||||
Return the category number from the given category name.
|
||||
"""
|
||||
print ("get_category", cat_name)
|
||||
for cat_num, cat_views in enumerate(self.views):
|
||||
if cat_name == cat_views[0][0].category[1]:
|
||||
return cat_num
|
||||
return None
|
||||
|
||||
def __create_page(self, pdata, page_def):
|
||||
"""
|
||||
Create a new page and set it as the current page.
|
||||
"""
|
||||
@ -1080,48 +1122,30 @@ class ViewManager(CLIManager):
|
||||
hbox.show_all()
|
||||
page_num = self.notebook.append_page(page_display,
|
||||
hbox)
|
||||
if show_page:
|
||||
self.notebook.set_current_page(page_num)
|
||||
|
||||
def register_category_manager(self, manager):
|
||||
def view_changed(self, notebook, page, page_num):
|
||||
"""
|
||||
Register a category manager with the view manager.
|
||||
Called when the notebook page is changed.
|
||||
"""
|
||||
self.category_manager = manager
|
||||
cat_num = view_num = None
|
||||
for key in self.page_lookup:
|
||||
if self.page_lookup[key] == page_num:
|
||||
cat_num, view_num = key
|
||||
break
|
||||
|
||||
def goto_category(self, category):
|
||||
"""
|
||||
Ask the category manager to go to a page. Returns success
|
||||
status.
|
||||
"""
|
||||
if self.category_manager:
|
||||
return self.category_manager.goto_category(category)
|
||||
return False
|
||||
# Save last view in configuration
|
||||
view_id = self.views[cat_num][view_num][0].id
|
||||
config.set('preferences.last-view', view_id)
|
||||
last_views = config.get('preferences.last-views')
|
||||
if len(last_views) != len(self.views):
|
||||
# If the number of categories has changed then reset the defaults
|
||||
last_views = [''] * len(self.views)
|
||||
last_views[cat_num] = view_id
|
||||
config.set('preferences.last-views', last_views)
|
||||
config.save()
|
||||
|
||||
def get_categories(self):
|
||||
"""
|
||||
Return available categories.
|
||||
"""
|
||||
if self.category_manager:
|
||||
return self.category_manager.get_categories()
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_category_page(self, category):
|
||||
"""
|
||||
External API for switching to a category page. Returns
|
||||
success status.
|
||||
"""
|
||||
if self.category_manager:
|
||||
return self.category_manager.get_category_page(category)
|
||||
else:
|
||||
return None
|
||||
|
||||
def goto_page(self, page_num):
|
||||
"""
|
||||
Change the current page.
|
||||
"""
|
||||
self.notebook.set_current_page(page_num)
|
||||
self.sidebar.view_changed(cat_num, view_num)
|
||||
self.__change_page(page_num)
|
||||
|
||||
def __change_page(self, page_num):
|
||||
"""
|
||||
@ -1142,12 +1166,6 @@ class ViewManager(CLIManager):
|
||||
|
||||
self.active_page.change_page()
|
||||
|
||||
def get_n_pages(self):
|
||||
"""
|
||||
Return the total number of pages.
|
||||
"""
|
||||
return self.notebook.get_n_pages()
|
||||
|
||||
def __delete_pages(self):
|
||||
"""
|
||||
Calls on_delete() for each view
|
||||
|
@ -85,35 +85,22 @@ class CategorySidebar(BaseSidebar):
|
||||
|
||||
self.viewmanager = uistate.viewmanager
|
||||
|
||||
self.categories = {}
|
||||
self.buttons = []
|
||||
self.button_handlers = []
|
||||
|
||||
self.window = gtk.ScrolledWindow()
|
||||
self.pages = {}
|
||||
self.page_defs = {}
|
||||
|
||||
self.ui_category = {}
|
||||
self.view_toggle_actions = {}
|
||||
self.cat_view_group = None
|
||||
self.merge_ids = []
|
||||
|
||||
self.window = gtk.ScrolledWindow()
|
||||
vbox = gtk.VBox()
|
||||
self.window.add_with_viewport(vbox)
|
||||
self.window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
|
||||
self.window.show()
|
||||
|
||||
self.views = get_available_views()
|
||||
defaults = views_to_show(self.views,
|
||||
config.get('preferences.use-last-view'))
|
||||
self.current_views = defaults[2]
|
||||
|
||||
# Let the view manager know what is responsible for
|
||||
# switching categories:
|
||||
self.viewmanager.register_category_manager(self)
|
||||
|
||||
use_text = config.get('interface.sidebar-text')
|
||||
for cat_num, cat_views in enumerate(self.views):
|
||||
for cat_num, cat_views in enumerate(self.viewmanager.get_views()):
|
||||
uimenuitems = ''
|
||||
uitoolitems = ''
|
||||
self.view_toggle_actions[cat_num] = []
|
||||
@ -135,9 +122,6 @@ class CategorySidebar(BaseSidebar):
|
||||
button.connect('drag_motion', self.cb_switch_page_on_dnd,
|
||||
cat_num)
|
||||
vbox.show_all()
|
||||
self.categories[category] = cat_num
|
||||
|
||||
self.page_defs[(cat_num, view_num)] = page
|
||||
|
||||
pageid = (page[0].id + '_%i' % view_num)
|
||||
uimenuitems += '\n<menuitem action="%s"/>' % pageid
|
||||
@ -166,35 +150,10 @@ class CategorySidebar(BaseSidebar):
|
||||
"""
|
||||
return self.window
|
||||
|
||||
def loaded(self):
|
||||
"""
|
||||
Open the default view after all the sidebar plugins have been loaded.
|
||||
"""
|
||||
defaults = views_to_show(self.views,
|
||||
config.get('preferences.use-last-view'))
|
||||
self.__category_clicked(self.buttons[defaults[0]], defaults[0])
|
||||
|
||||
def view_changed(self, page_num):
|
||||
def view_changed(self, cat_num, view_num):
|
||||
"""
|
||||
Called when the active view is changed.
|
||||
"""
|
||||
cat_num = view_num = None
|
||||
for key in self.pages:
|
||||
if self.pages[key] == page_num:
|
||||
cat_num, view_num = key
|
||||
break
|
||||
|
||||
# Save last view in configuration
|
||||
view_id = self.views[cat_num][view_num][0].id
|
||||
config.set('preferences.last-view', view_id)
|
||||
last_views = config.get('preferences.last-views')
|
||||
if len(last_views) != len(self.views):
|
||||
# If the number of categories has changed then reset the defaults
|
||||
last_views = [''] * len(self.views)
|
||||
last_views[cat_num] = view_id
|
||||
config.set('preferences.last-views', last_views)
|
||||
config.save()
|
||||
|
||||
# Add buttons to the toolbar for the different view in the category
|
||||
uimanager = self.viewmanager.uimanager
|
||||
if self.cat_view_group:
|
||||
@ -222,39 +181,6 @@ class CategorySidebar(BaseSidebar):
|
||||
button.set_active(False)
|
||||
self.__handlers_unblock()
|
||||
|
||||
def goto_category(self, category):
|
||||
"""
|
||||
External API for switching to a category page. Returns
|
||||
success status.
|
||||
"""
|
||||
if category in self.categories:
|
||||
index = self.categories[category]
|
||||
self.__category_clicked(None, index)
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_category_page(self, category):
|
||||
"""
|
||||
External API for getting a page. Creates it if necessary.
|
||||
"""
|
||||
if category not in self.categories:
|
||||
return None
|
||||
cat_num = self.categories[category]
|
||||
view_num = self.current_views[cat_num]
|
||||
page_num = self.pages.get((cat_num, view_num))
|
||||
page = self.page_defs[(cat_num, view_num)]
|
||||
if page_num is None:
|
||||
self.pages[(cat_num, view_num)] = self.viewmanager.get_n_pages()
|
||||
self.viewmanager.create_page(page[0], page[1], show_page=False)
|
||||
page_num = self.pages.get((cat_num, view_num))
|
||||
return self.viewmanager.pages[page_num]
|
||||
|
||||
def get_categories(self):
|
||||
"""
|
||||
External API for providing available categories.
|
||||
"""
|
||||
return self.categories.keys()
|
||||
|
||||
def __handlers_block(self):
|
||||
"""
|
||||
Block signals to the buttons to prevent spurious events.
|
||||
@ -274,34 +200,19 @@ class CategorySidebar(BaseSidebar):
|
||||
Called when a button causes a view change.
|
||||
"""
|
||||
view_num = radioaction.get_current_value()
|
||||
self.__goto_page(cat_num, view_num)
|
||||
self.viewmanager.goto_page(cat_num, view_num)
|
||||
|
||||
def __category_clicked(self, button, cat_num):
|
||||
"""
|
||||
Called when a button causes a category change.
|
||||
"""
|
||||
view_num = self.current_views[cat_num]
|
||||
self.__goto_page(cat_num, view_num)
|
||||
self.viewmanager.goto_page(cat_num, None)
|
||||
|
||||
# If the click is on the same view we're in,
|
||||
# restore the button state to active
|
||||
if button and not button.get_active():
|
||||
button.set_active(True)
|
||||
|
||||
def __goto_page(self, cat_num, view_num):
|
||||
"""
|
||||
Create the page if it doesn't exist and make it the current page.
|
||||
"""
|
||||
self.current_views[cat_num] = view_num
|
||||
|
||||
page_num = self.pages.get((cat_num, view_num))
|
||||
if page_num is None:
|
||||
page = self.page_defs[(cat_num, view_num)]
|
||||
self.pages[(cat_num, view_num)] = self.viewmanager.get_n_pages()
|
||||
self.viewmanager.create_page(page[0], page[1])
|
||||
else:
|
||||
self.viewmanager.goto_page(page_num)
|
||||
|
||||
def __make_sidebar_button(self, use_text, index, page_title, page_stock):
|
||||
"""
|
||||
Create the sidebar button. The page_title is the text associated with
|
||||
|
@ -40,16 +40,16 @@ menu_label = _('Category'),
|
||||
order = START
|
||||
)
|
||||
|
||||
register(SIDEBAR,
|
||||
id = 'historysidebar',
|
||||
name = _("History Sidebar"),
|
||||
description = _("A sidebar to display the history"),
|
||||
version = '1.0',
|
||||
gramps_target_version = '3.3',
|
||||
status = STABLE,
|
||||
fname = 'historysidebar.py',
|
||||
authors = [u"Nick Hall"],
|
||||
authors_email = ["nick__hall@hotmail.com"],
|
||||
sidebarclass = 'HistorySidebar',
|
||||
menu_label = _('History')
|
||||
)
|
||||
#register(SIDEBAR,
|
||||
#id = 'historysidebar',
|
||||
#name = _("History Sidebar"),
|
||||
#description = _("A sidebar to display the history"),
|
||||
#version = '1.0',
|
||||
#gramps_target_version = '3.3',
|
||||
#status = STABLE,
|
||||
#fname = 'historysidebar.py',
|
||||
#authors = [u"Nick Hall"],
|
||||
#authors_email = ["nick__hall@hotmail.com"],
|
||||
#sidebarclass = 'HistorySidebar',
|
||||
#menu_label = _('History')
|
||||
#)
|
||||
|
Loading…
Reference in New Issue
Block a user