4802: Removing a gramplet from a GrampsBar moved from the close button to the context menu
svn: r17052
This commit is contained in:
parent
5ac1e99915
commit
8acb19bb14
@ -319,7 +319,6 @@ class GrampsBar(gtk.Notebook):
|
|||||||
"""
|
"""
|
||||||
Create a tab label consisting of a label and a close button.
|
Create a tab label consisting of a label and a close button.
|
||||||
"""
|
"""
|
||||||
hbox = gtk.HBox(False, 4)
|
|
||||||
label = gtk.Label()
|
label = gtk.Label()
|
||||||
if gramplet.pui.has_data:
|
if gramplet.pui.has_data:
|
||||||
label.set_text("<b>%s</b>" % gramplet.title)
|
label.set_text("<b>%s</b>" % gramplet.title)
|
||||||
@ -327,23 +326,8 @@ class GrampsBar(gtk.Notebook):
|
|||||||
label.set_text(gramplet.title)
|
label.set_text(gramplet.title)
|
||||||
label.set_use_markup(True)
|
label.set_use_markup(True)
|
||||||
label.set_tooltip_text(gramplet.tname)
|
label.set_tooltip_text(gramplet.tname)
|
||||||
closebtn = gtk.Button()
|
label.show_all()
|
||||||
image = gtk.Image()
|
return label
|
||||||
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
|
|
||||||
|
|
||||||
def __delete_clicked(self, button, gramplet):
|
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:
|
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||||
uiman = self.uistate.uimanager
|
uiman = self.uistate.uimanager
|
||||||
ag_menu = uiman.get_widget('/GrampsBarPopup/AddGramplet')
|
ag_menu = uiman.get_widget('/GrampsBarPopup/AddGramplet')
|
||||||
if ag_menu:
|
|
||||||
submenu = ag_menu.get_submenu()
|
|
||||||
submenu = gtk.Menu()
|
|
||||||
skip = self.all_gramplets()
|
skip = self.all_gramplets()
|
||||||
gramplet_list = [(GET_AVAILABLE_GRAMPLETS(name)["tname"], name)
|
gramplet_list = [(GET_AVAILABLE_GRAMPLETS(name)["tname"], name)
|
||||||
for name in AVAILABLE_GRAMPLETS()
|
for name in AVAILABLE_GRAMPLETS()
|
||||||
if name not in skip]
|
if name not in skip]
|
||||||
gramplet_list.sort()
|
gramplet_list.sort()
|
||||||
for entry in gramplet_list:
|
self.__create_submenu(ag_menu, gramplet_list, self.__add_clicked)
|
||||||
item = gtk.MenuItem(entry[0])
|
|
||||||
item.connect("activate", self.__add_clicked, entry[1])
|
rg_menu = uiman.get_widget('/GrampsBarPopup/RemoveGramplet')
|
||||||
item.show()
|
if self.empty:
|
||||||
submenu.append(item)
|
rg_menu.hide()
|
||||||
ag_menu.set_submenu(submenu)
|
else:
|
||||||
|
gramplet_list = [(gramplet.title, gramplet.gname)
|
||||||
|
for gramplet in self.get_children() +
|
||||||
|
self.detached_gramplets]
|
||||||
|
gramplet_list.sort()
|
||||||
|
self.__create_submenu(rg_menu, gramplet_list,
|
||||||
|
self.__remove_clicked)
|
||||||
|
rg_menu.show()
|
||||||
|
|
||||||
menu = uiman.get_widget('/GrampsBarPopup')
|
menu = uiman.get_widget('/GrampsBarPopup')
|
||||||
if menu:
|
if menu:
|
||||||
@ -445,12 +433,32 @@ class GrampsBar(gtk.Notebook):
|
|||||||
return True
|
return True
|
||||||
return False
|
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):
|
def __add_clicked(self, menu, gname):
|
||||||
"""
|
"""
|
||||||
Called when a gramplet is added from the context menu.
|
Called when a gramplet is added from the context menu.
|
||||||
"""
|
"""
|
||||||
self.add_gramplet(gname)
|
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):
|
def get_config_funcs(self):
|
||||||
"""
|
"""
|
||||||
Return a list of configuration functions.
|
Return a list of configuration functions.
|
||||||
|
@ -113,6 +113,7 @@ class PageView(DbGUIElement):
|
|||||||
</menubar>
|
</menubar>
|
||||||
<popup name="GrampsBarPopup">
|
<popup name="GrampsBarPopup">
|
||||||
<menuitem action="AddGramplet"/>
|
<menuitem action="AddGramplet"/>
|
||||||
|
<menuitem action="RemoveGramplet"/>
|
||||||
</popup>
|
</popup>
|
||||||
</ui>'''
|
</ui>'''
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
@ -413,6 +414,8 @@ class PageView(DbGUIElement):
|
|||||||
None, None, self.__bottombar_toggled,
|
None, None, self.__bottombar_toggled,
|
||||||
self.bottombar.get_property('visible'))
|
self.bottombar.get_property('visible'))
|
||||||
self._add_action("AddGramplet", gtk.STOCK_ADD, _("Add a gramplet"))
|
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):
|
def __build_action_group(self):
|
||||||
"""
|
"""
|
||||||
|
@ -687,7 +687,7 @@ class GuiGramplet(object):
|
|||||||
def set_has_data(self, value):
|
def set_has_data(self, value):
|
||||||
if isinstance(self.pane, gtk.Notebook):
|
if isinstance(self.pane, gtk.Notebook):
|
||||||
if self.pane.get_tab_label(self):
|
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:
|
if value:
|
||||||
label.set_text("<b>%s</b>" % self.title)
|
label.set_text("<b>%s</b>" % self.title)
|
||||||
label.set_use_markup(True)
|
label.set_use_markup(True)
|
||||||
|
Loading…
Reference in New Issue
Block a user