From 06e4dcd11d9c18434df99edde413470fa44491d4 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Fri, 14 Jun 2013 11:05:21 +0000 Subject: [PATCH] GEP 18: fix bug setting cite when no cite loaded. Factor out fields for reuse in citation GUI svn: r22507 --- .../gui/editors/displaytabs/srctemplatetab.py | 90 ++++++++++++------- gramps/gui/editors/editsource.py | 3 +- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/gramps/gui/editors/displaytabs/srctemplatetab.py b/gramps/gui/editors/displaytabs/srctemplatetab.py index 859b9df05..20f0c5dc6 100644 --- a/gramps/gui/editors/displaytabs/srctemplatetab.py +++ b/gramps/gui/editors/displaytabs/srctemplatetab.py @@ -91,10 +91,9 @@ class SrcTemplateTab(GrampsTab): self._set_label(show_image=False) widget.connect('key_press_event', self.key_pressed) - self.lbls = [] - self.inpts = [] - self.monentry = [] - self.gridfields = self.glade.get_object('gridfields') + self.tmplfields = TemplateFields(self.dbstate.db, + self.glade.get_object('gridfields'), + self.src, None, self.callback_src_changed, None) 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') @@ -165,34 +164,36 @@ class SrcTemplateTab(GrampsTab): srcattr = SrcAttributeType() if index in srcattr.EVIDENCETEMPLATES: #a predefined template, - self.reset_template_fields(srcattr.EVIDENCETEMPLATES[index]) + self.tmplfields.reset_template_fields(srcattr.EVIDENCETEMPLATES[index]) - def _add_entry(self, row, srcattrtype, label): +#------------------------------------------------------------------------- +# +# TemplateFields Class +# +#------------------------------------------------------------------------- +class TemplateFields(object): + """ + Class to manage fields of a source template. + Can be used on source and on citation level. + """ + def __init__(self, db, grid, src, cite, callback_src_changed, + callback_cite_changed): """ - Add an entryfield to the grid of fields at row row, to edit the given - srcattrtype value. Use label label if given to indicate the field - (otherwise the srcattrtype string description is used) - Note srcattrtype should actually be the integer key of the type! + grid: The Gtk.Grid that should hold the fields + src : The source to which the fields belong + cite: The citation to which the fields belong (set None if only source) """ - self.gridfields.insert_row(row) - field = srcattrtype - #setup label - if not label: - srcattr = SrcAttributeType(field) - label = str(srcattr) - lbl = Gtk.Label(_("%s:") % label) - lbl.set_halign(Gtk.Align.START) - self.gridfields.attach(lbl, 0, row-1, 1, 1) - self.lbls.append(lbl) - #setup entry - inpt = UndoableEntry() - inpt.set_halign(Gtk.Align.FILL) - inpt.set_hexpand(True) - self.gridfields.attach(inpt, 1, row-1, 1, 1) - self.inpts.append(inpt) - MonitoredEntry(inpt, self.set_field, self.get_field, - read_only=self.dbstate.db.readonly, - parameter=srcattrtype) + self.gridfields = grid + self.db = db + self.src = src + self.cite = cite + self.callback_src_changed = callback_src_changed + self.callback_cite_changed = callback_cite_changed + + #storage + self.lbls = [] + self.inpts = [] + self.monentry = [] def reset_template_fields(self, template): # first remove old fields @@ -228,7 +229,6 @@ class SrcTemplateTab(GrampsTab): for fielddef in fieldsS: self._add_entry(row, tempsattrt.short_version(fielddef[1]), '') row += 1 - # now add optional default citation values fieldsF = [fielddef for fielddef in template[REF_TYPE_F] @@ -250,7 +250,35 @@ class SrcTemplateTab(GrampsTab): self._add_entry(row, tempsattrt.short_version(fielddef[1]), '') row += 1 - self.show_all() + self.gridfields.show_all() + + + def _add_entry(self, row, srcattrtype, label): + """ + Add an entryfield to the grid of fields at row row, to edit the given + srcattrtype value. Use label label if given to indicate the field + (otherwise the srcattrtype string description is used) + Note srcattrtype should actually be the integer key of the type! + """ + self.gridfields.insert_row(row) + field = srcattrtype + #setup label + if not label: + srcattr = SrcAttributeType(field) + label = str(srcattr) + lbl = Gtk.Label(_("%s:") % label) + lbl.set_halign(Gtk.Align.START) + self.gridfields.attach(lbl, 0, row-1, 1, 1) + self.lbls.append(lbl) + #setup entry + inpt = UndoableEntry() + inpt.set_halign(Gtk.Align.FILL) + inpt.set_hexpand(True) + self.gridfields.attach(inpt, 1, row-1, 1, 1) + self.inpts.append(inpt) + MonitoredEntry(inpt, self.set_field, self.get_field, + read_only=self.db.readonly, + parameter=srcattrtype) def get_field(self, srcattrtype): """ diff --git a/gramps/gui/editors/editsource.py b/gramps/gui/editors/editsource.py index 75d8cee75..732b5a520 100644 --- a/gramps/gui/editors/editsource.py +++ b/gramps/gui/editors/editsource.py @@ -706,7 +706,8 @@ class EditSource(EditPrimary): else: msg = '' # Make sure citation references this source - self.citation.set_reference_handle(self.obj.handle) + if self.citation: + self.citation.set_reference_handle(self.obj.handle) # Now commit the Citation Primary object if needed if self.citation_loaded: if not self.citation.get_handle():