automatic creation of needed fields

svn: r22453
This commit is contained in:
Benny Malengier 2013-05-29 17:08:51 +00:00
parent 6dce67703e
commit 69cfbe7a02
4 changed files with 134 additions and 53 deletions

View File

@ -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):
## """

View File

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

View File

@ -571,58 +571,96 @@
</packing>
</child>
<child>
<object class="GtkGrid" id="gridtemplate">
<object class="GtkBox" id="gridtemplate">
<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">5</property>
<property name="row_spacing">3</property>
<property name="column_spacing">3</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label11">
<object class="GtkBox" id="boxtemp">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">Source Template:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledtemplates">
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="shadow_type">in</property>
<property name="margin_left">3</property>
<property name="margin_right">3</property>
<property name="margin_top">5</property>
<child>
<placeholder/>
<object class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">4</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">Source Template:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledtemplates">
<property name="width_request">450</property>
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="shadow_type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">2</property>
<property name="height">2</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<child>
<object class="GtkGrid" id="gridfields">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label12">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Source Fields&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>

View File

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