From ccf1f2eac5b76c445a5036ea8639497333ec8090 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 5 Jun 2013 21:47:18 +0000 Subject: [PATCH] GEP 18: add autotitle setting from given attributes svn: r22483 --- .../gui/editors/displaytabs/srctemplatetab.py | 35 +++++++++++++++++-- gramps/gui/editors/editsource.py | 15 +++++--- gramps/gui/glade/editsource.glade | 16 +++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/gramps/gui/editors/displaytabs/srctemplatetab.py b/gramps/gui/editors/displaytabs/srctemplatetab.py index 5c72a543e..a527057d0 100644 --- a/gramps/gui/editors/displaytabs/srctemplatetab.py +++ b/gramps/gui/editors/displaytabs/srctemplatetab.py @@ -43,7 +43,7 @@ from gi.repository import Gtk #------------------------------------------------------------------------- from gramps.gen.lib.srcattrtype import (SrcAttributeType, REF_TYPE_F, REF_TYPE_S, REF_TYPE_L, EMPTY) -from gramps.gen.lib.srcattribute import SrcAttribute +from gramps.gen.lib import SrcAttribute, SrcTemplate from ...autocomp import StandardCustomSelector from ...widgets.srctemplatetreeview import SrcTemplateTreeView from ...widgets import UndoableEntry, MonitoredEntry @@ -80,7 +80,9 @@ class SrcTemplateTab(GrampsTab): self.glade = glade self.callback_src_changed = callback_src_changed self.readonly = dbstate.db.readonly - + + self.autoset_title = False + GrampsTab.__init__(self, dbstate, uistate, track, _("Source Template")) eventbox = Gtk.EventBox() widget = self.glade.get_object('gridtemplate') @@ -93,6 +95,7 @@ class SrcTemplateTab(GrampsTab): self.inpts = [] self.monentry = [] self.gridfields = self.glade.get_object('gridfields') + self.autotitle = self.glade.get_object("autotitle_checkbtn") #self.vbox_fields_label = self.glade.get_object('fields_01') #self.vbox_fields_input = self.glade.get_object('fields_02') self.setup_interface(self.glade.get_object('scrolledtemplates')) @@ -117,6 +120,34 @@ class SrcTemplateTab(GrampsTab): self.temp_tv = SrcTemplateTreeView(templ[2], sel_callback=self.on_template_selected) scrolled.add(self.temp_tv) + + #autotitle checkbox + self.autotitle.set_active(self.autotitle_get_orig_val()) + self.autotitle.set_sensitive(not self.dbstate.db.readonly) + self.autotitle.connect('toggled', self.autotitle_on_toggle) + + def autotitle_get_orig_val(self): + """ + If title of the source is what we would set with autotitle, we set + the checkbox to true. Otherwise to False + """ + srctemp = SrcTemplate(self.src.get_source_template()[0]) + srctemp.set_attr_list(self.src.get_attribute_list()) + title = srctemp.title_gedcom() + if self.src.get_title() == title: + self.autoset_title = True + else: + self.autoset_title = False + return self.autoset_title + + def autotitle_on_toggle(self, obj): + """ the autoset_title attribute will be used in editsource to + determine that title must be set + """ + self.autoset_title = obj.get_active() + #it might be that the title must be changed, so we trigger the callback + # which will update the title in the source object + self.callback_src_changed() def on_template_selected(self, index, key): """ diff --git a/gramps/gui/editors/editsource.py b/gramps/gui/editors/editsource.py index ba6714d9e..4f880f31a 100644 --- a/gramps/gui/editors/editsource.py +++ b/gramps/gui/editors/editsource.py @@ -80,6 +80,8 @@ class EditSource(EditPrimary): """ self.srctemp = None self.citation = citation + self.template_tab = None + self.attr_tab = None if not source and not citation: raise NotImplementedError elif not source: @@ -104,13 +106,13 @@ class EditSource(EditPrimary): def get_menu_title(self): title = self.obj.get_title() - if title: + if self.obj.get_handle(): title = _('Source') + ": " + title else: title = _('New Source') if self.citation is not None: citeid = self.citation.get_gramps_id() - if citeid: + if self.citation.get_handle(): if self.callertitle: title = _('Citation: %(id)s - %(context)s' % { 'id' : citeid, @@ -331,6 +333,12 @@ class EditSource(EditPrimary): self.refS.set_text(_("")) self.author.set_text(self.srctemp.author_gedcom()) self.pubinfo.set_text(self.srctemp.pubinfo_gedcom()) + if self.template_tab and self.template_tab.autoset_title: + title = self.srctemp.title_gedcom() + self.obj.set_title(title) + self.title.update() + #lastly update the window title + self.update_title(self.get_menu_title()) def update_template_data(self): """ @@ -358,14 +366,13 @@ class EditSource(EditPrimary): notebook = self.glade.get_object('notebook') gridsrc = self.glade.get_object('gridsrc') #recreate start page as GrampsTab + notebook.remove_page(1) notebook.remove_page(0) self.overviewtab = RefTab(self.dbstate, self.uistate, self.track, _('Overview'), gridsrc) self._add_tab(notebook, self.overviewtab) #recreate second page as GrampsTab - notebook.remove_page(0) - self.attr_tab = None self.template_tab = SrcTemplateTab(self.dbstate, self.uistate, self.track, self.obj, self.glade, self.update_template_data diff --git a/gramps/gui/glade/editsource.glade b/gramps/gui/glade/editsource.glade index 33e34e589..bb58af441 100644 --- a/gramps/gui/glade/editsource.glade +++ b/gramps/gui/glade/editsource.glade @@ -957,6 +957,22 @@ + + False + True + 0 + + + + + Automatically set Source title from source fields + True + True + False + 3 + 0 + True + False True