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
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

View File

@ -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(_("<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:
self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
row += 1
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:
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(_("<b>Optional Default Citation Fields:</b>"))
@ -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(_("<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:
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):
## """

View File

@ -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

View File

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