diff --git a/gramps/gen/lib/srcattrbase.py b/gramps/gen/lib/srcattrbase.py
index 541ee54ff..2efbcf385 100644
--- a/gramps/gen/lib/srcattrbase.py
+++ b/gramps/gen/lib/srcattrbase.py
@@ -53,7 +53,7 @@ class SrcAttributeBase(AttributeRootBase):
This is the value of the first source template in the attribute list
If not known UNKNOWN is returned as key, which is integer. Other keys
will be str.
- :rtype tuple: (key, description, string_key_as stored)
+ :rtype tuple: (index, description, string_key_as stored)
"""
#no template is UNKNOWN!
templ = SrcAttributeType.UNKNOWN
diff --git a/gramps/gui/editors/displaytabs/srctemplatetab.py b/gramps/gui/editors/displaytabs/srctemplatetab.py
index 20f0c5dc6..2cfe1a021 100644
--- a/gramps/gui/editors/displaytabs/srctemplatetab.py
+++ b/gramps/gui/editors/displaytabs/srctemplatetab.py
@@ -159,12 +159,10 @@ class SrcTemplateTab(GrampsTab):
Selected template changed, we save this and update interface
"""
self.src.set_source_template(index, key)
- self.callback_src_changed()
+ self.callback_src_changed(templatechanged=True)
- srcattr = SrcAttributeType()
- if index in srcattr.EVIDENCETEMPLATES:
- #a predefined template,
- self.tmplfields.reset_template_fields(srcattr.EVIDENCETEMPLATES[index])
+ #a predefined template,
+ self.tmplfields.reset_template_fields(index)
#-------------------------------------------------------------------------
#
@@ -195,7 +193,19 @@ class TemplateFields(object):
self.inpts = []
self.monentry = []
- def reset_template_fields(self, template):
+ def reset_template_fields(self, index):
+ """
+ Method that constructs the actual fields where user can enter data.
+ Template must be the index of the template.
+ """
+ #obtain the template of the index
+ srcattr = SrcAttributeType()
+ if index in srcattr.EVIDENCETEMPLATES:
+ #a predefined template,
+ template = srcattr.EVIDENCETEMPLATES[index]
+ else:
+ return
+
# first remove old fields
for lbl in self.lbls:
self.gridfields.remove(lbl)
@@ -211,29 +221,32 @@ class TemplateFields(object):
fieldsL = []
for fielddef in template[REF_TYPE_L]:
fieldsL.append(fielddef[1])
- self._add_entry(row, fielddef[1], '')
- row += 1
+ if self.cite is None:
+ #these are source fields
+ self._add_entry(row, fielddef[1], '')
+ row += 1
tempsattrt = SrcAttributeType()
# now add optional short citation values
- fieldsS = [fielddef for fielddef in template[REF_TYPE_S]
+ if self.cite is None:
+ fieldsS = [fielddef for fielddef in template[REF_TYPE_S]
if fielddef[1] in fieldsL and fielddef[6]==EMPTY]
- if fieldsS:
- self.gridfields.insert_row(row)
- lbl = Gtk.Label('')
- lbl.set_markup(_("Optional Short Versions:"))
- lbl.set_halign(Gtk.Align.START)
- self.gridfields.attach(lbl, 0, row-1, 2, 1)
- self.lbls.append(lbl)
- row += 1
- for fielddef in fieldsS:
- self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
- row += 1
+ if fieldsS:
+ self.gridfields.insert_row(row)
+ lbl = Gtk.Label('')
+ lbl.set_markup(_("Optional Short Versions:"))
+ lbl.set_halign(Gtk.Align.START)
+ self.gridfields.attach(lbl, 0, row-1, 2, 1)
+ self.lbls.append(lbl)
+ row += 1
+ for fielddef in fieldsS:
+ self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
+ row += 1
- # now add optional default citation values
+ # now add citation values (optional on source level)
fieldsF = [fielddef for fielddef in template[REF_TYPE_F]
if fielddef[1] not in fieldsL]
- if fieldsF:
+ if fieldsF and self.cite is None:
self.gridfields.insert_row(row)
lbl = Gtk.Label('')
lbl.set_markup(_("Optional Default Citation Fields:"))
@@ -246,13 +259,22 @@ class TemplateFields(object):
row += 1
fieldsS = [fielddef for fielddef in template[REF_TYPE_S]
if fielddef[1] not in fieldsL and fielddef[6]==EMPTY]
+ if not self.cite is None:
+ #we indicate with a text these are the short versions
+ if fieldsS:
+ self.gridfields.insert_row(row)
+ lbl = Gtk.Label('')
+ lbl.set_markup(_("Optional Short Versions:"))
+ lbl.set_halign(Gtk.Align.START)
+ self.gridfields.attach(lbl, 0, row-1, 2, 1)
+ self.lbls.append(lbl)
+ row += 1
for fielddef in fieldsS:
self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
row += 1
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
@@ -276,45 +298,62 @@ class TemplateFields(object):
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)
+ if self.cite:
+ MonitoredEntry(inpt, self.set_cite_field, self.get_cite_field,
+ read_only=self.db.readonly,
+ parameter=srcattrtype)
+ else:
+ MonitoredEntry(inpt, self.set_src_field, self.get_src_field,
+ read_only=self.db.readonly,
+ parameter=srcattrtype)
- def get_field(self, srcattrtype):
+ def get_src_field(self, srcattrtype):
+ self.__get_field(srcattrtype, self.src)
+
+ def get_cite_field(self, srcattrtype):
+ self.__get_field(srcattrtype, self.cite)
+
+ def __get_field(self, srcattrtype, obj):
"""
Obtain srcattribute with type srcattrtype, where srcattrtype is an
integer key!
"""
- src = self.src
val = ''
- for attr in src.attribute_list:
+ for attr in obj.attribute_list:
if int(attr.get_type()) == srcattrtype:
val = attr.get_value()
break
return val
- def set_field(self, value, srcattrtype):
+ def set_src_field(self, value, srcattrtype):
+ self.__set_field(value, srcattrtype, self.src)
+ #indicate source object changed
+ self.callback_src_changed()
+
+ def set_cite_field(self, value, srcattrtype):
+ self.__set_field(value, srcattrtype, self.cite)
+ #indicate source object changed
+ self.callback_cite_changed()
+
+ def __set_field(self, value, srcattrtype, obj):
"""
Set attribute of source of type srcattrtype (which is integer!) to
value. If not present, create attribute. If value == '', remove
"""
- src = self.src
value = value.strip()
foundattr = None
- for attr in src.attribute_list:
+ for attr in obj.attribute_list:
if int(attr.get_type()) == srcattrtype:
attr.set_value(value)
foundattr = attr
break
if foundattr and value == '':
- src.remove_attribute(foundattr)
+ obj.remove_attribute(foundattr)
if foundattr is None and value != '':
foundattr = SrcAttribute()
foundattr.set_type(srcattrtype)
foundattr.set_value(value)
- src.add_attribute(foundattr)
- #indicate source object changed
- self.callback_src_changed()
+ obj.add_attribute(foundattr)
## def setup_autocomp_combobox(self):
## """
diff --git a/gramps/gui/editors/editsource.py b/gramps/gui/editors/editsource.py
index 395bf6e86..0f0c80ca6 100644
--- a/gramps/gui/editors/editsource.py
+++ b/gramps/gui/editors/editsource.py
@@ -155,6 +155,7 @@ class EditSource(EditPrimary):
self.notebook_ref = self.glade.get_object('notebook_citation')
self.cinf = self.glade.get_object("cite_info_lbl")
self.btnclose_cite = self.glade.get_object("btnclose_cite")
+ self.tmplfields = None
self.define_warn_box2(self.glade.get_object("warn_box2"))
@@ -377,10 +378,14 @@ class EditSource(EditPrimary):
#lastly update the window title
self.update_title(self.get_menu_title())
- def update_template_data(self):
+ def update_template_data(self, templatechanged=False):
"""
- Change in the template tab must be reflected in other places
+ Change in the template tab of source must be reflected in other places.
+ If template itself changed, templatechanged==True must be passed
"""
+ if templatechanged and self.tmplfields:
+ #the citation template fields must be changed!
+ self.tmplfields.reset_template_fields(self.obj.get_source_template()[0])
if self.attr_tab:
self.attr_tab.rebuild_callback()
self.update_attr()
@@ -496,6 +501,7 @@ class EditSource(EditPrimary):
self.tmplfields = TemplateFields(self.dbstate.db,
self.glade.get_object('grid_citefields'),
self.obj, self.citation, None, self.callback_cite_changed)
+ self.tmplfields.reset_template_fields(self.obj.get_source_template()[0])
self.comment_tab = NoteTab(self.dbstate, self.uistate, self.track,
self.citation.get_note_list(), self.get_menu_title(),
@@ -815,6 +821,8 @@ class EditSource(EditPrimary):
self._create_citation_tabbed_pages()
else:
self.citation_changed()
+ #the citation template fields must be changed!
+ self.tmplfields.reset_template_fields(self.obj.get_source_template()[0])
self.cinf.set_visible(True)
self.btnclose_cite.set_sensitive(True)
self.citation_loaded = True
diff --git a/gramps/gui/glade/editsource.glade b/gramps/gui/glade/editsource.glade
index f37ad7930..ffc0794e7 100644
--- a/gramps/gui/glade/editsource.glade
+++ b/gramps/gui/glade/editsource.glade
@@ -334,7 +334,10 @@
TrueTrue10
+ True
+ Truein
+ 40