automatic creation of needed fields
svn: r22453
This commit is contained in:
@ -44,6 +44,7 @@ from gi.repository import Gtk
|
|||||||
from gramps.gen.lib.srcattrtype import SrcAttributeType
|
from gramps.gen.lib.srcattrtype import SrcAttributeType
|
||||||
from ...autocomp import StandardCustomSelector
|
from ...autocomp import StandardCustomSelector
|
||||||
from ...widgets.srctemplatetreeview import SrcTemplateTreeView
|
from ...widgets.srctemplatetreeview import SrcTemplateTreeView
|
||||||
|
from ...widgets import UndoableEntry
|
||||||
from .grampstab import GrampsTab
|
from .grampstab import GrampsTab
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -55,7 +56,7 @@ class SrcTemplateTab(GrampsTab):
|
|||||||
"""
|
"""
|
||||||
This class provides the tabpage for template generation of attributes.
|
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):
|
callback_src_changed):
|
||||||
"""
|
"""
|
||||||
@param dbstate: The database state. Contains a reference to
|
@param dbstate: The database state. Contains a reference to
|
||||||
@ -71,19 +72,27 @@ class SrcTemplateTab(GrampsTab):
|
|||||||
@type track: list
|
@type track: list
|
||||||
@param src: source which we manage in this tab
|
@param src: source which we manage in this tab
|
||||||
@type src: gen.lib.Source
|
@type src: gen.lib.Source
|
||||||
@param widget: widget with all the elements
|
@param glade: glade objects with the needed widgets
|
||||||
@type widget: GTK dialog
|
|
||||||
"""
|
"""
|
||||||
self.src = src
|
self.src = src
|
||||||
|
self.glade = glade
|
||||||
self.callback_src_changed = callback_src_changed
|
self.callback_src_changed = callback_src_changed
|
||||||
self.readonly = dbstate.db.readonly
|
self.readonly = dbstate.db.readonly
|
||||||
|
|
||||||
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')
|
||||||
eventbox.add(widget)
|
eventbox.add(widget)
|
||||||
self.pack_start(eventbox, True, True, 0)
|
self.pack_start(eventbox, True, True, 0)
|
||||||
self._set_label(show_image=False)
|
self._set_label(show_image=False)
|
||||||
widget.connect('key_press_event', self.key_pressed)
|
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()
|
self.show_all()
|
||||||
|
|
||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
@ -113,6 +122,39 @@ class SrcTemplateTab(GrampsTab):
|
|||||||
self.src.set_source_template(index, key)
|
self.src.set_source_template(index, key)
|
||||||
self.callback_src_changed()
|
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):
|
## def setup_autocomp_combobox(self):
|
||||||
## """
|
## """
|
||||||
## Experimental code to set up a combobox with all templates.
|
## Experimental code to set up a combobox with all templates.
|
||||||
|
@ -211,6 +211,7 @@ class EditSource(EditPrimary):
|
|||||||
"""
|
"""
|
||||||
Change in the template tab must be reflected in other places
|
Change in the template tab must be reflected in other places
|
||||||
"""
|
"""
|
||||||
|
if self.attr_tab:
|
||||||
self.attr_tab.rebuild_callback()
|
self.attr_tab.rebuild_callback()
|
||||||
|
|
||||||
def _create_tabbed_pages(self):
|
def _create_tabbed_pages(self):
|
||||||
@ -222,13 +223,11 @@ class EditSource(EditPrimary):
|
|||||||
_('Overview'), gridsrc)
|
_('Overview'), gridsrc)
|
||||||
self._add_tab(notebook, self.overviewtab)
|
self._add_tab(notebook, self.overviewtab)
|
||||||
|
|
||||||
gridtemp = self.glade.get_object('gridtemplate')
|
#recreate second page as GrampsTab
|
||||||
|
|
||||||
#recreate start page as GrampsTab
|
|
||||||
notebook.remove_page(0)
|
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, gridtemp,
|
self.track, self.obj, self.glade,
|
||||||
self.glade.get_object('scrolledtemplates'),
|
|
||||||
self.update_template_data
|
self.update_template_data
|
||||||
)
|
)
|
||||||
self._add_tab(notebook, self.template_tab)
|
self._add_tab(notebook, self.template_tab)
|
||||||
|
@ -571,58 +571,96 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<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="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="boxtemp">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="margin_left">3</property>
|
<property name="margin_left">3</property>
|
||||||
<property name="margin_right">3</property>
|
<property name="margin_right">3</property>
|
||||||
<property name="margin_top">5</property>
|
<property name="margin_top">5</property>
|
||||||
<property name="row_spacing">3</property>
|
|
||||||
<property name="column_spacing">3</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="label11">
|
<object class="GtkLabel" id="label11">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_right">4</property>
|
||||||
<property name="xalign">0</property>
|
<property name="xalign">0</property>
|
||||||
<property name="yalign">0</property>
|
<property name="yalign">0</property>
|
||||||
<property name="label" translatable="yes">Source Template:</property>
|
<property name="label" translatable="yes">Source Template:</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">0</property>
|
<property name="expand">False</property>
|
||||||
<property name="top_attach">0</property>
|
<property name="fill">True</property>
|
||||||
<property name="width">1</property>
|
<property name="position">0</property>
|
||||||
<property name="height">1</property>
|
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow" id="scrolledtemplates">
|
<object class="GtkScrolledWindow" id="scrolledtemplates">
|
||||||
|
<property name="width_request">450</property>
|
||||||
<property name="height_request">150</property>
|
<property name="height_request">150</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="halign">start</property>
|
||||||
<property name="shadow_type">in</property>
|
<property name="shadow_type">in</property>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">1</property>
|
<property name="expand">False</property>
|
||||||
<property name="top_attach">0</property>
|
<property name="fill">False</property>
|
||||||
<property name="width">2</property>
|
<property name="position">1</property>
|
||||||
<property name="height">2</property>
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<object class="GtkFrame" id="frame1">
|
||||||
</child>
|
<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>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
</object>
|
||||||
<placeholder/>
|
</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"><b>Source Fields</b></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>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
@ -66,7 +66,7 @@ class SrcTemplateTreeView(Gtk.TreeView):
|
|||||||
self.set_model(self.model)
|
self.set_model(self.model)
|
||||||
self.goto(default_key)
|
self.goto(default_key)
|
||||||
# set up selection and fields on click
|
# 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)
|
self.connect('key_press_event', self._on_key_press_event)
|
||||||
|
|
||||||
def build_model(self):
|
def build_model(self):
|
||||||
@ -77,6 +77,7 @@ class SrcTemplateTreeView(Gtk.TreeView):
|
|||||||
self.I2Str = srcattrt.I2S_SRCTEMPLATEMAP
|
self.I2Str = srcattrt.I2S_SRCTEMPLATEMAP
|
||||||
self.I2Key = srcattrt.I2E_SRCTEMPLATEMAP
|
self.I2Key = srcattrt.I2E_SRCTEMPLATEMAP
|
||||||
self.Str2I = srcattrt.S2I_SRCTEMPLATEMAP
|
self.Str2I = srcattrt.S2I_SRCTEMPLATEMAP
|
||||||
|
self.Key2I = srcattrt.E2I_SRCTEMPLATEMAP
|
||||||
self.Key2Path = {}
|
self.Key2Path = {}
|
||||||
# store (index, key, cat, cat_type, src_type)
|
# store (index, key, cat, cat_type, src_type)
|
||||||
self.model = Gtk.TreeStore(int, str, str)
|
self.model = Gtk.TreeStore(int, str, str)
|
||||||
@ -159,6 +160,7 @@ class SrcTemplateTreeView(Gtk.TreeView):
|
|||||||
self.selection.unselect_all()
|
self.selection.unselect_all()
|
||||||
self.selection.select_path(path)
|
self.selection.select_path(path)
|
||||||
self.scroll_to_cell(path, None, 1, 0.5, 0)
|
self.scroll_to_cell(path, None, 1, 0.5, 0)
|
||||||
|
self.sel_callback(self.Key2I[key], key)
|
||||||
|
|
||||||
def get_selected(self):
|
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 (model.get_value(node, 0), model.get_value(node,1), node)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _on_button_press(self, obj, event):
|
def _on_button_release(self, obj, event):
|
||||||
"""
|
"""
|
||||||
Handle button press
|
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()
|
ref = self.get_selected()
|
||||||
if ref and ref[0] != -10:
|
if ref and ref[0] != -10:
|
||||||
self.sel_callback(ref[0], ref[1])
|
self.sel_callback(ref[0], ref[1])
|
||||||
|
Reference in New Issue
Block a user