Updates to navigation sidebar
svn: r21104
This commit is contained in:
parent
c081c5f6f5
commit
d3f8f73180
@ -42,3 +42,15 @@ class BaseSidebar(object):
|
|||||||
Called when the active view is changed.
|
Called when the active view is changed.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def active(self, cat_num, view_num):
|
||||||
|
"""
|
||||||
|
Called when the sidebar is made visible.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def inactive(self):
|
||||||
|
"""
|
||||||
|
Called when the sidebar is hidden.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id: navigator.py 20492 2012-10-02 21:08:19Z nick-h $
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A module that provides pluggable sidebars. These provide an interface to
|
A module that provides pluggable sidebars. These provide an interface to
|
||||||
@ -29,6 +29,7 @@ manage pages in the main Gramps window.
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
from gi.repository import Gdk
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -36,6 +37,38 @@ from gi.repository import Gtk
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gen.plug import (START, END)
|
from gramps.gen.plug import (START, END)
|
||||||
|
from .pluginmanager import GuiPluginManager
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Constants
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
UICATEGORY = '''<ui>
|
||||||
|
<menubar name="MenuBar">
|
||||||
|
<menu action="ViewMenu">
|
||||||
|
<placeholder name="ViewsInCategory">%s
|
||||||
|
</placeholder>
|
||||||
|
</menu>
|
||||||
|
</menubar>
|
||||||
|
</ui>
|
||||||
|
'''
|
||||||
|
|
||||||
|
CATEGORY_ICON = {
|
||||||
|
'Dashboard': 'gramps-gramplet',
|
||||||
|
'People': 'gramps-person',
|
||||||
|
'Relationships': 'gramps-relation',
|
||||||
|
'Families': 'gramps-family',
|
||||||
|
'Events': 'gramps-event',
|
||||||
|
'Ancestry': 'gramps-pedigree',
|
||||||
|
'Places': 'gramps-place',
|
||||||
|
'Geography': 'gramps-geo',
|
||||||
|
'Sources': 'gramps-source',
|
||||||
|
'Repositories': 'gramps-repository',
|
||||||
|
'Media': 'gramps-media',
|
||||||
|
'Notes': 'gramps-notes',
|
||||||
|
'Citations': 'gramps-citation',
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -50,6 +83,14 @@ class Navigator(object):
|
|||||||
|
|
||||||
self.viewmanager = viewmanager
|
self.viewmanager = viewmanager
|
||||||
self.pages = []
|
self.pages = []
|
||||||
|
self.active_cat = None
|
||||||
|
self.active_view = None
|
||||||
|
|
||||||
|
self.ui_category = {}
|
||||||
|
self.view_toggle_actions = {}
|
||||||
|
self.cat_view_group = None
|
||||||
|
self.merge_ids = []
|
||||||
|
|
||||||
self.top = Gtk.VBox()
|
self.top = Gtk.VBox()
|
||||||
|
|
||||||
frame = Gtk.Frame()
|
frame = Gtk.Frame()
|
||||||
@ -92,6 +133,59 @@ class Navigator(object):
|
|||||||
self.top.show()
|
self.top.show()
|
||||||
self.top.pack_start(self.notebook, True, True, 0)
|
self.top.pack_start(self.notebook, True, True, 0)
|
||||||
|
|
||||||
|
def load_plugins(self, dbstate, uistate):
|
||||||
|
"""
|
||||||
|
Load the sidebar plugins.
|
||||||
|
"""
|
||||||
|
plugman = GuiPluginManager.get_instance()
|
||||||
|
|
||||||
|
categories = []
|
||||||
|
views = {}
|
||||||
|
for cat_num, cat_views in enumerate(self.viewmanager.get_views()):
|
||||||
|
uimenuitems = ''
|
||||||
|
self.view_toggle_actions[cat_num] = []
|
||||||
|
for view_num, page in enumerate(cat_views):
|
||||||
|
|
||||||
|
if view_num == 0:
|
||||||
|
views[cat_num] = []
|
||||||
|
cat_name = page[0].category[1]
|
||||||
|
cat_icon = CATEGORY_ICON.get(page[0].category[0])
|
||||||
|
if cat_icon is None:
|
||||||
|
cat_icon = 'gramps-view'
|
||||||
|
categories.append([cat_num, cat_name, cat_icon])
|
||||||
|
|
||||||
|
pageid = 'page_%i_%i' % (cat_num, view_num)
|
||||||
|
uimenuitems += '\n<menuitem action="%s"/>' % pageid
|
||||||
|
# id, stock, button text, UI, tooltip, page
|
||||||
|
if view_num < 9:
|
||||||
|
modifier = "<PRIMARY><ALT>%d" % ((view_num % 9) + 1)
|
||||||
|
else:
|
||||||
|
modifier = ""
|
||||||
|
|
||||||
|
stock_icon = page[0].stock_icon
|
||||||
|
if stock_icon is None:
|
||||||
|
stock_icon = cat_icon
|
||||||
|
self.view_toggle_actions[cat_num].append((pageid,
|
||||||
|
stock_icon,
|
||||||
|
page[0].name, modifier, page[0].name, view_num))
|
||||||
|
|
||||||
|
views[cat_num].append((view_num, page[0].name, stock_icon))
|
||||||
|
|
||||||
|
if len(cat_views) > 1:
|
||||||
|
#allow for switching views in a category
|
||||||
|
self.ui_category[cat_num] = UICATEGORY % uimenuitems
|
||||||
|
|
||||||
|
for pdata in plugman.get_reg_sidebars():
|
||||||
|
module = plugman.load_plugin(pdata)
|
||||||
|
if not module:
|
||||||
|
print("Error loading sidebar '%s': skipping content"
|
||||||
|
% pdata.name)
|
||||||
|
continue
|
||||||
|
|
||||||
|
sidebar_class = getattr(module, pdata.sidebarclass)
|
||||||
|
sidebar_page = sidebar_class(dbstate, uistate, categories, views)
|
||||||
|
self.add(pdata.menu_label, sidebar_page, pdata.order)
|
||||||
|
|
||||||
def get_top(self):
|
def get_top(self):
|
||||||
"""
|
"""
|
||||||
Return the top container widget for the GUI.
|
Return the top container widget for the GUI.
|
||||||
@ -121,8 +215,37 @@ class Navigator(object):
|
|||||||
"""
|
"""
|
||||||
Called when a Gramps view is changed.
|
Called when a Gramps view is changed.
|
||||||
"""
|
"""
|
||||||
for page in self.pages:
|
self.active_cat = cat_num
|
||||||
page[1].view_changed(cat_num, view_num)
|
self.active_view = view_num
|
||||||
|
|
||||||
|
# Add buttons to the menu for the different view in the category
|
||||||
|
uimanager = self.viewmanager.uimanager
|
||||||
|
if self.cat_view_group:
|
||||||
|
if self.cat_view_group in uimanager.get_action_groups():
|
||||||
|
uimanager.remove_action_group(self.cat_view_group)
|
||||||
|
|
||||||
|
list(map(uimanager.remove_ui, self.merge_ids))
|
||||||
|
|
||||||
|
if cat_num in self.ui_category:
|
||||||
|
self.cat_view_group = Gtk.ActionGroup('viewmenu')
|
||||||
|
self.cat_view_group.add_radio_actions(
|
||||||
|
self.view_toggle_actions[cat_num], value=view_num,
|
||||||
|
on_change=self.cb_view_clicked, user_data=cat_num)
|
||||||
|
self.cat_view_group.set_sensitive(True)
|
||||||
|
uimanager.insert_action_group(self.cat_view_group, 1)
|
||||||
|
mergeid = uimanager.add_ui_from_string(self.ui_category[cat_num])
|
||||||
|
self.merge_ids.append(mergeid)
|
||||||
|
|
||||||
|
# Call the view_changed method for the active sidebar
|
||||||
|
sidebar = self.pages[self.notebook.get_current_page()][1]
|
||||||
|
sidebar.view_changed(cat_num, view_num)
|
||||||
|
|
||||||
|
def cb_view_clicked(self, radioaction, current, cat_num):
|
||||||
|
"""
|
||||||
|
Called when a view is selected from the menu.
|
||||||
|
"""
|
||||||
|
view_num = radioaction.get_current_value()
|
||||||
|
self.viewmanager.goto_page(cat_num, view_num)
|
||||||
|
|
||||||
def __menu_button_pressed(self, button, event):
|
def __menu_button_pressed(self, button, event):
|
||||||
"""
|
"""
|
||||||
@ -145,7 +268,11 @@ class Navigator(object):
|
|||||||
"""
|
"""
|
||||||
Called when the user has switched to a new sidebar plugin page.
|
Called when the user has switched to a new sidebar plugin page.
|
||||||
"""
|
"""
|
||||||
if self.pages:
|
old_page = notebook.get_current_page()
|
||||||
|
if old_page != -1:
|
||||||
|
self.pages[old_page][1].inactive()
|
||||||
|
self.pages[index][1].active(self.active_cat, self.active_view)
|
||||||
|
self.pages[index][1].view_changed(self.active_cat, self.active_view)
|
||||||
self.title_label.set_text(self.pages[index][0])
|
self.title_label.set_text(self.pages[index][0])
|
||||||
|
|
||||||
def cb_close_clicked(self, button):
|
def cb_close_clicked(self, button):
|
||||||
@ -164,9 +291,9 @@ def cb_menu_position(menu, button):
|
|||||||
"""
|
"""
|
||||||
Determine the position of the popup menu.
|
Determine the position of the popup menu.
|
||||||
"""
|
"""
|
||||||
x_pos, y_pos = button.window.get_origin()
|
ret_val, x_pos, y_pos = button.get_window().get_origin()
|
||||||
x_pos += button.allocation.x
|
x_pos += button.get_allocation().x
|
||||||
y_pos += button.allocation.y + button.allocation.height
|
y_pos += button.get_allocation().y + button.get_allocation().height
|
||||||
|
|
||||||
return (x_pos, y_pos, False)
|
return (x_pos, y_pos, False)
|
||||||
|
|
||||||
|
@ -685,21 +685,6 @@ class ViewManager(CLIManager):
|
|||||||
# But we need to realize it here to have Gdk.window handy
|
# But we need to realize it here to have Gdk.window handy
|
||||||
self.window.realize()
|
self.window.realize()
|
||||||
|
|
||||||
def __load_sidebar_plugins(self):
|
|
||||||
"""
|
|
||||||
Load the sidebar plugins.
|
|
||||||
"""
|
|
||||||
for pdata in self._pmgr.get_reg_sidebars():
|
|
||||||
module = self._pmgr.load_plugin(pdata)
|
|
||||||
if not module:
|
|
||||||
print("Error loading sidebar '%s': skipping content"
|
|
||||||
% pdata.name)
|
|
||||||
continue
|
|
||||||
|
|
||||||
sidebar_class = getattr(module, pdata.sidebarclass)
|
|
||||||
sidebar_page = sidebar_class(self.dbstate, self.uistate)
|
|
||||||
self.navigator.add(pdata.menu_label, sidebar_page, pdata.order)
|
|
||||||
|
|
||||||
def __setup_statusbar(self):
|
def __setup_statusbar(self):
|
||||||
"""
|
"""
|
||||||
Create the statusbar that sits at the bottom of the window
|
Create the statusbar that sits at the bottom of the window
|
||||||
@ -957,7 +942,7 @@ class ViewManager(CLIManager):
|
|||||||
config.get('preferences.use-last-view'))
|
config.get('preferences.use-last-view'))
|
||||||
self.current_views = defaults[2]
|
self.current_views = defaults[2]
|
||||||
|
|
||||||
self.__load_sidebar_plugins()
|
self.navigator.load_plugins(self.dbstate, self.uistate)
|
||||||
|
|
||||||
self.goto_page(defaults[0], defaults[1])
|
self.goto_page(defaults[0], defaults[1])
|
||||||
|
|
||||||
|
@ -45,12 +45,6 @@ from gramps.gui.viewmanager import get_available_views, views_to_show
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
UICATEGORY = '''<ui>
|
UICATEGORY = '''<ui>
|
||||||
<menubar name="MenuBar">
|
|
||||||
<menu action="ViewMenu">
|
|
||||||
<placeholder name="ViewsInCategory">%s
|
|
||||||
</placeholder>
|
|
||||||
</menu>
|
|
||||||
</menubar>
|
|
||||||
<toolbar name="ToolBar">
|
<toolbar name="ToolBar">
|
||||||
<placeholder name="ViewsInCategory">%s
|
<placeholder name="ViewsInCategory">%s
|
||||||
</placeholder>
|
</placeholder>
|
||||||
@ -58,22 +52,6 @@ UICATEGORY = '''<ui>
|
|||||||
</ui>
|
</ui>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
CATEGORY_ICON = {
|
|
||||||
'Dashboard': 'gramps-gramplet',
|
|
||||||
'People': 'gramps-person',
|
|
||||||
'Relationships': 'gramps-relation',
|
|
||||||
'Families': 'gramps-family',
|
|
||||||
'Events': 'gramps-event',
|
|
||||||
'Ancestry': 'gramps-pedigree',
|
|
||||||
'Places': 'gramps-place',
|
|
||||||
'Geography': 'gramps-geo',
|
|
||||||
'Sources': 'gramps-source',
|
|
||||||
'Repositories': 'gramps-repository',
|
|
||||||
'Media': 'gramps-media',
|
|
||||||
'Notes': 'gramps-notes',
|
|
||||||
'Citations': 'gramps-citation',
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# CategorySidebar class
|
# CategorySidebar class
|
||||||
@ -84,7 +62,7 @@ class CategorySidebar(BaseSidebar):
|
|||||||
A sidebar displaying a column of toggle buttons that allows the user to
|
A sidebar displaying a column of toggle buttons that allows the user to
|
||||||
change the current view.
|
change the current view.
|
||||||
"""
|
"""
|
||||||
def __init__(self, dbstate, uistate):
|
def __init__(self, dbstate, uistate, categories, views):
|
||||||
|
|
||||||
self.viewmanager = uistate.viewmanager
|
self.viewmanager = uistate.viewmanager
|
||||||
|
|
||||||
@ -92,8 +70,6 @@ class CategorySidebar(BaseSidebar):
|
|||||||
self.button_handlers = []
|
self.button_handlers = []
|
||||||
|
|
||||||
self.ui_category = {}
|
self.ui_category = {}
|
||||||
self.view_toggle_actions = {}
|
|
||||||
self.cat_view_group = None
|
|
||||||
self.merge_ids = []
|
self.merge_ids = []
|
||||||
|
|
||||||
self.window = Gtk.ScrolledWindow()
|
self.window = Gtk.ScrolledWindow()
|
||||||
@ -103,49 +79,26 @@ class CategorySidebar(BaseSidebar):
|
|||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
use_text = config.get('interface.sidebar-text')
|
use_text = config.get('interface.sidebar-text')
|
||||||
for cat_num, cat_views in enumerate(self.viewmanager.get_views()):
|
for cat_num, cat_name, cat_icon in categories:
|
||||||
uimenuitems = ''
|
|
||||||
uitoolitems = ''
|
|
||||||
self.view_toggle_actions[cat_num] = []
|
|
||||||
for view_num, page in enumerate(cat_views):
|
|
||||||
|
|
||||||
if view_num == 0:
|
|
||||||
category = page[0].category[1]
|
|
||||||
cat_icon = CATEGORY_ICON.get(page[0].category[0])
|
|
||||||
if cat_icon is None:
|
|
||||||
cat_icon = 'gramps-view'
|
|
||||||
|
|
||||||
# create the button and add it to the sidebar
|
# create the button and add it to the sidebar
|
||||||
button = self.__make_sidebar_button(use_text, cat_num,
|
button = self.__make_sidebar_button(use_text, cat_num,
|
||||||
category, cat_icon)
|
cat_name, cat_icon)
|
||||||
vbox.pack_start(button, False, True, 0)
|
vbox.pack_start(button, False, True, 0)
|
||||||
|
|
||||||
# Enable view switching during DnD
|
# Enable view switching during DnD
|
||||||
button.drag_dest_set(0, [], 0)
|
button.drag_dest_set(0, [], 0)
|
||||||
button.connect('drag_motion', self.cb_switch_page_on_dnd,
|
button.connect('drag_motion', self.cb_switch_page_on_dnd, cat_num)
|
||||||
cat_num)
|
|
||||||
vbox.show_all()
|
|
||||||
|
|
||||||
pageid = (page[0].id + '_%i' % view_num)
|
# toollbar buttons for switching views in a category
|
||||||
uimenuitems += '\n<menuitem action="%s"/>' % pageid
|
uitoolitems = ''
|
||||||
|
for view_num, view_name, view_icon in views[cat_num]:
|
||||||
|
pageid = 'page_%i_%i' % (cat_num, view_num)
|
||||||
uitoolitems += '\n<toolitem action="%s"/>' % pageid
|
uitoolitems += '\n<toolitem action="%s"/>' % pageid
|
||||||
# id, stock, button text, UI, tooltip, page
|
if len(views[cat_num]) > 1:
|
||||||
if view_num < 9:
|
self.ui_category[cat_num] = UICATEGORY % uitoolitems
|
||||||
modifier = "<PRIMARY><ALT>%d" % ((view_num % 9) + 1)
|
|
||||||
else:
|
|
||||||
modifier = ""
|
|
||||||
|
|
||||||
stock_icon = page[0].stock_icon
|
vbox.show_all()
|
||||||
if stock_icon is None:
|
|
||||||
stock_icon = cat_icon
|
|
||||||
self.view_toggle_actions[cat_num].append((pageid,
|
|
||||||
stock_icon,
|
|
||||||
page[0].name, modifier, page[0].name, view_num))
|
|
||||||
|
|
||||||
if len(cat_views) > 1:
|
|
||||||
#allow for switching views in a category
|
|
||||||
self.ui_category[cat_num] = UICATEGORY % (uimenuitems,
|
|
||||||
uitoolitems)
|
|
||||||
|
|
||||||
def get_top(self):
|
def get_top(self):
|
||||||
"""
|
"""
|
||||||
@ -159,19 +112,8 @@ class CategorySidebar(BaseSidebar):
|
|||||||
"""
|
"""
|
||||||
# Add buttons to the toolbar for the different view in the category
|
# Add buttons to the toolbar for the different view in the category
|
||||||
uimanager = self.viewmanager.uimanager
|
uimanager = self.viewmanager.uimanager
|
||||||
if self.cat_view_group:
|
|
||||||
if self.cat_view_group in uimanager.get_action_groups():
|
|
||||||
uimanager.remove_action_group(self.cat_view_group)
|
|
||||||
|
|
||||||
list(map(uimanager.remove_ui, self.merge_ids))
|
list(map(uimanager.remove_ui, self.merge_ids))
|
||||||
|
|
||||||
if cat_num in self.ui_category:
|
if cat_num in self.ui_category:
|
||||||
self.cat_view_group = Gtk.ActionGroup('categoryviews')
|
|
||||||
self.cat_view_group.add_radio_actions(
|
|
||||||
self.view_toggle_actions[cat_num], value=view_num,
|
|
||||||
on_change=self.cb_view_clicked, user_data=cat_num)
|
|
||||||
self.cat_view_group.set_sensitive(True)
|
|
||||||
uimanager.insert_action_group(self.cat_view_group, 1)
|
|
||||||
mergeid = uimanager.add_ui_from_string(self.ui_category[cat_num])
|
mergeid = uimanager.add_ui_from_string(self.ui_category[cat_num])
|
||||||
self.merge_ids.append(mergeid)
|
self.merge_ids.append(mergeid)
|
||||||
|
|
||||||
@ -263,3 +205,10 @@ class CategorySidebar(BaseSidebar):
|
|||||||
if self.viewmanager.notebook.get_current_page() != page_no:
|
if self.viewmanager.notebook.get_current_page() != page_no:
|
||||||
self.viewmanager.notebook.set_current_page(page_no)
|
self.viewmanager.notebook.set_current_page(page_no)
|
||||||
self.__handlers_unblock()
|
self.__handlers_unblock()
|
||||||
|
|
||||||
|
def inactive(self):
|
||||||
|
"""
|
||||||
|
Called when the sidebar is hidden.
|
||||||
|
"""
|
||||||
|
uimanager = self.viewmanager.uimanager
|
||||||
|
list(map(uimanager.remove_ui, self.merge_ids))
|
||||||
|
Loading…
Reference in New Issue
Block a user