4809: Add an option to restore a GrampsBar to its default gramplets

svn: r17897
This commit is contained in:
Nick Hall 2011-07-06 22:31:03 +00:00
parent 58657454f5
commit 58eb8627e9
2 changed files with 37 additions and 27 deletions

View File

@ -39,15 +39,6 @@ import os
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gtk import gtk
gtk.rc_parse_string("""
style "tab-button-style" {
GtkWidget::focus-padding = 0
GtkWidget::focus-line-width = 0
xthickness = 0
ythickness = 0
}
widget "*.tab-button" style "tab-button-style"
""")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -67,6 +58,7 @@ from gui.widgets.grampletpane import (AVAILABLE_GRAMPLETS,
GuiGramplet) GuiGramplet)
from gui.widgets.undoablebuffer import UndoableBuffer from gui.widgets.undoablebuffer import UndoableBuffer
from gui.utils import add_menuitem from gui.utils import add_menuitem
from QuestionDialog import QuestionDialog
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -92,6 +84,7 @@ class GrampsBar(gtk.Notebook):
self.uistate = uistate self.uistate = uistate
self.pageview = pageview self.pageview = pageview
self.configfile = os.path.join(const.VERSION_DIR, "%s.ini" % configfile) self.configfile = os.path.join(const.VERSION_DIR, "%s.ini" % configfile)
self.defaults = defaults
self.detached_gramplets = [] self.detached_gramplets = []
self.empty = False self.empty = False
@ -297,6 +290,14 @@ class GrampsBar(gtk.Notebook):
return [gramplet.gname for gramplet in self.get_children() + return [gramplet.gname for gramplet in self.get_children() +
self.detached_gramplets] self.detached_gramplets]
def restore(self):
"""
Restore the GrampsBar to its default gramplets.
"""
map(self.remove_gramplet, self.all_gramplets())
map(self.add_gramplet, self.defaults)
self.set_current_page(0)
def __create_empty_tab(self): def __create_empty_tab(self):
""" """
Create an empty tab to be displayed when the GrampsBar is empty. Create an empty tab to be displayed when the GrampsBar is empty.
@ -319,7 +320,7 @@ class GrampsBar(gtk.Notebook):
def __create_tab_label(self, gramplet): def __create_tab_label(self, gramplet):
""" """
Create a tab label consisting of a label and a close button. Create a tab label.
""" """
label = gtk.Label() label = gtk.Label()
if hasattr(gramplet.pui, "has_data"): if hasattr(gramplet.pui, "has_data"):
@ -412,18 +413,19 @@ class GrampsBar(gtk.Notebook):
Called when a button is pressed in the tabs section of the GrampsBar. Called when a button is pressed in the tabs section of the GrampsBar.
""" """
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 menu = gtk.Menu()
ag_menu = uiman.get_widget('/GrampsBarPopup/AddGramplet')
ag_menu = gtk.MenuItem(_('Add a gramplet'))
nav_type = self.pageview.navigation_type() nav_type = self.pageview.navigation_type()
skip = self.all_gramplets() skip = self.all_gramplets()
gramplet_list = GET_GRAMPLET_LIST(nav_type, skip) gramplet_list = GET_GRAMPLET_LIST(nav_type, skip)
gramplet_list.sort() gramplet_list.sort()
self.__create_submenu(ag_menu, gramplet_list, self.__add_clicked) self.__create_submenu(ag_menu, gramplet_list, self.__add_clicked)
ag_menu.show()
menu.append(ag_menu)
rg_menu = uiman.get_widget('/GrampsBarPopup/RemoveGramplet') if not self.empty:
if self.empty: rg_menu = gtk.MenuItem(_('Remove a gramplet'))
rg_menu.hide()
else:
gramplet_list = [(gramplet.title, gramplet.gname) gramplet_list = [(gramplet.title, gramplet.gname)
for gramplet in self.get_children() + for gramplet in self.get_children() +
self.detached_gramplets] self.detached_gramplets]
@ -431,11 +433,16 @@ class GrampsBar(gtk.Notebook):
self.__create_submenu(rg_menu, gramplet_list, self.__create_submenu(rg_menu, gramplet_list,
self.__remove_clicked) self.__remove_clicked)
rg_menu.show() rg_menu.show()
menu.append(rg_menu)
rd_menu = gtk.MenuItem(_('Restore default gramplets'))
rd_menu.connect("activate", self.__restore_clicked)
rd_menu.show()
menu.append(rd_menu)
menu.popup(None, None, None, 1, event.time)
return True
menu = uiman.get_widget('/GrampsBarPopup')
if menu:
menu.popup(None, None, None, 1, event.time)
return True
return False return False
def __create_submenu(self, main_menu, gramplet_list, callback_func): def __create_submenu(self, main_menu, gramplet_list, callback_func):
@ -464,6 +471,16 @@ class GrampsBar(gtk.Notebook):
""" """
self.remove_gramplet(gname) self.remove_gramplet(gname)
def __restore_clicked(self, menu):
"""
Called when restore defaults is clicked from the context menu.
"""
QuestionDialog(_("Restore to defaults?"),
_("The Grampsbar will be restored to contain its default "
"gramplets. This action cannot be undone."),
_("OK"),
self.restore)
def get_config_funcs(self): def get_config_funcs(self):
""" """
Return a list of configuration functions. Return a list of configuration functions.

View File

@ -111,10 +111,6 @@ class PageView(DbGUIElement):
</placeholder> </placeholder>
</menu> </menu>
</menubar> </menubar>
<popup name="GrampsBarPopup">
<menuitem action="AddGramplet"/>
<menuitem action="RemoveGramplet"/>
</popup>
</ui>''' </ui>'''
self.dirty = True self.dirty = True
self.active = False self.active = False
@ -413,9 +409,6 @@ class PageView(DbGUIElement):
self._add_toggle_action('Bottombar', None, _('_Bottombar'), self._add_toggle_action('Bottombar', None, _('_Bottombar'),
"<shift><control>B", None, self.__bottombar_toggled, "<shift><control>B", 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("RemoveGramplet", gtk.STOCK_REMOVE,
_("Remove a gramplet"))
def __build_action_group(self): def __build_action_group(self):
""" """