Store sidebar state in the configuration file

svn: r16274
This commit is contained in:
Nick Hall 2010-12-12 18:58:22 +00:00
parent 84c07b3f56
commit b79b09b86b
9 changed files with 72 additions and 60 deletions

View File

@ -33,13 +33,6 @@ from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
import gtk
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
import config
#-------------------------------------------------------------------------
#
# Sidebar class
@ -49,9 +42,10 @@ class Sidebar(object):
"""
A class which defines the graphical representation of the Gramps sidebar.
"""
def __init__(self, callback):
def __init__(self, changed_callback, close_callback):
self.callback = callback
self.changed_callback = changed_callback
self.close_callback = close_callback
self.pages = []
self.top = gtk.VBox()
@ -77,6 +71,7 @@ class Sidebar(object):
close_button.connect('clicked', self.__close_clicked)
hbox.pack_start(select_button, False)
hbox.pack_end(close_button, False)
frame.show_all()
self.top.pack_start(frame, False)
@ -90,7 +85,7 @@ class Sidebar(object):
self.notebook.set_show_border(False)
self.notebook.connect('switch_page', self.__switch_page)
self.top.pack_start(self.notebook, True)
self.top.show_all()
self.top.show()
def get_display(self):
"""
@ -98,6 +93,24 @@ class Sidebar(object):
"""
return self.top
def show(self):
"""
Display the sidebar.
"""
self.top.show()
def hide(self):
"""
Hide the sidebar.
"""
self.top.hide()
def set_current_page(self, page_num):
"""
Set the sidebar page.
"""
self.notebook.set_current_page(page_num)
def get_page_type(self):
"""
Return the type of the active page.
@ -175,11 +188,10 @@ class Sidebar(object):
if self.pages:
self.title_label.set_markup('<b>%s</b>' % self.pages[index][0])
active = self.top.get_property('visible')
self.callback(self.pages[index][1], active)
self.changed_callback(self.pages[index][1], active, index)
def __close_clicked(self, button):
"""
Called when the sidebar is closed.
"""
config.set('interface.filter', False)
config.save()
self.close_callback()

View File

@ -135,7 +135,7 @@ UIDEFAULT = '''<ui>
<menuitem action="ConfigView"/>
<menuitem action="Navigator"/>
<menuitem action="Toolbar"/>
<menuitem action="Sidebar"/>
<placeholder name="Bars"/>
<menuitem action="Fullscreen"/>
<separator/>
<placeholder name="ViewsInCategory"/>
@ -298,7 +298,6 @@ class ViewManager(CLIManager):
self.show_navigator = config.get('interface.view')
self.show_toolbar = config.get('interface.toolbar-on')
self.show_sidebar = config.get('interface.filter')
self.fullscreen = config.get('interface.fullscreen')
self.__build_main_window()
@ -794,8 +793,6 @@ class ViewManager(CLIManager):
self.navigator_toggle, self.show_navigator ),
('Toolbar', None, _('_Toolbar'), None, None, self.toolbar_toggle,
self.show_toolbar ),
('Sidebar', None, _('_Sidebar'), None, None,
sidebar_toggle, self.show_sidebar),
('Fullscreen', None, _('F_ull Screen'), "F11", None,
self.fullscreen_toggle, self.fullscreen),
]
@ -877,7 +874,6 @@ class ViewManager(CLIManager):
self.fileactions.set_sensitive(True)
self.uistate.widget.set_sensitive(True)
config.connect("interface.statusbar", self.__statusbar_key_update)
config.connect("interface.filter", self.__sidebar_signal)
def __statusbar_key_update(self, client, cnxn_id, entry, data):
"""
@ -885,13 +881,6 @@ class ViewManager(CLIManager):
"""
self.uistate.modify_statusbar(self.dbstate)
def __sidebar_signal(self, client, cnxn_id, entry, data):
"""
Callback function for sidebar key update
"""
if self.sidebar_menu.get_active() != config.get('interface.filter'):
self.sidebar_menu.set_active(config.get('interface.filter'))
def post_init_interface(self, show_manager=True):
"""
Showing the main window is deferred so that
@ -1163,6 +1152,8 @@ class ViewManager(CLIManager):
wspace.add_view(page)
self.pages.append(wspace)
wspace.define_actions()
# create icon/label for workspace notebook
hbox = gtk.HBox()
@ -1726,13 +1717,6 @@ def display_about_box(obj):
about.run()
about.destroy()
def sidebar_toggle(obj):
"""
Save the filter state to the config settings on change
"""
config.set('interface.filter', obj.get_active())
config.save()
def key_bindings(obj):
"""
Display key bindings

View File

@ -131,7 +131,6 @@ class ListView(NavigationView):
contains the interface. This containter will be inserted into
a gtk.Notebook page.
"""
self.init_config()
self.vbox = gtk.VBox()
self.vbox.set_border_width(4)
self.vbox.set_spacing(4)

View File

@ -312,6 +312,7 @@ class PageView(DbGUIElement):
Set the id of the view. This is an unique ident
"""
self.ident = ident
self.init_config()
def get_display(self):
"""
@ -475,6 +476,8 @@ class PageView(DbGUIElement):
use_config_path=True)
for section, value in self.CONFIGSETTINGS:
self._config.register(section, value)
self._config.register('sidebar.visible', True)
self._config.register('sidebar.page', 0)
self._config.init()
self.config_connect()

View File

@ -72,22 +72,14 @@ class Workspace(object):
self.dbstate = dbstate
self.active = False
self.view = None
self.__configure_content = None
self._config = None
self.sidebar = Sidebar(self.sidebar_changed)
self.sidebar = Sidebar(self.sidebar_changed, self.sidebar_closed)
self.hpane = gtk.HPaned()
self.vpane = gtk.VPaned()
self.gramplet_pane = self.__create_gramplet_pane()
self.gramplet_pane.show_all()
self.hpane.pack1(self.vpane, resize=True, shrink=True)
self.hpane.pack2(self.sidebar.get_display(), resize=False, shrink=False)
self.hpane.show()
self.vpane.show()
if config.get('interface.filter'):
self.sidebar.get_display().show()
else:
self.sidebar.get_display().hide()
self.define_actions()
def get_display(self):
"""
@ -101,10 +93,20 @@ class Workspace(object):
"""
self.view = view
self.vpane.add1(view.get_display())
initial_page = self.view._config.get('sidebar.page')
self.gramplet_pane = self.__create_gramplet_pane()
if isinstance(view, ListView):
self.add_filter(view.filter_class)
if self.view._config.get('sidebar.visible'):
self.sidebar.show()
else:
self.sidebar.hide()
self.sidebar.set_current_page(initial_page)
def add_aux(self, aux):
"""
Add an auxilliary object to the workspace.
@ -134,6 +136,13 @@ class Workspace(object):
Create a gramplet pane.
"""
self.uidef = '''<ui>
<menubar name="MenuBar">
<menu action="ViewMenu">
<placeholder name="Bars">
<menuitem action="Sidebar"/>
</placeholder>
</menu>
</menubar>
<popup name="Popup">
<menuitem action="AddGramplet"/>
<menuitem action="RestoreGramplet"/>
@ -143,9 +152,10 @@ class Workspace(object):
eb = gtk.EventBox()
eb.connect('button-press-event', self._gramplet_button_press)
gramplet_pane = GrampletPane("grampletsidebar",
gramplet_pane = GrampletPane(self.view.ident + "_gramplets",
self, self.dbstate, self.uistate,
column_count=1)
gramplet_pane.show_all()
eb.add(gramplet_pane)
eb.show()
self.sidebar.add(_('Gramplets'), eb, GRAMPLET_PAGE)
@ -174,24 +184,32 @@ class Workspace(object):
"""
active = action.get_active()
if active:
self.sidebar.get_display().show()
self.sidebar_changed(self.sidebar.get_page_type(), True)
self.sidebar.show()
self.sidebar_changed(self.sidebar.get_page_type(), True, None)
else:
self.sidebar.get_display().hide()
self.sidebar_changed(None, False)
config.set('interface.filter', active)
config.save()
self.sidebar.hide()
self.sidebar_changed(None, False, None)
self.view._config.set('sidebar.visible', active)
def sidebar_changed(self, page_type, active):
def sidebar_changed(self, page_type, active, index):
"""
Called when the sidebar page is changed.
"""
if index is not None:
self.view._config.set('sidebar.page', index)
if isinstance(self.view, ListView):
if active and page_type == FILTER_PAGE:
self.view.search_bar.hide()
else:
self.view.search_bar.show()
def sidebar_closed(self):
"""
Called when the sidebar close button is clicked.
"""
uimanager = self.uistate.uimanager
uimanager.get_action('/MenuBar/ViewMenu/Bars/Sidebar').activate()
def get_title(self):
"""
Return the title of the view.
@ -207,7 +225,8 @@ class Workspace(object):
self.action_group = gtk.ActionGroup('Workspace')
self.action_group.add_toggle_actions([
('Sidebar', None, _('_Sidebar'),
None, None, self.__sidebar_toggled, config.get('interface.filter'))
None, None, self.__sidebar_toggled,
self.view._config.get('sidebar.visible'))
])
self.action_group.add_actions([
("AddGramplet", None, _("Add a gramplet")),
@ -219,16 +238,16 @@ class Workspace(object):
Called when the view is set as active.
"""
self.active = True
self.view.set_active()
self.gramplet_pane.set_active()
self.view.set_active()
def set_inactive(self):
"""
Called when the view is set as inactive.
"""
self.active = False
self.view.set_inactive()
self.gramplet_pane.set_inactive()
self.view.set_inactive()
def get_actions(self):
"""
@ -291,14 +310,13 @@ class Workspace(object):
"""
Open the configure dialog for the workspace.
"""
if not self.__configure_content:
self.__configure_content = self._get_configure_page_funcs()
__configure_content = self._get_configure_page_funcs()
title = _("Configure %(cat)s - %(view)s") % \
{'cat': self.view.get_translated_category(),
'view': self.view.get_title()}
try:
ViewConfigureDialog(self.uistate, self.dbstate,
self.__configure_content,
__configure_content,
self, self.view._config, dialogtitle=title,
ident=_("%(cat)s - %(view)s") %
{'cat': self.view.get_translated_category(),

View File

@ -479,7 +479,6 @@ class GeoView(HtmlView):
self.filter.pack_start(self.hpaned, True, True)
self.signal_map = {'place-add': self._place_changed,
'place-update' : self._place_changed}
self.init_config()
self.context_id = 0
self.active = False
self.already_testing = False

View File

@ -474,7 +474,6 @@ class HtmlView(PageView):
# The two toolkits ( webkit and mozilla ) are available.
# The user is able to choose what toolkit he will use.
try:
self.init_config()
# preferences.webkit is useful only in geoview;
# not in htmlview.
if self._config.get('preferences.webkit'):

View File

@ -868,7 +868,6 @@ class PedigreeView(NavigationView):
We use this to create immediately the config file with this ident.
"""
NavigationView.set_ident(self, ident)
self.init_config()
# Automatic resize
self.force_size = self._config.get('interface.pedview-tree-size')

View File

@ -189,7 +189,6 @@ class RelationshipView(NavigationView):
We use this to create immediately the config file with this ident.
"""
NavigationView.set_ident(self, ident)
self.init_config()
self.show_siblings = self._config.get('preferences.family-siblings')
self.show_details = self._config.get('preferences.family-details')
self.use_shade = self._config.get('preferences.relation-shade')