From 8b6077a95e9de0aedd00807e82b723281b90f376 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 3 Feb 2010 23:31:38 +0000 Subject: [PATCH] Give relview a configuration, remove old config from preferences svn: r14204 --- src/config.py | 5 -- src/gui/configure.py | 89 ++++--------------- src/gui/views/listview.py | 2 +- src/gui/views/pageview.py | 2 +- src/gui/widgets/labels.py | 75 ++++++++++++---- src/plugins/view/relview.py | 171 ++++++++++++++++++++++++++---------- 6 files changed, 199 insertions(+), 145 deletions(-) diff --git a/src/config.py b/src/config.py index 02259d2b4..41d66d565 100644 --- a/src/config.py +++ b/src/config.py @@ -223,7 +223,6 @@ register('interface.place-sel-height', 450) register('interface.place-sel-width', 600) register('interface.place-width', 650) register('interface.prefix-suffix', 0) -register('interface.releditbtn', False) register('interface.repo-height', 450) register('interface.repo-ref-height', 450) register('interface.repo-ref-width', 600) @@ -257,8 +256,6 @@ register('preferences.date-format', 0) register('preferences.calendar-format-report', 0) register('preferences.default-source', False) register('preferences.eprefix', 'E%04d') -register('preferences.family-details', True) -register('preferences.family-siblings', True) register('preferences.family-warn', True) register('preferences.fprefix', 'F%04d') register('preferences.hide-ep-msg', False) @@ -278,8 +275,6 @@ register('preferences.pprefix', 'P%04d') register('preferences.private-given-text', "[%s]" % _("Living")) register('preferences.private-record-text', "[%s]" % _("Private Record")) register('preferences.private-surname-text', "[%s]" % _("Living")) -register('preferences.relation-display-theme', "CLASSIC") -register('preferences.relation-shade', True) register('preferences.rprefix', 'R%04d') register('preferences.sprefix', 'S%04d') register('preferences.todo-color', '#ff0000') diff --git a/src/gui/configure.py b/src/gui/configure.py index cb56b5576..3bb383dc9 100644 --- a/src/gui/configure.py +++ b/src/gui/configure.py @@ -2,7 +2,8 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2008 Raphael Ackermann +# Copyright (C) 2008 Raphael Ackermann +# Copyright (C) 2010 Benny Malengier # # 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 @@ -178,7 +179,7 @@ class ConfigureDialog(ManagedWindow.ManagedWindow): This method builds the notebookpages in the panel """ for func in configure_page_funcs: - labeltitle, widget = func() + labeltitle, widget = func(self) self.panel.append_page(widget, MarkupLabel(labeltitle)) def done(self, obj, value): @@ -324,7 +325,7 @@ class GrampsPreferences(ConfigureDialog): GrampsPreferences, config, on_close=Utils.update_constants) - def add_researcher_panel(self): + def add_researcher_panel(self, configdialog): table = gtk.Table(3, 8) table.set_border_width(12) table.set_col_spacings(6) @@ -339,7 +340,7 @@ class GrampsPreferences(ConfigureDialog): self.add_entry(table, _('Email'), 7, 'researcher.researcher-email') return _('Researcher'), table - def add_prefix_panel(self): + def add_prefix_panel(self, configdialog): """ Add the ID prefix tab to the preferences. """ @@ -365,7 +366,7 @@ class GrampsPreferences(ConfigureDialog): self.update_idformat_entry) return _('ID Formats'), table - def add_advanced_panel(self): + def add_advanced_panel(self, configdialog): table = gtk.Table(4, 8) table.set_border_width(12) table.set_col_spacings(6) @@ -389,7 +390,7 @@ class GrampsPreferences(ConfigureDialog): return _('Warnings'), table - def add_color_panel(self): + def add_color_panel(self, configdialog): table = gtk.Table(3, 8) table.set_border_width(12) table.set_col_spacings(12) @@ -423,58 +424,6 @@ class GrampsPreferences(ConfigureDialog): for widget in [self.comp_color, self.todo_color, self.custom_color]: widget.emit('color-set') - def add_name_panel(self): - """ - Name format settings panel - """ - - # a dummy name to be used in the examples - self.examplename = Name() - self.examplename.set_title('Dr.') - self.examplename.set_first_name('Edwin Jose') - self.examplename.set_surname_prefix('von der') - self.examplename.set_surname('Smith') - self.examplename.set_suffix('Sr') - self.examplename.set_patronymic('Wilson') - self.examplename.set_call_name('Ed') - - table = gtk.Table(2, 2) - table.set_border_width(12) - table.set_col_spacings(6) - table.set_row_spacings(6) - - # get the model for the combo and the treeview - active = _nd.get_default_format() - self.fmt_model, active = self._build_name_format_model(active) - - # set up the combo to choose the preset format - self.fmt_obox = gtk.ComboBox() - cell = gtk.CellRendererText() - self.fmt_obox.pack_start(cell, True) - self.fmt_obox.add_attribute(cell, 'text', 1) - self.fmt_obox.set_model(self.fmt_model) - - # set the default value as active in the combo - self.fmt_obox.set_active(active) - self.fmt_obox.connect('changed', self.cb_name_changed) - # label for the combo - lwidget = BasicLabel("%s: " % _('_Display format')) - lwidget.set_use_underline(True) - lwidget.set_mnemonic_widget(self.fmt_obox) - - # build the format manager ui - custom_ui = self._build_custom_name_ui() - name_exp = gtk.expander_new_with_mnemonic(_('C_ustom format details')) - name_exp.add(custom_ui) - name_exp.set_sensitive(self.dbstate.open) - - # put all these together - table.attach(lwidget, 0, 1, 0, 1, yoptions=0) - table.attach(self.fmt_obox, 1, 2, 0, 1, yoptions=0) - table.attach(name_exp, 0, 2, 1, 2, yoptions=gtk.FILL|gtk.EXPAND) - - return table - def _build_name_format_model(self, active): """ Create a common model for ComboBox and TreeView @@ -796,7 +745,7 @@ class GrampsPreferences(ConfigureDialog): self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True, only_active=False) - def add_formats_panel(self): + def add_formats_panel(self, configdialog): row = 0 table = gtk.Table(4, 4) table.set_border_width(12) @@ -901,7 +850,7 @@ class GrampsPreferences(ConfigureDialog): row += 1 return _('Display'), table - def add_text_panel(self): + def add_text_panel(self, configdialog): row = 0 table = gtk.Table(6, 8) table.set_border_width(12) @@ -944,7 +893,7 @@ class GrampsPreferences(ConfigureDialog): config.set('preferences.calendar-format-report', obj.get_active()) - def add_date_panel(self): + def add_date_panel(self, configdialog): table = gtk.Table(2, 7) table.set_border_width(12) table.set_col_spacings(6) @@ -977,8 +926,8 @@ class GrampsPreferences(ConfigureDialog): return _('Dates'), table - def add_behavior_panel(self): - table = gtk.Table(3, 8) + def add_behavior_panel(self, configdialog): + table = gtk.Table(3, 6) table.set_border_width(12) table.set_col_spacings(6) table.set_row_spacings(6) @@ -992,27 +941,21 @@ class GrampsPreferences(ConfigureDialog): self.add_checkbox(table, _('Display Tip of the Day'), 2, 'behavior.use-tips') - self.add_checkbox(table, - _('Use shading in Relationship View'), - 3, 'preferences.relation-shade') - self.add_checkbox(table, - _('Display edit buttons on Relationship View'), - 4, 'interface.releditbtn') self.add_checkbox(table, _('Remember last view displayed'), - 5, 'preferences.use-last-view') + 3, 'preferences.use-last-view') self.add_pos_int_entry(table, _('Max generations for relationships'), - 6, 'behavior.generation-depth', self.update_gen_depth) + 4, 'behavior.generation-depth', self.update_gen_depth) self.path_entry = gtk.Entry() self.add_path_box(table, _('Base path for relative media paths'), - 7, self.path_entry, self.dbstate.db.get_mediapath(), + 5, self.path_entry, self.dbstate.db.get_mediapath(), self.set_mediapath, self.select_mediapath) return _('General'), table - def add_database_panel(self): + def add_database_panel(self, configdialog): table = gtk.Table(2, 2) table.set_border_width(12) table.set_col_spacings(6) diff --git a/src/gui/views/listview.py b/src/gui/views/listview.py index c79c0513a..dca873ab0 100644 --- a/src/gui/views/listview.py +++ b/src/gui/views/listview.py @@ -1077,7 +1077,7 @@ class ListView(NavigationView): :return: list of functions """ - def columnpage(): + def columnpage(configdialog): return _('Columns'), ColumnOrder(self._config, self.COLUMN_NAMES, self.set_column_order, tree=self.type_list()==LISTTREE) diff --git a/src/gui/views/pageview.py b/src/gui/views/pageview.py index 23c8f3155..028496987 100644 --- a/src/gui/views/pageview.py +++ b/src/gui/views/pageview.py @@ -392,7 +392,7 @@ class PageView(DbGUIElement): def init_config(self): """ If you need a view with a config, then call this method in the - build_tree method. It will set up a config file for the + build_widget or __init__ method. It will set up a config file for the view, and use CONFIGSETTINGS to set the config defaults. The config is later accessbile via self._config So you can do diff --git a/src/gui/widgets/labels.py b/src/gui/widgets/labels.py index 9081491fb..eacc6c80b 100644 --- a/src/gui/widgets/labels.py +++ b/src/gui/widgets/labels.py @@ -47,7 +47,6 @@ import pango # Gramps modules # #------------------------------------------------------------------------- -import config #------------------------------------------------------------------------- # @@ -71,27 +70,44 @@ def realize_cb(widget): #------------------------------------------------------------------------- class LinkLabel(gtk.EventBox): - def __init__(self, label, func, handle, decoration=None): - if decoration is None: - relation_display_theme = config.get('preferences.relation-display-theme') - if relation_display_theme == "CLASSIC": - decoration = 'underline="single"' - elif relation_display_theme == "WEBPAGE": - decoration = 'foreground="blue"' + def __init__(self, label, func, handle, emph=False, theme="CLASSIC"): + self.theme = theme + self.emph = emph + if emph: + #emphasize a link + if theme == "CLASSIC": + format = 'underline="single" weight="heavy" style="italic"' + elif theme == "WEBPAGE": + format = 'foreground="blue" weight="heavy"' else: - raise AttributeError("invalid relation-display-theme: '%s'" % relation_display_theme) + raise AttributeError("invalid theme: '%s'" % theme) + elif emph is None: + #emphasize, but not a link + if theme == "CLASSIC": + format = 'weight="heavy"' + elif theme == "WEBPAGE": + format = 'weight="heavy"' + else: + raise AttributeError("invalid theme: '%s'" % theme) + else: + #no emphasize, a link + if theme == "CLASSIC": + format = 'underline="single"' + elif theme == "WEBPAGE": + format = 'foreground="blue"' + else: + raise AttributeError("invalid theme: '%s'" % theme) gtk.EventBox.__init__(self) self.orig_text = cgi.escape(label[0]) self.gender = label[1] - self.decoration = decoration + self.decoration = format text = '%s' % (self.decoration, self.orig_text) if func: msg = _('Click to make this person active\n' - 'Right click to display the edit menu') - if not config.get('interface.releditbtn'): - msg += "\n" + _('Edit icons can be enabled in the Preferences dialog') + 'Right click to display the edit menu\n' + 'Click Edit icon (enable in configuration dialog) to edit') self.set_tooltip_text(msg) @@ -116,13 +132,34 @@ class LinkLabel(gtk.EventBox): self.label.set_padding(x, y) def enter_text(self, obj, event, handle): - relation_display_theme = config.get('preferences.relation-display-theme') - if relation_display_theme == "CLASSIC": - text = '%s' % (self.decoration, self.orig_text) - elif relation_display_theme == "WEBPAGE": - text = '%s' % (self.decoration, self.orig_text) + if self.emph: + #emphasize a link + if self.theme == "CLASSIC": + format = 'foreground="blue" underline="single" '\ + 'weight="heavy" style="italic"' + elif self.theme == "WEBPAGE": + format = 'underline="single" foreground="blue" '\ + 'weight="heavy"' + else: + raise AttributeError("invalid theme: '%s'" % theme) + elif self.emph is None: + # no link, no change on enter_text + if self.theme == "CLASSIC": + format = 'weight="heavy"' + elif self.theme == "WEBPAGE": + format = 'weight="heavy"' + else: + raise AttributeError("invalid theme: '%s'" % theme) else: - raise AttributeError("invalid relation-display-theme: '%s'" % relation_display_theme) + #no emphasize, a link + if self.theme == "CLASSIC": + format = 'foreground="blue" underline="single"' + elif self.theme == "WEBPAGE": + format = 'underline="single" foreground="blue"' + else: + raise AttributeError("invalid theme: '%s'" % theme) + + text = '%s' % (format, self.orig_text) self.label.set_text(text) self.label.set_use_markup(True) diff --git a/src/plugins/view/relview.py b/src/plugins/view/relview.py index 1a53cb638..dfab115c7 100644 --- a/src/plugins/view/relview.py +++ b/src/plugins/view/relview.py @@ -115,6 +115,18 @@ class AttachList(object): self.max_y = max(self.max_y, y1) class RelationshipView(NavigationView): + """ + View showing a textual representation of the relationships of the + active person + """ + #settings in the config file + CONFIGSETTINGS = ( + ('preferences.family-siblings', True), + ('preferences.family-details', True), + ('preferences.relation-display-theme', "CLASSIC"), + ('preferences.relation-shade', True), + ('preferences.releditbtn', True), + ) def __init__(self, dbstate, uistate, nav_group=0): NavigationView.__init__(self, _('Relationships'), @@ -128,22 +140,12 @@ class RelationshipView(NavigationView): } dbstate.connect('database-changed', self.change_db) - self.show_siblings = config.get('preferences.family-siblings') - self.show_details = config.get('preferences.family-details') self.redrawing = False - self.use_shade = config.get('preferences.relation-shade') - self.toolbar_visible = config.get('interface.toolbar-on') self.color = gtk.TextView().style.white self.child = None self.old_handle = None - config.connect("preferences.relation-shade", - self.shade_update) - config.connect("interface.releditbtn", - self.config_update) - config.connect("interface.toolbar-on", - self.shade_update) self.reorder_sensitive = False self.collapsed_items = {} @@ -167,11 +169,35 @@ class RelationshipView(NavigationView): def navigation_type(self): return 'Person' + def can_configure(self): + """ + See :class:`~gui.views.pageview.PageView + :return: bool + """ + return True + + def on_delete(self): + self._config.save() + NavigationView.on_delete(self) + + def set_ident(self, ident): + """ + Set the id of the view. This is an unique ident + 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') + self.theme = self._config.get('preferences.relation-display-theme') + self.toolbar_visible = config.get('interface.toolbar-on') + def goto_handle(self, handle): self.change_person(handle) def shade_update(self, client, cnxn_id, entry, data): - self.use_shade = config.get('preferences.relation-shade') + self.use_shade = self._config.get('preferences.relation-shade') self.toolbar_visible = config.get('interface.toolbar-on') self.uistate.modify_statusbar(self.dbstate) self.redraw() @@ -251,7 +277,10 @@ class RelationshipView(NavigationView): return 'gramps-relation' def build_widget(self): - + """ + Build the widget that contains the view, see + :class:`~gui.views.pageview.PageView + """ container = gtk.VBox() container.set_border_width(12) @@ -394,12 +423,12 @@ class RelationshipView(NavigationView): def siblings_toggle(self, obj): self.show_siblings = obj.get_active() self.change_person(self.get_active()) - config.set('preferences.family-siblings', self.show_siblings) + self._config.set('preferences.family-siblings', self.show_siblings) def details_toggle(self, obj): self.show_details = obj.get_active() self.change_person(self.get_active()) - config.set('preferences.family-details', self.show_details) + self._config.set('preferences.family-details', self.show_details) def change_db(self, db): #reset the connects @@ -556,7 +585,7 @@ class RelationshipView(NavigationView): text = fmt % cgi.escape(name) label = widgets.DualMarkupLabel(text, _GenderCode[person.gender], x_align=1, y_align=0) - if config.get('interface.releditbtn'): + if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_button_press, person.handle) button.set_tooltip_text(_('Edit %s') % name) @@ -946,10 +975,11 @@ class RelationshipView(NavigationView): initial_name = False if handle: name = self.get_name(handle, True) - link_label = widgets.LinkLabel(name, self._button_press, handle) + link_label = widgets.LinkLabel(name, self._button_press, + handle, theme=self.theme) if self.use_shade: link_label.modify_bg(gtk.STATE_NORMAL, self.color) - if config.get('interface.releditbtn'): + if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_button_press, handle) button.set_tooltip_text(_('Edit %s') % name[0]) @@ -975,7 +1005,7 @@ class RelationshipView(NavigationView): label = widgets.MarkupLabel(format % cgi.escape(title), x_align=1, y_align=0) - if config.get('interface.releditbtn'): + if self._config.get('preferences.releditbtn'): label.set_padding(0, 5) self.attach.attach(label, _PLABEL_START, _PLABEL_STOP, self.row, self.row+1, xoptions=gtk.FILL|gtk.SHRINK, @@ -988,22 +1018,17 @@ class RelationshipView(NavigationView): person = self.dbstate.db.get_person_from_handle(handle) parent = len(person.get_parent_family_handle_list()) > 0 format = '' - relation_display_theme = config.get('preferences.relation-display-theme') + relation_display_theme = self._config.get( + 'preferences.relation-display-theme') if parent: - if relation_display_theme == "CLASSIC": - format = 'underline="single" weight="heavy" style="italic"' - elif relation_display_theme == "WEBPAGE": - format = 'foreground="blue" weight="heavy"' + emph = True else: - if relation_display_theme == "CLASSIC": - format = 'underline="single"' - elif relation_display_theme == "WEBPAGE": - format = 'foreground="blue"' + emph = False link_label = widgets.LinkLabel(name, self._button_press, - handle, format) + handle, emph, theme=self.theme) if self.use_shade: link_label.modify_bg(gtk.STATE_NORMAL, self.color) - if config.get('interface.releditbtn'): + if self._config.get('preferences.releditbtn'): button = widgets.IconButton(self.edit_button_press, handle) button.set_tooltip_text(_('Edit %s') % name[0]) else: @@ -1038,7 +1063,7 @@ class RelationshipView(NavigationView): lbl = widgets.MarkupLabel(format % cgi.escape(title), x_align=1, y_align=.5) - if config.get('interface.releditbtn'): + if self._config.get('preferences.releditbtn'): lbl.set_padding(0, 5) return lbl @@ -1061,23 +1086,15 @@ class RelationshipView(NavigationView): self.dbstate.db.get_person_from_handle(handle)) format = '' - relation_display_theme = config.get('preferences.relation-display-theme') + relation_display_theme = self._config.get( + 'preferences.relation-display-theme') + emph = False if child_should_be_linked and parent: - if relation_display_theme == "CLASSIC": - format = 'underline="single" weight="heavy" style="italic"' - elif relation_display_theme == "WEBPAGE": - format = 'foreground="blue" weight="heavy"' - else: - raise AttributeError("invalid relation-display-theme: '%s'" % relation_display_theme) + emph = True elif child_should_be_linked and not parent: - if relation_display_theme == "CLASSIC": - format = 'underline="single"' - elif relation_display_theme == "WEBPAGE": - format = 'foreground="blue"' - else: - raise AttributeError("invalid relation-display-theme: '%s'" % relation_display_theme) + emph = False elif parent and not child_should_be_linked: - format = 'weight="heavy"' + emph = None if child_should_be_linked: link_func = self._button_press @@ -1085,12 +1102,14 @@ class RelationshipView(NavigationView): link_func = None name = self.get_name(handle, True) - link_label = widgets.LinkLabel(name, link_func, handle, format) + link_label = widgets.LinkLabel(name, link_func, handle, emph, + theme=self.theme) if self.use_shade: link_label.modify_bg(gtk.STATE_NORMAL, self.color) link_label.set_padding(3, 0) - if child_should_be_linked and config.get('interface.releditbtn'): + if child_should_be_linked and self._config.get( + 'preferences.releditbtn'): button = widgets.IconButton(self.edit_button_press, handle) button.set_tooltip_text(_('Edit %s') % name[0]) else: @@ -1580,6 +1599,66 @@ class RelationshipView(NavigationView): except Errors.WindowActiveError: pass + def config_connect(self): + """ + Overwriten from :class:`~gui.views.pageview.PageView method + This method will be called after the ini file is initialized, + use it to monitor changes in the ini file + """ + self._config.connect("preferences.relation-shade", + self.shade_update) + self._config.connect("preferences.releditbtn", + self.config_update) + self._config.connect("preferences.relation-display-theme", + self.config_update) + config.connect("interface.toolbar-on", + self.shade_update) + + def config_panel(self, configdialog): + """ + Function that builds the widget in the configuration dialog + """ + table = gtk.Table(3, 2) + table.set_border_width(12) + table.set_col_spacings(6) + table.set_row_spacings(6) + + configdialog.add_checkbox(table, + _('Use shading'), + 0, 'preferences.relation-shade') + configdialog.add_checkbox(table, + _('Display edit buttons'), + 1, 'preferences.releditbtn') + checkbox = gtk.CheckButton(_('View links as website links')) + theme = self._config.get('preferences.relation-display-theme') + checkbox.set_active(theme == 'WEBPAGE') + checkbox.connect('toggled', self._config_update_theme) + table.attach(checkbox, 1, 9, 2, 3, yoptions=0) + + return _('Layout'), table + + def _config_update_theme(self, obj): + """ + callback from the theme checkbox + """ + if obj.get_active(): + self.theme = 'WEBPAGE' + self._config.set('preferences.relation-display-theme', + 'WEBPAGE') + else: + self.theme = 'CLASSIC' + self._config.set('preferences.relation-display-theme', + 'CLASSIC') + + def _get_configure_page_funcs(self): + """ + Return a list of functions that create gtk elements to use in the + notebook pages of the Configure dialog + + :return: list of functions + """ + return [self.config_panel] + #------------------------------------------------------------------------- # # Function to return if person has children