4802: Removing a gramplet from a GrampsBar moved from the close button to the context menu

svn: r17057
This commit is contained in:
Nick Hall 2011-04-05 23:41:59 +00:00
parent 30f0415f0e
commit e9fe8b7de2
3 changed files with 43 additions and 32 deletions

View File

@ -319,7 +319,6 @@ class GrampsBar(gtk.Notebook):
"""
Create a tab label consisting of a label and a close button.
"""
hbox = gtk.HBox(False, 4)
label = gtk.Label()
if gramplet.pui.has_data:
label.set_text("<b>%s</b>" % gramplet.title)
@ -327,23 +326,8 @@ class GrampsBar(gtk.Notebook):
label.set_text(gramplet.title)
label.set_use_markup(True)
label.set_tooltip_text(gramplet.tname)
closebtn = gtk.Button()
image = gtk.Image()
image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
closebtn.connect("clicked", self.__delete_clicked, gramplet)
closebtn.set_image(image)
closebtn.set_relief(gtk.RELIEF_NONE)
# The next three lines adjust the close button to the correct size.
closebtn.set_name('tab-button')
size = gtk.icon_size_lookup_for_settings(closebtn.get_settings(),
gtk.ICON_SIZE_MENU)
closebtn.set_size_request(size[0] + 2, size[1] + 2)
hbox.pack_start(label, True, True)
hbox.pack_end(closebtn, False, False)
hbox.show_all()
return hbox
label.show_all()
return label
def __delete_clicked(self, button, gramplet):
"""
@ -424,20 +408,24 @@ class GrampsBar(gtk.Notebook):
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
uiman = self.uistate.uimanager
ag_menu = uiman.get_widget('/GrampsBarPopup/AddGramplet')
if ag_menu:
submenu = ag_menu.get_submenu()
submenu = gtk.Menu()
skip = self.all_gramplets()
gramplet_list = [(GET_AVAILABLE_GRAMPLETS(name)["tname"], name)
for name in AVAILABLE_GRAMPLETS()
if name not in skip]
skip = self.all_gramplets()
gramplet_list = [(GET_AVAILABLE_GRAMPLETS(name)["tname"], name)
for name in AVAILABLE_GRAMPLETS()
if name not in skip]
gramplet_list.sort()
self.__create_submenu(ag_menu, gramplet_list, self.__add_clicked)
rg_menu = uiman.get_widget('/GrampsBarPopup/RemoveGramplet')
if self.empty:
rg_menu.hide()
else:
gramplet_list = [(gramplet.title, gramplet.gname)
for gramplet in self.get_children() +
self.detached_gramplets]
gramplet_list.sort()
for entry in gramplet_list:
item = gtk.MenuItem(entry[0])
item.connect("activate", self.__add_clicked, entry[1])
item.show()
submenu.append(item)
ag_menu.set_submenu(submenu)
self.__create_submenu(rg_menu, gramplet_list,
self.__remove_clicked)
rg_menu.show()
menu = uiman.get_widget('/GrampsBarPopup')
if menu:
@ -445,12 +433,32 @@ class GrampsBar(gtk.Notebook):
return True
return False
def __create_submenu(self, main_menu, gramplet_list, callback_func):
"""
Create a submenu of the context menu.
"""
if main_menu:
submenu = main_menu.get_submenu()
submenu = gtk.Menu()
for entry in gramplet_list:
item = gtk.MenuItem(entry[0])
item.connect("activate", callback_func, entry[1])
item.show()
submenu.append(item)
main_menu.set_submenu(submenu)
def __add_clicked(self, menu, gname):
"""
Called when a gramplet is added from the context menu.
"""
self.add_gramplet(gname)
def __remove_clicked(self, menu, gname):
"""
Called when a gramplet is removed from the context menu.
"""
self.remove_gramplet(gname)
def get_config_funcs(self):
"""
Return a list of configuration functions.

View File

@ -113,6 +113,7 @@ class PageView(DbGUIElement):
</menubar>
<popup name="GrampsBarPopup">
<menuitem action="AddGramplet"/>
<menuitem action="RemoveGramplet"/>
</popup>
</ui>'''
self.dirty = True
@ -413,6 +414,8 @@ class PageView(DbGUIElement):
None, None, self.__bottombar_toggled,
self.bottombar.get_property('visible'))
self._add_action("AddGramplet", gtk.STOCK_ADD, _("Add a gramplet"))
self._add_action("RemoveGramplet", gtk.STOCK_REMOVE,
_("Remove a gramplet"))
def __build_action_group(self):
"""

View File

@ -687,7 +687,7 @@ class GuiGramplet(object):
def set_has_data(self, value):
if isinstance(self.pane, gtk.Notebook):
if self.pane.get_tab_label(self):
label = self.pane.get_tab_label(self).get_children()[0]
label = self.pane.get_tab_label(self)
if value:
label.set_text("<b>%s</b>" % self.title)
label.set_use_markup(True)