GEP 18: fix bug setting cite when no cite loaded. Factor out fields for reuse in citation GUI

svn: r22507
This commit is contained in:
Benny Malengier
2013-06-14 11:05:21 +00:00
parent 3135b2b304
commit 06e4dcd11d
2 changed files with 61 additions and 32 deletions

View File

@@ -91,10 +91,9 @@ class SrcTemplateTab(GrampsTab):
self._set_label(show_image=False) self._set_label(show_image=False)
widget.connect('key_press_event', self.key_pressed) widget.connect('key_press_event', self.key_pressed)
self.lbls = [] self.tmplfields = TemplateFields(self.dbstate.db,
self.inpts = [] self.glade.get_object('gridfields'),
self.monentry = [] self.src, None, self.callback_src_changed, None)
self.gridfields = self.glade.get_object('gridfields')
self.autotitle = self.glade.get_object("autotitle_checkbtn") self.autotitle = self.glade.get_object("autotitle_checkbtn")
#self.vbox_fields_label = self.glade.get_object('fields_01') #self.vbox_fields_label = self.glade.get_object('fields_01')
#self.vbox_fields_input = self.glade.get_object('fields_02') #self.vbox_fields_input = self.glade.get_object('fields_02')
@@ -165,34 +164,36 @@ class SrcTemplateTab(GrampsTab):
srcattr = SrcAttributeType() srcattr = SrcAttributeType()
if index in srcattr.EVIDENCETEMPLATES: if index in srcattr.EVIDENCETEMPLATES:
#a predefined template, #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 grid: The Gtk.Grid that should hold the fields
srcattrtype value. Use label label if given to indicate the field src : The source to which the fields belong
(otherwise the srcattrtype string description is used) cite: The citation to which the fields belong (set None if only source)
Note srcattrtype should actually be the integer key of the type!
""" """
self.gridfields.insert_row(row) self.gridfields = grid
field = srcattrtype self.db = db
#setup label self.src = src
if not label: self.cite = cite
srcattr = SrcAttributeType(field) self.callback_src_changed = callback_src_changed
label = str(srcattr) self.callback_cite_changed = callback_cite_changed
lbl = Gtk.Label(_("%s:") % label)
lbl.set_halign(Gtk.Align.START) #storage
self.gridfields.attach(lbl, 0, row-1, 1, 1) self.lbls = []
self.lbls.append(lbl) self.inpts = []
#setup entry self.monentry = []
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)
def reset_template_fields(self, template): def reset_template_fields(self, template):
# first remove old fields # first remove old fields
@@ -229,7 +230,6 @@ class SrcTemplateTab(GrampsTab):
self._add_entry(row, tempsattrt.short_version(fielddef[1]), '') self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
row += 1 row += 1
# now add optional default citation values # now add optional default citation values
fieldsF = [fielddef for fielddef in template[REF_TYPE_F] fieldsF = [fielddef for fielddef in template[REF_TYPE_F]
if fielddef[1] not in fieldsL] if fielddef[1] not in fieldsL]
@@ -250,7 +250,35 @@ class SrcTemplateTab(GrampsTab):
self._add_entry(row, tempsattrt.short_version(fielddef[1]), '') self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
row += 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): def get_field(self, srcattrtype):
""" """

View File

@@ -706,7 +706,8 @@ class EditSource(EditPrimary):
else: else:
msg = '' msg = ''
# Make sure citation references this source # 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 # Now commit the Citation Primary object if needed
if self.citation_loaded: if self.citation_loaded:
if not self.citation.get_handle(): if not self.citation.get_handle():