GEP 18: * fixes in template handling
* add source text to overview tab of source svn: r22471
This commit is contained in:
parent
6e2272bb78
commit
9310d5c32d
@ -101,8 +101,16 @@ class SrcTemplate(object):
|
||||
self.refS = None
|
||||
# attrmap will hold mapping of field to normal value and short value
|
||||
# short value will be None if not given
|
||||
# map is field -> (normal value for ref L,
|
||||
# normal value for ref F/S, short value ref S)
|
||||
self.attrmap = {}
|
||||
|
||||
def get_template_key(self):
|
||||
"""
|
||||
Obtain the current template key used
|
||||
"""
|
||||
return self.template_key
|
||||
|
||||
def set_template_key(self, template_key):
|
||||
"""
|
||||
Change to the new template key for reference styling
|
||||
@ -123,17 +131,22 @@ class SrcTemplate(object):
|
||||
print ('SrcTemplate: Keyerror "', template_key,
|
||||
'", custom templates templates not implemented?')
|
||||
raise NotImplementedError
|
||||
self.template_key = template_key
|
||||
|
||||
def set_attr_list(self, attr_list):
|
||||
def set_attr_list(self, attr_list, attr_list_citation=None):
|
||||
"""
|
||||
Set the attribute list of this template. Setting once for difference
|
||||
references saves some time
|
||||
Set the attribute list of this template. Setting once for different
|
||||
references saves some time.
|
||||
attr_list should be the source attribute list
|
||||
If citation given, citation attributes overrule source attributes for
|
||||
the Full and Short references
|
||||
"""
|
||||
self.empty()
|
||||
self.attr_list = attr_list or []
|
||||
self.attr_list_cite = attr_list_citation or []
|
||||
# store attributes in a dict last to first. this overwrites data so first
|
||||
# attribute will be the one taken if duplicates are present
|
||||
for attr in attr_list[::-1]:
|
||||
for attr in self.attr_list[::-1]:
|
||||
lower = False
|
||||
typ = attr.get_type()
|
||||
key = int(typ)
|
||||
@ -146,15 +159,50 @@ class SrcTemplate(object):
|
||||
key = str(typ)
|
||||
if key in self.attrmap:
|
||||
if lower:
|
||||
self.attrmap[key] = (self.attrmap[key][0], attr.get_value())
|
||||
self.attrmap[key] = (self.attrmap[key][0],
|
||||
self.attrmap[key][0], attr.get_value())
|
||||
else:
|
||||
self.attrmap[key] = (attr.get_value(), self.attrmap[key][1])
|
||||
self.attrmap[key] = (attr.get_value(),
|
||||
attr.get_value(), self.attrmap[key][1])
|
||||
else:
|
||||
if lower:
|
||||
#store also in normal already value of short
|
||||
self.attrmap[key] = (attr.get_value(), attr.get_value())
|
||||
self.attrmap[key] = (attr.get_value(),
|
||||
attr.get_value(), attr.get_value())
|
||||
else:
|
||||
self.attrmap[key] = (attr.get_value(), None)
|
||||
self.attrmap[key] = (attr.get_value(),
|
||||
attr.get_value(), None)
|
||||
|
||||
for attr in self.attr_list_cite[::-1]:
|
||||
#we do same for citation information, but only update last two
|
||||
# values of the attrmap
|
||||
lower = False
|
||||
typ = attr.get_type()
|
||||
key = int(typ)
|
||||
keystr = typ.xml_str().lower()
|
||||
if keystr.lower().endswith(' (short)'):
|
||||
#a shorter version, we store with base type
|
||||
key = int(SrcAttributeType(keystr[:-8]))
|
||||
lower = True
|
||||
if key == SrcAttributeType.CUSTOM:
|
||||
key = str(typ)
|
||||
if key in self.attrmap:
|
||||
if lower:
|
||||
self.attrmap[key] = (self.attrmap[key][0],
|
||||
self.attrmap[key][2], attr.get_value())
|
||||
else:
|
||||
self.attrmap[key] = (self.attrmap[key][0],
|
||||
attr.get_value(), self.attrmap[key][3])
|
||||
else:
|
||||
#field only present in citation.
|
||||
if lower:
|
||||
#store also in normal already value of short, keep None
|
||||
#for source fields
|
||||
self.attrmap[key] = (None,
|
||||
attr.get_value(), attr.get_value())
|
||||
else:
|
||||
self.attrmap[key] = (None,
|
||||
attr.get_value(), None)
|
||||
|
||||
def reference_L(self, attr_list=None):
|
||||
"""
|
||||
@ -205,7 +253,16 @@ class SrcTemplate(object):
|
||||
# ('', DATE, ' -', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ('', PAGE6S9, '.', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ]
|
||||
|
||||
#set col of attrmap to use:
|
||||
if reftype == REF_TYPE_L:
|
||||
COL_NORMAL = 0
|
||||
COL_SHORT = 2
|
||||
else:
|
||||
COL_NORMAL = 1
|
||||
COL_SHORT = 2
|
||||
ref = ['']
|
||||
fieldadded = [False]
|
||||
for (ldel, field, rdel, style, priv, opt, short, gedcom) in reflist:
|
||||
if not gedcomfield is None and gedcom != gedcomfield:
|
||||
continue
|
||||
@ -213,6 +270,7 @@ class SrcTemplate(object):
|
||||
#left delimiter
|
||||
if ldel in ['(', '[', '{']:
|
||||
ref += ['']
|
||||
fieldadded += [False]
|
||||
ref[-1] += ldel
|
||||
ldeltodo = ''
|
||||
else:
|
||||
@ -221,42 +279,67 @@ class SrcTemplate(object):
|
||||
#field
|
||||
field = ''
|
||||
if val is not None:
|
||||
if reftype == REF_TYPE_S and val[1] is not None:
|
||||
if reftype == REF_TYPE_S and val[COL_SHORT] is not None:
|
||||
customshort = True
|
||||
field = val[1]
|
||||
field = val[COL_SHORT]
|
||||
else:
|
||||
field = val[0]
|
||||
field = val[COL_NORMAL]
|
||||
if short and not customshort:
|
||||
#we apply the shortening algorithm
|
||||
## TODO: not implemented yet
|
||||
pass
|
||||
if field:
|
||||
ref[-1] += ldeltodo + field
|
||||
if field.strip():
|
||||
fieldadded[-1] = True
|
||||
ref[-1] += ldeltodo
|
||||
if len(ref[-1]) and ref[-1][-1] == '.':
|
||||
ref[-1] += ' ' + field.capitalize()
|
||||
elif len(ref[-1]) and ref[-1][-1] in [',', ':', '-']:
|
||||
ref[-1] += ' ' + field
|
||||
else:
|
||||
ref[-1] += field
|
||||
#right delimiter
|
||||
if ')' in rdel:
|
||||
if len(ref[-1] [ref[-1].find('('):]) > 0 :
|
||||
newval = ref[-1] + rdel
|
||||
ref = ref[:-1]
|
||||
fieldadded = fieldadded[:-1]
|
||||
fieldadded[-1] = True
|
||||
ref[-1] += newval
|
||||
else:
|
||||
#no data inside of delimiter, we remove it entirely
|
||||
ref = ref[:-1]
|
||||
fieldadded = fieldadded[:-1]
|
||||
#if . at end of rdel, add it
|
||||
if rdel[-1] == '.':
|
||||
ref[-1] = ref[-1] + '.'
|
||||
elif ']' in rdel:
|
||||
if len(ref[-1] [ref[-1].find(']'):]) > 0 :
|
||||
if len(ref[-1] [ref[-1].find('['):]) > 0 :
|
||||
newval = ref[-1] + rdel
|
||||
ref = ref[:-1]
|
||||
fieldadded = fieldadded[:-1]
|
||||
fieldadded[-1] = True
|
||||
ref[-1] += newval
|
||||
else:
|
||||
#no data inside of delimiter, we remove it entirely
|
||||
ref = ref[:-1]
|
||||
fieldadded = fieldadded[:-1]
|
||||
#if . at end of rdel, add it
|
||||
if rdel[-1] == '.':
|
||||
ref[-1] = ref[-1] + '.'
|
||||
elif '}' in rdel:
|
||||
if len(ref[-1] [ref[-1].find('}'):]) > 0 :
|
||||
if len(ref[-1] [ref[-1].find('{'):]) > 0 :
|
||||
newval = ref[-1] + rdel
|
||||
ref = ref[:-1]
|
||||
fieldadded = fieldadded[:-1]
|
||||
fieldadded[-1] = True
|
||||
ref[-1] += newval
|
||||
else:
|
||||
#no data inside of delimiter, we remove it entirely
|
||||
ref = ref[:-1]
|
||||
fieldadded = fieldadded[:-1]
|
||||
#if . at end of rdel, add it
|
||||
if rdel[-1] == '.':
|
||||
ref[-1] = ref[-1] + '.'
|
||||
else:
|
||||
# we add rdel
|
||||
if not ref[-1]:
|
||||
@ -270,19 +353,26 @@ class SrcTemplate(object):
|
||||
ref[-1] = ref[-1][:-1] + rdel
|
||||
else:
|
||||
ref[-1] = ref[-1] + rdel
|
||||
#we only add delimiters after this if new fields are added
|
||||
fieldadded[-1] = False
|
||||
elif len(rdel) and rdel[0] == ',':
|
||||
curval = ref[-1]
|
||||
if len(curval) and curval[-1] == '.':
|
||||
pass
|
||||
elif len(curval) and curval[-1] == ',':
|
||||
pass
|
||||
else:
|
||||
elif fieldadded[-1]:
|
||||
ref[-1] = ref[-1] + rdel
|
||||
#we only add delimiters after this if new fields are added
|
||||
fieldadded[-1] = False
|
||||
else:
|
||||
ref[-1] = ref[-1] + rdel
|
||||
if fieldadded[-1]:
|
||||
ref[-1] = ref[-1] + rdel
|
||||
#we only add delimiters after this if new fields are added
|
||||
fieldadded[-1] = False
|
||||
|
||||
ref = ''.join(ref)
|
||||
return ref
|
||||
return ref.capitalize()
|
||||
|
||||
def author_gedcom(self, attr_list=None):
|
||||
if attr_list:
|
||||
|
@ -81,10 +81,11 @@ class NoteTab(EmbeddedList, DbGUIElement):
|
||||
]
|
||||
|
||||
def __init__(self, dbstate, uistate, track, data, callertitle=None,
|
||||
notetype=None):
|
||||
notetype=None, callback_notebase_changed=None):
|
||||
self.data = data
|
||||
self.callertitle = callertitle
|
||||
self.notetype = notetype
|
||||
self.callback_notebase_changed = callback_notebase_changed
|
||||
EmbeddedList.__init__(self, dbstate, uistate, track,
|
||||
_("_Notes"), NoteModel, share_button=True,
|
||||
move_buttons=True)
|
||||
@ -150,6 +151,8 @@ class NoteTab(EmbeddedList, DbGUIElement):
|
||||
self.changed = True
|
||||
self.rebuild()
|
||||
GObject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
|
||||
if self.callback_notebase_changed:
|
||||
self.callback_notebase_changed()
|
||||
|
||||
def edit_button_clicked(self, obj):
|
||||
"""
|
||||
|
@ -70,7 +70,8 @@ from ..glade import Glade
|
||||
class EditSource(EditPrimary):
|
||||
|
||||
def __init__(self, dbstate, uistate, track, source):
|
||||
|
||||
self.srctemp = None
|
||||
self.citation = None
|
||||
EditPrimary.__init__(self, dbstate, uistate, track, source,
|
||||
dbstate.db.get_source_from_handle,
|
||||
dbstate.db.get_source_from_gramps_id)
|
||||
@ -162,6 +163,10 @@ class EditSource(EditPrimary):
|
||||
"""
|
||||
self._add_db_signal('source-rebuild', self._do_close)
|
||||
self._add_db_signal('source-delete', self.check_for_close)
|
||||
self._add_db_signal('note-delete', self.update_notes)
|
||||
self._add_db_signal('note-update', self.update_notes)
|
||||
self._add_db_signal('note-add', self.update_notes)
|
||||
self._add_db_signal('note-rebuild', self.update_notes)
|
||||
|
||||
def _setup_fields(self):
|
||||
## self.author = MonitoredEntry(self.glade.get_object("author"),
|
||||
@ -172,8 +177,13 @@ class EditSource(EditPrimary):
|
||||
## self.obj.set_publication_info,
|
||||
## self.obj.get_publication_info,
|
||||
## self.db.readonly)
|
||||
#reference info fields
|
||||
self.refL = self.glade.get_object("refL")
|
||||
self.refF = self.glade.get_object("refF")
|
||||
self.refS = self.glade.get_object("refS")
|
||||
self.author = self.glade.get_object("author")
|
||||
self.pubinfo = self.glade.get_object("pubinfo")
|
||||
self.source_text = self.glade.get_object("source_text")
|
||||
|
||||
self.gid = MonitoredEntry(self.glade.get_object("gid"),
|
||||
self.obj.set_gramps_id,
|
||||
@ -200,13 +210,31 @@ class EditSource(EditPrimary):
|
||||
self.db.readonly)
|
||||
|
||||
self.update_attr()
|
||||
self.update_notes()
|
||||
|
||||
def update_attr(self):
|
||||
"""
|
||||
Reaction to update on attributes
|
||||
"""
|
||||
self.author.set_text(self.obj.get_author())
|
||||
self.pubinfo.set_text(self.obj.get_publication_info())
|
||||
#we only construct once the template to use to format information
|
||||
if self.srctemp is None:
|
||||
self.srctemp = SrcTemplate(self.obj.get_source_template()[0])
|
||||
#if source template changed, reinit template
|
||||
if self.obj.get_source_template()[0] != self.srctemp.get_template_key():
|
||||
self.srctemp.set_template_key(self.obj.get_source_template()[0])
|
||||
#set new attrlist in template
|
||||
self.srctemp.set_attr_list(self.obj.get_attribute_list())
|
||||
|
||||
#set fields with the template
|
||||
self.refL.set_text(self.srctemp.reference_L())
|
||||
if self.citation:
|
||||
self.refF.set_text(self.srctemp.reference_F())
|
||||
self.refS.set_text(self.srctemp.reference_S())
|
||||
else:
|
||||
self.refF.set_text(_("<no citation loaded>"))
|
||||
self.refS.set_text(_("<no citation loaded>"))
|
||||
self.author.set_text(self.srctemp.author_gedcom())
|
||||
self.pubinfo.set_text(self.srctemp.pubinfo_gedcom())
|
||||
|
||||
def update_template_data(self):
|
||||
"""
|
||||
@ -216,6 +244,20 @@ class EditSource(EditPrimary):
|
||||
self.attr_tab.rebuild_callback()
|
||||
self.update_attr()
|
||||
|
||||
def update_notes(self, *par):
|
||||
"""
|
||||
Change the source text on the overview page when notebase of the source
|
||||
changed
|
||||
"""
|
||||
note_list = [ self.db.get_note_from_handle(h)
|
||||
for h in self.obj.get_note_list() ]
|
||||
note_list = [ n for n in note_list
|
||||
if n.get_type() == NoteType.SOURCE_TEXT]
|
||||
ref_text = ""
|
||||
for note in note_list:
|
||||
ref_text += note_list[0].get() + "\n"
|
||||
self.source_text.get_buffer().set_text(ref_text)
|
||||
|
||||
def _create_tabbed_pages(self):
|
||||
notebook = self.glade.get_object('notebook')
|
||||
gridsrc = self.glade.get_object('gridsrc')
|
||||
@ -240,7 +282,8 @@ class EditSource(EditPrimary):
|
||||
self.track,
|
||||
self.obj.get_note_list(),
|
||||
self.get_menu_title(),
|
||||
NoteType.SOURCE)
|
||||
NoteType.SOURCE,
|
||||
callback_notebase_changed=self.update_notes)
|
||||
self._add_tab(notebook, self.note_tab)
|
||||
self.track_ref_for_deletion("note_tab")
|
||||
|
||||
|
@ -308,7 +308,7 @@
|
||||
<property name="valign">start</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0</property>
|
||||
<property name="label" translatable="yes">In List:</property>
|
||||
<property name="label" translatable="yes">Listing:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
@ -352,7 +352,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="RefF">
|
||||
<object class="GtkLabel" id="refF">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">start</property>
|
||||
@ -369,7 +369,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="RefS">
|
||||
<object class="GtkLabel" id="refS">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">start</property>
|
||||
@ -543,6 +543,43 @@
|
||||
<property name="height">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkExpander" id="expander3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="expanded">True</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTextView" id="source_text">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">False</property>
|
||||
<property name="wrap_mode">word</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="label">
|
||||
<object class="GtkLabel" id="label13">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes"><b>Source Text</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="width">4</property>
|
||||
<property name="height">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
|
@ -96,9 +96,6 @@ class SrcTemplateTreeView(Gtk.TreeView):
|
||||
lastval = vals[-2]
|
||||
if not lastval:
|
||||
lastval = vals[-3]
|
||||
if vals[0] == 'All':
|
||||
print lastval
|
||||
print vals
|
||||
truevals = ['','','']
|
||||
if len(vals) < 3 :
|
||||
truevals[:len(vals)] = vals[:]
|
||||
@ -128,7 +125,6 @@ class SrcTemplateTreeView(Gtk.TreeView):
|
||||
#only new sublevel1 needed
|
||||
parentiterlev1 = self.model.append(None, [-10, '', vals[0]])
|
||||
parentiter = parentiterlev1
|
||||
print 'here', row, alltext
|
||||
iter = self.model.append(parentiter, row)
|
||||
else:
|
||||
#only a top level
|
||||
|
Loading…
Reference in New Issue
Block a user