Add two experimental navigation plugins

svn: r21088
This commit is contained in:
Nick Hall 2013-01-12 23:35:45 +00:00
parent 6400f61b29
commit ce373e3036
7 changed files with 653 additions and 100 deletions

View File

@ -42,3 +42,15 @@ class BaseSidebar(object):
Called when the active view is changed.
"""
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

View File

@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# 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
@ -29,6 +29,7 @@ manage pages in the main Gramps window.
#
#-------------------------------------------------------------------------
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 .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.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()
frame = Gtk.Frame()
@ -92,6 +133,59 @@ class Navigator(object):
self.top.show()
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):
"""
Return the top container widget for the GUI.
@ -121,8 +215,37 @@ class Navigator(object):
"""
Called when a Gramps view is changed.
"""
for page in self.pages:
page[1].view_changed(cat_num, view_num)
self.active_cat = cat_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):
"""
@ -145,6 +268,11 @@ class Navigator(object):
"""
Called when the user has switched to a new sidebar plugin page.
"""
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)
if self.pages:
self.title_label.set_text(self.pages[index][0])
@ -164,9 +292,9 @@ def cb_menu_position(menu, button):
"""
Determine the position of the popup menu.
"""
x_pos, y_pos = button.window.get_origin()
x_pos += button.allocation.x
y_pos += button.allocation.y + button.allocation.height
ret_val, x_pos, y_pos = button.get_window().get_origin()
x_pos += button.get_allocation().x
y_pos += button.get_allocation().y + button.get_allocation().height
return (x_pos, y_pos, False)

View File

@ -685,21 +685,6 @@ class ViewManager(CLIManager):
# But we need to realize it here to have Gdk.window handy
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):
"""
Create the statusbar that sits at the bottom of the window
@ -957,7 +942,7 @@ class ViewManager(CLIManager):
config.get('preferences.use-last-view'))
self.current_views = defaults[2]
self.__load_sidebar_plugins()
self.navigator.load_plugins(self.dbstate, self.uistate)
self.goto_page(defaults[0], defaults[1])

View File

@ -45,12 +45,6 @@ from gramps.gui.viewmanager import get_available_views, views_to_show
#
#-------------------------------------------------------------------------
UICATEGORY = '''<ui>
<menubar name="MenuBar">
<menu action="ViewMenu">
<placeholder name="ViewsInCategory">%s
</placeholder>
</menu>
</menubar>
<toolbar name="ToolBar">
<placeholder name="ViewsInCategory">%s
</placeholder>
@ -58,22 +52,6 @@ UICATEGORY = '''<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
@ -84,7 +62,7 @@ class CategorySidebar(BaseSidebar):
A sidebar displaying a column of toggle buttons that allows the user to
change the current view.
"""
def __init__(self, dbstate, uistate):
def __init__(self, dbstate, uistate, categories, views):
self.viewmanager = uistate.viewmanager
@ -92,8 +70,6 @@ class CategorySidebar(BaseSidebar):
self.button_handlers = []
self.ui_category = {}
self.view_toggle_actions = {}
self.cat_view_group = None
self.merge_ids = []
self.window = Gtk.ScrolledWindow()
@ -103,49 +79,26 @@ class CategorySidebar(BaseSidebar):
self.window.show()
use_text = config.get('interface.sidebar-text')
for cat_num, cat_views in enumerate(self.viewmanager.get_views()):
uimenuitems = ''
for cat_num, cat_name, cat_icon in categories:
# create the button and add it to the sidebar
button = self.__make_sidebar_button(use_text, cat_num,
cat_name, cat_icon)
vbox.pack_start(button, False, True, 0)
# Enable view switching during DnD
button.drag_dest_set(0, [], 0)
button.connect('drag_motion', self.cb_switch_page_on_dnd, cat_num)
# toollbar buttons for switching views in a category
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
button = self.__make_sidebar_button(use_text, cat_num,
category, cat_icon)
vbox.pack_start(button, False, True, 0)
# Enable view switching during DnD
button.drag_dest_set(0, [], 0)
button.connect('drag_motion', self.cb_switch_page_on_dnd,
cat_num)
vbox.show_all()
pageid = (page[0].id + '_%i' % view_num)
uimenuitems += '\n<menuitem action="%s"/>' % pageid
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
# id, stock, button text, UI, tooltip, page
if view_num < 9:
modifier = "<PRIMARY><ALT>%d" % ((view_num % 9) + 1)
else:
modifier = ""
if len(views[cat_num]) > 1:
self.ui_category[cat_num] = UICATEGORY % uitoolitems
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))
if len(cat_views) > 1:
#allow for switching views in a category
self.ui_category[cat_num] = UICATEGORY % (uimenuitems,
uitoolitems)
vbox.show_all()
def get_top(self):
"""
@ -159,19 +112,8 @@ class CategorySidebar(BaseSidebar):
"""
# Add buttons to the toolbar 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))
list(map(uimanager.remove_ui, self.merge_ids))
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])
self.merge_ids.append(mergeid)
@ -263,3 +205,10 @@ class CategorySidebar(BaseSidebar):
if self.viewmanager.notebook.get_current_page() != page_no:
self.viewmanager.notebook.set_current_page(page_no)
self.__handlers_unblock()
def inactive(self):
"""
Called when the sidebar is hidden.
"""
uimanager = self.viewmanager.uimanager
list(map(uimanager.remove_ui, self.merge_ids))

View File

@ -0,0 +1,220 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2005-2007 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier
# Copyright (C) 2010 Nick Hall
# Copyright (C) 2011 Tim G L Lyons
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: categorysidebar.py 20634 2012-11-07 17:53:14Z bmcage $
#-------------------------------------------------------------------------
#
# GNOME modules
#
#-------------------------------------------------------------------------
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gramps.gen.config import config
from gramps.gui.basesidebar import BaseSidebar
#-------------------------------------------------------------------------
#
# DropdownSidebar class
#
#-------------------------------------------------------------------------
class DropdownSidebar(BaseSidebar):
"""
A sidebar displaying toggle buttons and buttons with drop-down menus that
allows the user to change the current view.
"""
def __init__(self, dbstate, uistate, categories, views):
self.viewmanager = uistate.viewmanager
self.views = views
self.buttons = []
self.button_handlers = []
self.window = Gtk.ScrolledWindow()
vbox = Gtk.VBox()
self.window.add_with_viewport(vbox)
self.window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.window.show()
use_text = config.get('interface.sidebar-text')
for cat_num, cat_name, cat_icon in categories:
# create the button and add it to the sidebar
button = self.__make_sidebar_button(use_text, cat_num,
cat_name, cat_icon)
vbox.pack_start(button, False, True, 0)
# Enable view switching during DnD
button.drag_dest_set(0, [], 0)
button.connect('drag_motion', self.cb_switch_page_on_dnd, cat_num)
vbox.show_all()
def get_top(self):
"""
Return the top container widget for the GUI.
"""
return self.window
def view_changed(self, cat_num, view_num):
"""
Called when the active view is changed.
"""
# Set new button as selected
self.__handlers_block()
for index, button in enumerate(self.buttons):
if index == cat_num:
button.set_active(True)
else:
button.set_active(False)
self.__handlers_unblock()
def __handlers_block(self):
"""
Block signals to the buttons to prevent spurious events.
"""
for idx in range(len(self.buttons)):
self.buttons[idx].handler_block(self.button_handlers[idx])
def __handlers_unblock(self):
"""
Unblock signals to the buttons.
"""
for idx in range(len(self.buttons)):
self.buttons[idx].handler_unblock(self.button_handlers[idx])
def cb_view_clicked(self, radioaction, current, cat_num):
"""
Called when a button causes a view change.
"""
view_num = radioaction.get_current_value()
self.viewmanager.goto_page(cat_num, view_num)
def __category_clicked(self, button, cat_num):
"""
Called when a category button is clicked.
"""
# Make the button inactive. It will be set to active in the
# view_changed method if the change was successful.
button.set_active(False)
self.viewmanager.goto_page(cat_num, None)
def __view_clicked(self, button, cat_num):
"""
Called when a view drop-down arrow is clicked.
"""
menu = Gtk.Menu()
for item in self.views[cat_num]:
menuitem = Gtk.ImageMenuItem(label=item[1])
image = Gtk.Image.new_from_stock(item[2], Gtk.IconSize.MENU)
image.show()
menuitem.set_image(image)
menuitem.connect("activate", self.cb_menu_clicked, cat_num, item[0])
menuitem.show()
menu.append(menuitem)
menu.popup(None, None, cb_menu_position, button, 0, 0)
def cb_menu_clicked(self, menuitem, cat_num, view_num):
"""
Called when a view is selected from a drop-down menu.
"""
self.viewmanager.goto_page(cat_num, view_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
the button.
"""
top = Gtk.HBox()
# create the button
button = Gtk.ToggleButton()
button.set_relief(Gtk.ReliefStyle.NONE)
button.set_alignment(0, 0.5)
self.buttons.append(button)
button2 = Gtk.Button()
button2.set_relief(Gtk.ReliefStyle.NONE)
button2.set_alignment(0.5, 0.5)
arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE)
button2.add(arrow)
button2.connect('clicked', self.__view_clicked, index)
# add the tooltip
button.set_tooltip_text(page_title)
# connect the signal, along with the index as user data
handler_id = button.connect('clicked', self.__category_clicked, index)
self.button_handlers.append(handler_id)
button.show()
# add the image. If we are using text, use the BUTTON (larger) size.
# otherwise, use the smaller size
hbox = Gtk.HBox()
hbox.show()
image = Gtk.Image()
if use_text:
image.set_from_stock(page_stock, Gtk.IconSize.BUTTON)
else:
image.set_from_stock(page_stock, Gtk.IconSize.DND)
image.show()
hbox.pack_start(image, False, False, 0)
hbox.set_spacing(4)
# add text if requested
if use_text:
label = Gtk.Label(label=page_title)
label.show()
hbox.pack_start(label, False, True, 0)
button.add(hbox)
top.pack_start(button, False, True, 0)
top.pack_start(button2, False, True, 0)
return top
def cb_switch_page_on_dnd(self, widget, context, xpos, ypos, time, page_no):
"""
Switches the page based on drag and drop.
"""
self.__handlers_block()
if self.viewmanager.notebook.get_current_page() != page_no:
self.viewmanager.notebook.set_current_page(page_no)
self.__handlers_unblock()
def cb_menu_position(menu, button):
"""
Determine the position of the popup menu.
"""
ret_val, x_pos, y_pos = button.get_window().get_origin()
x_pos += button.get_allocation().x
y_pos += button.get_allocation().y + button.get_allocation().height
return (x_pos, y_pos, False)

View File

@ -0,0 +1,229 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2005-2007 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier
# Copyright (C) 2010 Nick Hall
# Copyright (C) 2011 Tim G L Lyons
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: categorysidebar.py 20634 2012-11-07 17:53:14Z bmcage $
#-------------------------------------------------------------------------
#
# GNOME modules
#
#-------------------------------------------------------------------------
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gramps.gen.config import config
from gramps.gui.basesidebar import BaseSidebar
#-------------------------------------------------------------------------
#
# ExpanderSidebar class
#
#-------------------------------------------------------------------------
class ExpanderSidebar(BaseSidebar):
"""
A sidebar displaying toggle buttons and buttons with drop-down menus that
allows the user to change the current view.
"""
def __init__(self, dbstate, uistate, categories, views):
self.viewmanager = uistate.viewmanager
self.views = views
self.expanders = []
self.buttons = []
self.button_handlers = []
self.lookup = {}
self.window = Gtk.ScrolledWindow()
vbox = Gtk.VBox()
self.window.add_with_viewport(vbox)
self.window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.window.show()
use_text = config.get('interface.sidebar-text')
for cat_num, cat_name, cat_icon in categories:
expander = Gtk.Expander()
self.expanders.append(expander)
catbox = Gtk.HBox()
image = Gtk.Image()
image.set_from_stock(cat_icon, Gtk.IconSize.BUTTON)
catbox.pack_start(image, False, False, 4)
if use_text:
label = Gtk.Label(label=cat_name)
catbox.pack_start(label, False, True, 4)
catbox.set_tooltip_text(cat_name)
expander.set_label_widget(catbox)
viewbox = Gtk.VBox()
for view_num, view_name, view_icon in views[cat_num]:
# create the button and add it to the sidebar
button = self.__make_sidebar_button(use_text, cat_num, view_num,
view_name, view_icon)
viewbox.pack_start(button, False, False, 0)
expander.add(viewbox)
vbox.pack_start(expander, False, True, 0)
# Enable view switching during DnD
#catbox.drag_dest_set(0, [], 0)
#catbox.connect('drag_motion', self.cb_switch_page_on_dnd, cat_num)
vbox.show_all()
def get_top(self):
"""
Return the top container widget for the GUI.
"""
return self.window
def view_changed(self, cat_num, view_num):
"""
Called when the active view is changed.
"""
if cat_num is None:
return
# Expand category
self.expanders[cat_num].set_expanded(True)
# Set new button as selected
button_num = self.lookup[(cat_num, view_num)]
self.__handlers_block()
for index, button in enumerate(self.buttons):
if index == button_num:
button.set_active(True)
else:
button.set_active(False)
self.__handlers_unblock()
def __handlers_block(self):
"""
Block signals to the buttons to prevent spurious events.
"""
for idx in range(len(self.buttons)):
self.buttons[idx].handler_block(self.button_handlers[idx])
def __handlers_unblock(self):
"""
Unblock signals to the buttons.
"""
for idx in range(len(self.buttons)):
self.buttons[idx].handler_unblock(self.button_handlers[idx])
def cb_view_clicked(self, radioaction, current, cat_num):
"""
Called when a button causes a view change.
"""
view_num = radioaction.get_current_value()
self.viewmanager.goto_page(cat_num, view_num)
def __category_clicked(self, button, cat_num):
"""
Called when a category button is clicked.
"""
# Make the button inactive. It will be set to active in the
# view_changed method if the change was successful.
button.set_active(False)
self.viewmanager.goto_page(cat_num, None)
def __view_clicked(self, button, cat_num, view_num):
"""
Called when a view button is clicked.
"""
self.viewmanager.goto_page(cat_num, view_num)
def cb_menu_clicked(self, menuitem, cat_num, view_num):
"""
Called when a view is selected from a drop-down menu.
"""
self.viewmanager.goto_page(cat_num, view_num)
def __make_sidebar_button(self, use_text, cat_num, view_num, view_name, view_icon):
"""
Create the sidebar button. The page_title is the text associated with
the button.
"""
top = Gtk.HBox()
# create the button
button = Gtk.ToggleButton()
button.set_relief(Gtk.ReliefStyle.NONE)
button.set_alignment(0, 0.5)
self.buttons.append(button)
self.lookup[(cat_num, view_num)] = len(self.buttons) - 1
# add the tooltip
button.set_tooltip_text(view_name)
# connect the signal, along with the index as user data
handler_id = button.connect('clicked', self.__view_clicked, cat_num, view_num)
self.button_handlers.append(handler_id)
button.show()
# add the image. If we are using text, use the BUTTON (larger) size.
# otherwise, use the smaller size
hbox = Gtk.HBox()
hbox.show()
image = Gtk.Image()
if use_text:
image.set_from_stock(view_icon, Gtk.IconSize.BUTTON)
else:
image.set_from_stock(view_icon, Gtk.IconSize.DND)
image.show()
hbox.pack_start(image, False, False, 0)
hbox.set_spacing(4)
# add text if requested
if use_text:
label = Gtk.Label(label=view_name)
label.show()
hbox.pack_start(label, False, True, 0)
button.add(hbox)
top.pack_start(button, False, True, 0)
return top
def cb_switch_page_on_dnd(self, widget, context, xpos, ypos, time, page_no):
"""
Switches the page based on drag and drop.
"""
self.__handlers_block()
if self.viewmanager.notebook.get_current_page() != page_no:
self.viewmanager.notebook.set_current_page(page_no)
self.__handlers_unblock()
def cb_menu_position(menu, button):
"""
Determine the position of the popup menu.
"""
ret_val, x_pos, y_pos = button.get_window().get_origin()
x_pos += button.get_allocation().x
y_pos += button.get_allocation().y + button.get_allocation().height
return (x_pos, y_pos, False)

View File

@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
# $Id: sidebar.gpr.py 20634 2012-11-07 17:53:14Z bmcage $
#------------------------------------------------------------------------
#
@ -39,3 +39,33 @@ sidebarclass = 'CategorySidebar',
menu_label = _('Category'),
order = START
)
register(SIDEBAR,
id = 'dropdownsidebar',
name = _("Drop-down Sidebar"),
description = _("Selection of categories and views from drop-down lists"),
version = '1.0',
gramps_target_version = '4.1',
status = STABLE,
fname = 'dropdownsidebar.py',
authors = ["Nick Hall"],
authors_email = ["nick__hall@hotmail.com"],
sidebarclass = 'DropdownSidebar',
menu_label = _('Drop-Down'),
order = END
)
register(SIDEBAR,
id = 'expandersidebar',
name = _("Expander Sidebar"),
description = _("Selection of views from lists with expanders"),
version = '1.0',
gramps_target_version = '4.1',
status = STABLE,
fname = 'expandersidebar.py',
authors = ["Nick Hall"],
authors_email = ["nick__hall@hotmail.com"],
sidebarclass = 'ExpanderSidebar',
menu_label = _('Expander'),
order = END
)