GEP 18: automatic setting of fields, and updating attribute list
svn: r22454
This commit is contained in:
parent
69cfbe7a02
commit
a091d97677
@ -42,9 +42,10 @@ from gi.repository import Gtk
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gen.lib.srcattrtype import SrcAttributeType
|
from gramps.gen.lib.srcattrtype import SrcAttributeType
|
||||||
|
from gramps.gen.lib.srcattribute import SrcAttribute
|
||||||
from ...autocomp import StandardCustomSelector
|
from ...autocomp import StandardCustomSelector
|
||||||
from ...widgets.srctemplatetreeview import SrcTemplateTreeView
|
from ...widgets.srctemplatetreeview import SrcTemplateTreeView
|
||||||
from ...widgets import UndoableEntry
|
from ...widgets import UndoableEntry, MonitoredEntry
|
||||||
from .grampstab import GrampsTab
|
from .grampstab import GrampsTab
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -141,18 +142,61 @@ class SrcTemplateTab(GrampsTab):
|
|||||||
self.gridfields.insert_row(row)
|
self.gridfields.insert_row(row)
|
||||||
row += 1
|
row += 1
|
||||||
field = fielddef[1]
|
field = fielddef[1]
|
||||||
|
#setup label
|
||||||
srcattr = SrcAttributeType(field)
|
srcattr = SrcAttributeType(field)
|
||||||
lbl = Gtk.Label(_("%s:") %str(srcattr))
|
lbl = Gtk.Label(_("%s:") %str(srcattr))
|
||||||
lbl.set_halign(Gtk.Align.START)
|
lbl.set_halign(Gtk.Align.START)
|
||||||
self.gridfields.attach(lbl, 0, row-1, 1, 1)
|
self.gridfields.attach(lbl, 0, row-1, 1, 1)
|
||||||
self.lbls.append(lbl)
|
self.lbls.append(lbl)
|
||||||
|
#setup entry
|
||||||
inpt = UndoableEntry()
|
inpt = UndoableEntry()
|
||||||
inpt.set_halign(Gtk.Align.FILL)
|
inpt.set_halign(Gtk.Align.FILL)
|
||||||
|
inpt.set_hexpand(True)
|
||||||
self.gridfields.attach(inpt, 1, row-1, 1, 1)
|
self.gridfields.attach(inpt, 1, row-1, 1, 1)
|
||||||
self.inpts.append(inpt)
|
self.inpts.append(inpt)
|
||||||
|
MonitoredEntry(inpt, self.set_field, self.get_field,
|
||||||
|
read_only=self.dbstate.db.readonly,
|
||||||
|
parameter=field)
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
def get_field(self, srcattrtype):
|
||||||
|
"""
|
||||||
|
Obtain srcattribute with type srcattrtype, where srcattrtype is an
|
||||||
|
integer key!
|
||||||
|
"""
|
||||||
|
print 'get field called'
|
||||||
|
src = self.src
|
||||||
|
val = ''
|
||||||
|
for attr in src.attribute_list:
|
||||||
|
if int(attr.get_type()) == srcattrtype:
|
||||||
|
val = attr.get_value()
|
||||||
|
break
|
||||||
|
return val
|
||||||
|
|
||||||
|
def set_field(self, value, srcattrtype):
|
||||||
|
"""
|
||||||
|
Set attribute of source of type srcattrtype (which is integer!) to
|
||||||
|
value. If not present, create attribute. If value == '', remove
|
||||||
|
"""
|
||||||
|
print 'set field called', value, srcattrtype
|
||||||
|
src = self.src
|
||||||
|
value = value.strip()
|
||||||
|
foundattr = None
|
||||||
|
for attr in src.attribute_list:
|
||||||
|
if int(attr.get_type()) == srcattrtype:
|
||||||
|
attr.set_value(value)
|
||||||
|
foundattr = attr
|
||||||
|
break
|
||||||
|
if foundattr and value == '':
|
||||||
|
src.remove_attribute(foundattr)
|
||||||
|
if foundattr is None and value != '':
|
||||||
|
foundattr = SrcAttribute()
|
||||||
|
foundattr.set_type(srcattrtype)
|
||||||
|
foundattr.set_value(value)
|
||||||
|
src.add_attribute(foundattr)
|
||||||
|
#indicate source object changed
|
||||||
|
self.callback_src_changed()
|
||||||
|
|
||||||
|
|
||||||
## def setup_autocomp_combobox(self):
|
## def setup_autocomp_combobox(self):
|
||||||
|
@ -107,20 +107,35 @@ class MonitoredCheckbox(object):
|
|||||||
class MonitoredEntry(object):
|
class MonitoredEntry(object):
|
||||||
|
|
||||||
def __init__(self, obj, set_val, get_val, read_only=False,
|
def __init__(self, obj, set_val, get_val, read_only=False,
|
||||||
autolist=None, changed=None):
|
autolist=None, changed=None, parameter=None):
|
||||||
|
"""
|
||||||
|
A monitored entry field. On changes, set_val will be called. get_val is
|
||||||
|
used to obtain the data. set and get_val are passed parameter if it is
|
||||||
|
not None.
|
||||||
|
Use autolist to use autocompletion.
|
||||||
|
"""
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.set_val = set_val
|
self.__set_func(set_val, get_val, parameter)
|
||||||
self.get_val = get_val
|
|
||||||
self.changed = changed
|
self.changed = changed
|
||||||
|
|
||||||
if get_val():
|
gval = self.get_val(self.parameter)
|
||||||
self.obj.set_text(get_val())
|
if gval:
|
||||||
|
self.obj.set_text(gval)
|
||||||
self.obj.connect('changed', self._on_change)
|
self.obj.connect('changed', self._on_change)
|
||||||
self.obj.set_editable(not read_only)
|
self.obj.set_editable(not read_only)
|
||||||
|
|
||||||
if autolist:
|
if autolist:
|
||||||
fill_entry(obj, autolist)
|
fill_entry(obj, autolist)
|
||||||
|
|
||||||
|
def __set_func(self, set_val, get_val, parameter):
|
||||||
|
if parameter is not None:
|
||||||
|
self.set_val = lambda x: set_val(x, parameter)
|
||||||
|
self.get_val = lambda x: get_val(parameter)
|
||||||
|
else:
|
||||||
|
self.set_val = set_val
|
||||||
|
self.get_val = lambda x: get_val()
|
||||||
|
self.parameter = parameter
|
||||||
|
|
||||||
## def destroy(self):
|
## def destroy(self):
|
||||||
## """
|
## """
|
||||||
## Unset all elements that can prevent garbage collection
|
## Unset all elements that can prevent garbage collection
|
||||||
@ -129,9 +144,8 @@ class MonitoredEntry(object):
|
|||||||
## self.get_val = None
|
## self.get_val = None
|
||||||
## self.obj = None
|
## self.obj = None
|
||||||
|
|
||||||
def reinit(self, set_val, get_val):
|
def reinit(self, set_val, get_val, parameter=None):
|
||||||
self.set_val = set_val
|
self.__set_func(set_val, get_val, parameter)
|
||||||
self.get_val = get_val
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
@ -163,8 +177,8 @@ class MonitoredEntry(object):
|
|||||||
self.obj.grab_focus()
|
self.obj.grab_focus()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.get_val() is not None:
|
if self.get_val(None) is not None:
|
||||||
self.obj.set_text(self.get_val())
|
self.obj.set_text(self.get_val(None))
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -180,7 +194,7 @@ class MonitoredEntryIndicator(MonitoredEntry):
|
|||||||
autolist=None, changed=None):
|
autolist=None, changed=None):
|
||||||
MonitoredEntry.__init__(self, obj, set_val, get_val, read_only,
|
MonitoredEntry.__init__(self, obj, set_val, get_val, read_only,
|
||||||
autolist, changed)
|
autolist, changed)
|
||||||
if get_val():
|
if get_val(None):
|
||||||
self.indicatorshown = False
|
self.indicatorshown = False
|
||||||
else:
|
else:
|
||||||
self.indicatorshown = True
|
self.indicatorshown = True
|
||||||
|
Loading…
Reference in New Issue
Block a user