GEP 18: add autotitle setting from given attributes

svn: r22483
This commit is contained in:
Benny Malengier 2013-06-05 21:47:18 +00:00
parent 1e99275b84
commit ccf1f2eac5
3 changed files with 60 additions and 6 deletions

View File

@ -43,7 +43,7 @@ from gi.repository import Gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.lib.srcattrtype import (SrcAttributeType, REF_TYPE_F, from gramps.gen.lib.srcattrtype import (SrcAttributeType, REF_TYPE_F,
REF_TYPE_S, REF_TYPE_L, EMPTY) REF_TYPE_S, REF_TYPE_L, EMPTY)
from gramps.gen.lib.srcattribute import SrcAttribute from gramps.gen.lib import SrcAttribute, SrcTemplate
from ...autocomp import StandardCustomSelector from ...autocomp import StandardCustomSelector
from ...widgets.srctemplatetreeview import SrcTemplateTreeView from ...widgets.srctemplatetreeview import SrcTemplateTreeView
from ...widgets import UndoableEntry, MonitoredEntry from ...widgets import UndoableEntry, MonitoredEntry
@ -81,6 +81,8 @@ class SrcTemplateTab(GrampsTab):
self.callback_src_changed = callback_src_changed self.callback_src_changed = callback_src_changed
self.readonly = dbstate.db.readonly self.readonly = dbstate.db.readonly
self.autoset_title = False
GrampsTab.__init__(self, dbstate, uistate, track, _("Source Template")) GrampsTab.__init__(self, dbstate, uistate, track, _("Source Template"))
eventbox = Gtk.EventBox() eventbox = Gtk.EventBox()
widget = self.glade.get_object('gridtemplate') widget = self.glade.get_object('gridtemplate')
@ -93,6 +95,7 @@ class SrcTemplateTab(GrampsTab):
self.inpts = [] self.inpts = []
self.monentry = [] self.monentry = []
self.gridfields = self.glade.get_object('gridfields') self.gridfields = self.glade.get_object('gridfields')
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')
self.setup_interface(self.glade.get_object('scrolledtemplates')) self.setup_interface(self.glade.get_object('scrolledtemplates'))
@ -118,6 +121,34 @@ class SrcTemplateTab(GrampsTab):
sel_callback=self.on_template_selected) sel_callback=self.on_template_selected)
scrolled.add(self.temp_tv) scrolled.add(self.temp_tv)
#autotitle checkbox
self.autotitle.set_active(self.autotitle_get_orig_val())
self.autotitle.set_sensitive(not self.dbstate.db.readonly)
self.autotitle.connect('toggled', self.autotitle_on_toggle)
def autotitle_get_orig_val(self):
"""
If title of the source is what we would set with autotitle, we set
the checkbox to true. Otherwise to False
"""
srctemp = SrcTemplate(self.src.get_source_template()[0])
srctemp.set_attr_list(self.src.get_attribute_list())
title = srctemp.title_gedcom()
if self.src.get_title() == title:
self.autoset_title = True
else:
self.autoset_title = False
return self.autoset_title
def autotitle_on_toggle(self, obj):
""" the autoset_title attribute will be used in editsource to
determine that title must be set
"""
self.autoset_title = obj.get_active()
#it might be that the title must be changed, so we trigger the callback
# which will update the title in the source object
self.callback_src_changed()
def on_template_selected(self, index, key): def on_template_selected(self, index, key):
""" """
Selected template changed, we save this and update interface Selected template changed, we save this and update interface

View File

@ -80,6 +80,8 @@ class EditSource(EditPrimary):
""" """
self.srctemp = None self.srctemp = None
self.citation = citation self.citation = citation
self.template_tab = None
self.attr_tab = None
if not source and not citation: if not source and not citation:
raise NotImplementedError raise NotImplementedError
elif not source: elif not source:
@ -104,13 +106,13 @@ class EditSource(EditPrimary):
def get_menu_title(self): def get_menu_title(self):
title = self.obj.get_title() title = self.obj.get_title()
if title: if self.obj.get_handle():
title = _('Source') + ": " + title title = _('Source') + ": " + title
else: else:
title = _('New Source') title = _('New Source')
if self.citation is not None: if self.citation is not None:
citeid = self.citation.get_gramps_id() citeid = self.citation.get_gramps_id()
if citeid: if self.citation.get_handle():
if self.callertitle: if self.callertitle:
title = _('Citation: %(id)s - %(context)s' % { title = _('Citation: %(id)s - %(context)s' % {
'id' : citeid, 'id' : citeid,
@ -331,6 +333,12 @@ class EditSource(EditPrimary):
self.refS.set_text(_("<no citation loaded>")) self.refS.set_text(_("<no citation loaded>"))
self.author.set_text(self.srctemp.author_gedcom()) self.author.set_text(self.srctemp.author_gedcom())
self.pubinfo.set_text(self.srctemp.pubinfo_gedcom()) self.pubinfo.set_text(self.srctemp.pubinfo_gedcom())
if self.template_tab and self.template_tab.autoset_title:
title = self.srctemp.title_gedcom()
self.obj.set_title(title)
self.title.update()
#lastly update the window title
self.update_title(self.get_menu_title())
def update_template_data(self): def update_template_data(self):
""" """
@ -358,14 +366,13 @@ class EditSource(EditPrimary):
notebook = self.glade.get_object('notebook') notebook = self.glade.get_object('notebook')
gridsrc = self.glade.get_object('gridsrc') gridsrc = self.glade.get_object('gridsrc')
#recreate start page as GrampsTab #recreate start page as GrampsTab
notebook.remove_page(1)
notebook.remove_page(0) notebook.remove_page(0)
self.overviewtab = RefTab(self.dbstate, self.uistate, self.track, self.overviewtab = RefTab(self.dbstate, self.uistate, self.track,
_('Overview'), gridsrc) _('Overview'), gridsrc)
self._add_tab(notebook, self.overviewtab) self._add_tab(notebook, self.overviewtab)
#recreate second page as GrampsTab #recreate second page as GrampsTab
notebook.remove_page(0)
self.attr_tab = None
self.template_tab = SrcTemplateTab(self.dbstate, self.uistate, self.template_tab = SrcTemplateTab(self.dbstate, self.uistate,
self.track, self.obj, self.glade, self.track, self.obj, self.glade,
self.update_template_data self.update_template_data

View File

@ -957,6 +957,22 @@
</packing> </packing>
</child> </child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="autotitle_checkbtn">
<property name="label" translatable="yes">Automatically set Source title from source fields</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="margin_left">3</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>