GEP 18: show citation template fields, source fields in scrolled window.

svn: r22512
This commit is contained in:
Benny Malengier
2013-06-15 10:17:58 +00:00
parent 9391218f20
commit dce3fc0605
4 changed files with 155 additions and 68 deletions

View File

@@ -53,7 +53,7 @@ class SrcAttributeBase(AttributeRootBase):
This is the value of the first source template in the attribute list 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 If not known UNKNOWN is returned as key, which is integer. Other keys
will be str. will be str.
:rtype tuple: (key, description, string_key_as stored) :rtype tuple: (index, description, string_key_as stored)
""" """
#no template is UNKNOWN! #no template is UNKNOWN!
templ = SrcAttributeType.UNKNOWN templ = SrcAttributeType.UNKNOWN

View File

@@ -159,12 +159,10 @@ class SrcTemplateTab(GrampsTab):
Selected template changed, we save this and update interface Selected template changed, we save this and update interface
""" """
self.src.set_source_template(index, key) self.src.set_source_template(index, key)
self.callback_src_changed() self.callback_src_changed(templatechanged=True)
srcattr = SrcAttributeType() #a predefined template,
if index in srcattr.EVIDENCETEMPLATES: self.tmplfields.reset_template_fields(index)
#a predefined template,
self.tmplfields.reset_template_fields(srcattr.EVIDENCETEMPLATES[index])
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@@ -195,7 +193,19 @@ class TemplateFields(object):
self.inpts = [] self.inpts = []
self.monentry = [] 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 # first remove old fields
for lbl in self.lbls: for lbl in self.lbls:
self.gridfields.remove(lbl) self.gridfields.remove(lbl)
@@ -211,29 +221,32 @@ class TemplateFields(object):
fieldsL = [] fieldsL = []
for fielddef in template[REF_TYPE_L]: for fielddef in template[REF_TYPE_L]:
fieldsL.append(fielddef[1]) fieldsL.append(fielddef[1])
self._add_entry(row, fielddef[1], '') if self.cite is None:
row += 1 #these are source fields
self._add_entry(row, fielddef[1], '')
row += 1
tempsattrt = SrcAttributeType() tempsattrt = SrcAttributeType()
# now add optional short citation values # 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 fielddef[1] in fieldsL and fielddef[6]==EMPTY]
if fieldsS: if fieldsS:
self.gridfields.insert_row(row) self.gridfields.insert_row(row)
lbl = Gtk.Label('') lbl = Gtk.Label('')
lbl.set_markup(_("<b>Optional Short Versions:</b>")) lbl.set_markup(_("<b>Optional Short Versions:</b>"))
lbl.set_halign(Gtk.Align.START) lbl.set_halign(Gtk.Align.START)
self.gridfields.attach(lbl, 0, row-1, 2, 1) self.gridfields.attach(lbl, 0, row-1, 2, 1)
self.lbls.append(lbl) self.lbls.append(lbl)
row += 1 row += 1
for fielddef in fieldsS: for fielddef in fieldsS:
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 citation values (optional on source level)
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]
if fieldsF: if fieldsF and self.cite is None:
self.gridfields.insert_row(row) self.gridfields.insert_row(row)
lbl = Gtk.Label('') lbl = Gtk.Label('')
lbl.set_markup(_("<b>Optional Default Citation Fields:</b>")) lbl.set_markup(_("<b>Optional Default Citation Fields:</b>"))
@@ -246,13 +259,22 @@ class TemplateFields(object):
row += 1 row += 1
fieldsS = [fielddef for fielddef in template[REF_TYPE_S] fieldsS = [fielddef for fielddef in template[REF_TYPE_S]
if fielddef[1] not in fieldsL and fielddef[6]==EMPTY] 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(_("<b>Optional Short Versions:</b>"))
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: for fielddef in fieldsS:
self._add_entry(row, tempsattrt.short_version(fielddef[1]), '') self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
row += 1 row += 1
self.gridfields.show_all() self.gridfields.show_all()
def _add_entry(self, row, srcattrtype, label): def _add_entry(self, row, srcattrtype, label):
""" """
Add an entryfield to the grid of fields at row row, to edit the given 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) inpt.set_hexpand(True)
self.gridfields.attach(inpt, 1, row-1, 1, 1) self.gridfields.attach(inpt, 1, row-1, 1, 1)
self.inpts.append(inpt) self.inpts.append(inpt)
MonitoredEntry(inpt, self.set_field, self.get_field, if self.cite:
read_only=self.db.readonly, MonitoredEntry(inpt, self.set_cite_field, self.get_cite_field,
parameter=srcattrtype) 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 Obtain srcattribute with type srcattrtype, where srcattrtype is an
integer key! integer key!
""" """
src = self.src
val = '' val = ''
for attr in src.attribute_list: for attr in obj.attribute_list:
if int(attr.get_type()) == srcattrtype: if int(attr.get_type()) == srcattrtype:
val = attr.get_value() val = attr.get_value()
break break
return val 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 Set attribute of source of type srcattrtype (which is integer!) to
value. If not present, create attribute. If value == '', remove value. If not present, create attribute. If value == '', remove
""" """
src = self.src
value = value.strip() value = value.strip()
foundattr = None foundattr = None
for attr in src.attribute_list: for attr in obj.attribute_list:
if int(attr.get_type()) == srcattrtype: if int(attr.get_type()) == srcattrtype:
attr.set_value(value) attr.set_value(value)
foundattr = attr foundattr = attr
break break
if foundattr and value == '': if foundattr and value == '':
src.remove_attribute(foundattr) obj.remove_attribute(foundattr)
if foundattr is None and value != '': if foundattr is None and value != '':
foundattr = SrcAttribute() foundattr = SrcAttribute()
foundattr.set_type(srcattrtype) foundattr.set_type(srcattrtype)
foundattr.set_value(value) foundattr.set_value(value)
src.add_attribute(foundattr) obj.add_attribute(foundattr)
#indicate source object changed
self.callback_src_changed()
## def setup_autocomp_combobox(self): ## def setup_autocomp_combobox(self):
## """ ## """

View File

@@ -155,6 +155,7 @@ class EditSource(EditPrimary):
self.notebook_ref = self.glade.get_object('notebook_citation') self.notebook_ref = self.glade.get_object('notebook_citation')
self.cinf = self.glade.get_object("cite_info_lbl") self.cinf = self.glade.get_object("cite_info_lbl")
self.btnclose_cite = self.glade.get_object("btnclose_cite") self.btnclose_cite = self.glade.get_object("btnclose_cite")
self.tmplfields = None
self.define_warn_box2(self.glade.get_object("warn_box2")) self.define_warn_box2(self.glade.get_object("warn_box2"))
@@ -377,10 +378,14 @@ class EditSource(EditPrimary):
#lastly update the window title #lastly update the window title
self.update_title(self.get_menu_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: if self.attr_tab:
self.attr_tab.rebuild_callback() self.attr_tab.rebuild_callback()
self.update_attr() self.update_attr()
@@ -496,6 +501,7 @@ class EditSource(EditPrimary):
self.tmplfields = TemplateFields(self.dbstate.db, self.tmplfields = TemplateFields(self.dbstate.db,
self.glade.get_object('grid_citefields'), self.glade.get_object('grid_citefields'),
self.obj, self.citation, None, self.callback_cite_changed) 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.comment_tab = NoteTab(self.dbstate, self.uistate, self.track,
self.citation.get_note_list(), self.get_menu_title(), self.citation.get_note_list(), self.get_menu_title(),
@@ -815,6 +821,8 @@ class EditSource(EditPrimary):
self._create_citation_tabbed_pages() self._create_citation_tabbed_pages()
else: else:
self.citation_changed() 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.cinf.set_visible(True)
self.btnclose_cite.set_sensitive(True) self.btnclose_cite.set_sensitive(True)
self.citation_loaded = True self.citation_loaded = True

View File

@@ -334,7 +334,10 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="margin_left">10</property> <property name="margin_left">10</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property> <property name="shadow_type">in</property>
<property name="min_content_height">40</property>
<child> <child>
<object class="GtkViewport" id="viewport1"> <object class="GtkViewport" id="viewport1">
<property name="visible">True</property> <property name="visible">True</property>
@@ -343,6 +346,29 @@
<object class="GtkGrid" id="grid_citefields"> <object class="GtkGrid" id="grid_citefields">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="margin_left">3</property>
<property name="margin_right">3</property>
<property name="margin_top">3</property>
<property name="row_spacing">2</property>
<property name="column_spacing">2</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
@@ -1008,40 +1034,54 @@
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
<property name="shadow_type">none</property> <property name="shadow_type">none</property>
<child> <child>
<object class="GtkAlignment" id="alignment1"> <object class="GtkScrolledWindow" id="scrolledwindow3">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">True</property>
<property name="left_padding">12</property> <property name="margin_left">15</property>
<property name="shadow_type">in</property>
<child> <child>
<object class="GtkGrid" id="gridfields"> <object class="GtkViewport" id="viewport2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<placeholder/> <object class="GtkGrid" id="gridfields">
</child> <property name="visible">True</property>
<child> <property name="can_focus">False</property>
<placeholder/> <property name="margin_left">3</property>
</child> <property name="margin_right">3</property>
<child> <property name="margin_top">3</property>
<placeholder/> <property name="hexpand">True</property>
</child> <property name="vexpand">True</property>
<child> <property name="row_spacing">2</property>
<placeholder/> <property name="column_spacing">2</property>
</child> <child>
<child> <placeholder/>
<placeholder/> </child>
</child> <child>
<child> <placeholder/>
<placeholder/> </child>
</child> <child>
<child> <placeholder/>
<placeholder/> </child>
</child> <child>
<child> <placeholder/>
<placeholder/> </child>
</child> <child>
<child> <placeholder/>
<placeholder/> </child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child> </child>
</object> </object>
</child> </child>