From 69cfbe7a02361c0d55a6373b686feb4db1111ca1 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 29 May 2013 17:08:51 +0000 Subject: [PATCH] automatic creation of needed fields svn: r22453 --- .../gui/editors/displaytabs/srctemplatetab.py | 50 +++++++- gramps/gui/editors/editsource.py | 11 +- gramps/gui/glade/editsource.glade | 118 ++++++++++++------ gramps/gui/widgets/srctemplatetreeview.py | 8 +- 4 files changed, 134 insertions(+), 53 deletions(-) diff --git a/gramps/gui/editors/displaytabs/srctemplatetab.py b/gramps/gui/editors/displaytabs/srctemplatetab.py index 79bf3c629..0c334539a 100644 --- a/gramps/gui/editors/displaytabs/srctemplatetab.py +++ b/gramps/gui/editors/displaytabs/srctemplatetab.py @@ -44,6 +44,7 @@ from gi.repository import Gtk from gramps.gen.lib.srcattrtype import SrcAttributeType from ...autocomp import StandardCustomSelector from ...widgets.srctemplatetreeview import SrcTemplateTreeView +from ...widgets import UndoableEntry from .grampstab import GrampsTab #------------------------------------------------------------------------- @@ -55,7 +56,7 @@ class SrcTemplateTab(GrampsTab): """ This class provides the tabpage for template generation of attributes. """ - def __init__(self, dbstate, uistate, track, src, widget, scrolled, + def __init__(self, dbstate, uistate, track, src, glade, callback_src_changed): """ @param dbstate: The database state. Contains a reference to @@ -71,19 +72,27 @@ class SrcTemplateTab(GrampsTab): @type track: list @param src: source which we manage in this tab @type src: gen.lib.Source - @param widget: widget with all the elements - @type widget: GTK dialog + @param glade: glade objects with the needed widgets """ self.src = src + self.glade = glade self.callback_src_changed = callback_src_changed self.readonly = dbstate.db.readonly + GrampsTab.__init__(self, dbstate, uistate, track, _("Source Template")) eventbox = Gtk.EventBox() + widget = self.glade.get_object('gridtemplate') eventbox.add(widget) self.pack_start(eventbox, True, True, 0) self._set_label(show_image=False) widget.connect('key_press_event', self.key_pressed) - self.setup_interface(scrolled) + + self.lbls = [] + self.inpts = [] + self.gridfields = self.glade.get_object('gridfields') + #self.vbox_fields_label = self.glade.get_object('fields_01') + #self.vbox_fields_input = self.glade.get_object('fields_02') + self.setup_interface(self.glade.get_object('scrolledtemplates')) self.show_all() def is_empty(self): @@ -112,6 +121,39 @@ class SrcTemplateTab(GrampsTab): """ self.src.set_source_template(index, key) self.callback_src_changed() + + srcattr = SrcAttributeType() + if index in srcattr.EVIDENCETEMPLATES: + #a predefined template, + self.reset_template_fields(srcattr.EVIDENCETEMPLATES[index]) + + def reset_template_fields(self, template): + # first remove old fields + for lbl in self.lbls: + self.gridfields.remove(lbl) + for inpt in self.inpts: + self.gridfields.remove(inpt) + self.lbls = [] + self.inpts = [] + row = 1 + # now add new fields + for fielddef in template['F']: + self.gridfields.insert_row(row) + row += 1 + field = fielddef[1] + srcattr = SrcAttributeType(field) + lbl = Gtk.Label(_("%s:") %str(srcattr)) + lbl.set_halign(Gtk.Align.START) + self.gridfields.attach(lbl, 0, row-1, 1, 1) + self.lbls.append(lbl) + inpt = UndoableEntry() + inpt.set_halign(Gtk.Align.FILL) + self.gridfields.attach(inpt, 1, row-1, 1, 1) + self.inpts.append(inpt) + + self.show_all() + + ## def setup_autocomp_combobox(self): ## """ diff --git a/gramps/gui/editors/editsource.py b/gramps/gui/editors/editsource.py index 3a5112a63..b94d65519 100644 --- a/gramps/gui/editors/editsource.py +++ b/gramps/gui/editors/editsource.py @@ -211,7 +211,8 @@ class EditSource(EditPrimary): """ Change in the template tab must be reflected in other places """ - self.attr_tab.rebuild_callback() + if self.attr_tab: + self.attr_tab.rebuild_callback() def _create_tabbed_pages(self): notebook = self.glade.get_object('notebook') @@ -222,13 +223,11 @@ class EditSource(EditPrimary): _('Overview'), gridsrc) self._add_tab(notebook, self.overviewtab) - gridtemp = self.glade.get_object('gridtemplate') - - #recreate start 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.track, self.obj, gridtemp, - self.glade.get_object('scrolledtemplates'), + self.track, self.obj, self.glade, self.update_template_data ) self._add_tab(notebook, self.template_tab) diff --git a/gramps/gui/glade/editsource.glade b/gramps/gui/glade/editsource.glade index 9b0d81249..538daba62 100644 --- a/gramps/gui/glade/editsource.glade +++ b/gramps/gui/glade/editsource.glade @@ -571,58 +571,96 @@ - + True False - 3 - 3 - 5 - 3 - 3 + vertical - + True False - 0 - 0 - Source Template: - - - 0 - 0 - 1 - 1 - - - - - 150 - True - True - True - in + 3 + 3 + 5 - + + True + False + 4 + 0 + 0 + Source Template: + + + False + True + 0 + + + + + 450 + 150 + True + True + start + in + + + + + + False + False + 1 + - 1 - 0 - 2 - 2 + False + True + 1 - - - - - - - - - - + + True + False + 0 + none + + + True + False + 12 + + + True + False + + + + + + + + + + + + + True + False + <b>Source Fields</b> + True + + + + + False + True + 2 + diff --git a/gramps/gui/widgets/srctemplatetreeview.py b/gramps/gui/widgets/srctemplatetreeview.py index c49f12c91..eab9e5a10 100644 --- a/gramps/gui/widgets/srctemplatetreeview.py +++ b/gramps/gui/widgets/srctemplatetreeview.py @@ -66,7 +66,7 @@ class SrcTemplateTreeView(Gtk.TreeView): self.set_model(self.model) self.goto(default_key) # set up selection and fields on click - self.connect('button-press-event', self._on_button_press) + self.connect('button-release-event', self._on_button_release) self.connect('key_press_event', self._on_key_press_event) def build_model(self): @@ -77,6 +77,7 @@ class SrcTemplateTreeView(Gtk.TreeView): self.I2Str = srcattrt.I2S_SRCTEMPLATEMAP self.I2Key = srcattrt.I2E_SRCTEMPLATEMAP self.Str2I = srcattrt.S2I_SRCTEMPLATEMAP + self.Key2I = srcattrt.E2I_SRCTEMPLATEMAP self.Key2Path = {} # store (index, key, cat, cat_type, src_type) self.model = Gtk.TreeStore(int, str, str) @@ -159,6 +160,7 @@ class SrcTemplateTreeView(Gtk.TreeView): self.selection.unselect_all() self.selection.select_path(path) self.scroll_to_cell(path, None, 1, 0.5, 0) + self.sel_callback(self.Key2I[key], key) def get_selected(self): """ @@ -169,11 +171,11 @@ class SrcTemplateTreeView(Gtk.TreeView): return (model.get_value(node, 0), model.get_value(node,1), node) return None - def _on_button_press(self, obj, event): + def _on_button_release(self, obj, event): """ Handle button press """ - if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 1: + if event.type == Gdk.EventType.BUTTON_RELEASE and event.button == 1: ref = self.get_selected() if ref and ref[0] != -10: self.sel_callback(ref[0], ref[1])