Add origin type selector with autocompletion to surname table
svn: r16009
This commit is contained in:
parent
ada8c30955
commit
3cfbd2482d
@ -45,11 +45,11 @@ class SurnameModel(gtk.ListStore):
|
||||
|
||||
def __init__(self, surn_list, db):
|
||||
#setup model for the treeview
|
||||
gtk.ListStore.__init__(self, str, str, str, gobject.TYPE_PYOBJECT,
|
||||
gtk.ListStore.__init__(self, str, str, str, str,
|
||||
bool, object)
|
||||
for surn in surn_list:
|
||||
# fill the liststore
|
||||
self.append(row=[surn.get_prefix(), surn.get_surname(),
|
||||
surn.get_connector(), surn.get_origintype(),
|
||||
surn.get_connector(), str(surn.get_origintype()),
|
||||
surn.get_primary(), surn])
|
||||
self.db = db
|
||||
|
@ -27,6 +27,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gen.ggettext import gettext as _
|
||||
import locale
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -34,6 +35,8 @@ from gen.ggettext import gettext as _
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
import gobject
|
||||
import pango
|
||||
_TAB = gtk.gdk.keyval_from_name("Tab")
|
||||
_ENTER = gtk.gdk.keyval_from_name("Enter")
|
||||
|
||||
@ -45,6 +48,7 @@ _ENTER = gtk.gdk.keyval_from_name("Enter")
|
||||
from surnamemodel import SurnameModel
|
||||
from embeddedlist import EmbeddedList
|
||||
from DdTargets import DdTargets
|
||||
import AutoComp
|
||||
from gen.lib import Surname, NameOriginType
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -68,10 +72,11 @@ class SurnameTab(EmbeddedList):
|
||||
#index = column in model. Value =
|
||||
# (name, sortcol in model, width, markup/text
|
||||
_column_names = [
|
||||
(_('Prefix'), 0, 150, 0, -1),
|
||||
(_('Surname'), 1, 250, 0, -1),
|
||||
(_('Connector'), 2, 100, 0, -1),
|
||||
(_('Prefix'), -1, 150, 0, -1),
|
||||
(_('Surname'), -1, 250, 0, -1),
|
||||
(_('Connector'), -1, 100, 0, -1),
|
||||
]
|
||||
_column_combo = (_('Origin'), -1, 150, 3) # name, sort, width, modelcol
|
||||
|
||||
def __init__(self, dbstate, uistate, track, name):
|
||||
self.obj = name
|
||||
@ -91,14 +96,53 @@ class SurnameTab(EmbeddedList):
|
||||
for colno in range(len(self.columns)):
|
||||
for renderer in self.columns[colno].get_cell_renderers():
|
||||
renderer.set_property('editable', not self.dbstate.db.readonly)
|
||||
renderer.connect('editing_started', self.edit_start, colno)
|
||||
renderer.connect('edited', self.edit_inline, colno)
|
||||
#no sorting
|
||||
self.columns[colno].set_sort_column_id(-1)
|
||||
renderer.connect('editing_started', self.on_edit_start, colno)
|
||||
renderer.connect('edited', self.on_edit_inline, colno)
|
||||
|
||||
# now we add the two special columns
|
||||
# combobox for type
|
||||
colno = len(self.columns)
|
||||
name = self._column_combo[0]
|
||||
renderer = gtk.CellRendererCombo()
|
||||
renderer.set_property('ellipsize', pango.ELLIPSIZE_END)
|
||||
# set up the comboentry editable
|
||||
no = NameOriginType()
|
||||
self.cmborig = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING)
|
||||
self.cmborigmap = no.get_map().copy()
|
||||
keys = sorted(self.cmborigmap, self.by_value)
|
||||
for key in keys:
|
||||
if key != no.get_custom():
|
||||
self.cmborig.append(row=[key, self.cmborigmap[key]])
|
||||
additional = self.dbstate.db.get_origin_types()
|
||||
if additional:
|
||||
for type in additional:
|
||||
if type:
|
||||
self.cmborig.append(row=[no.get_custom(), type])
|
||||
renderer.set_property("model", self.cmborig)
|
||||
renderer.set_property("text-column", 1)
|
||||
renderer.set_property('editable', not self.dbstate.db.readonly)
|
||||
|
||||
renderer.connect('editing_started', self.on_edit_start_cmb, colno)
|
||||
renderer.connect('edited', self.on_orig_edited, colno)
|
||||
# add to treeview
|
||||
column = gtk.TreeViewColumn(name, renderer, text=self._column_combo[3])
|
||||
column.set_resizable(True)
|
||||
column.set_sort_column_id(self._column_combo[1])
|
||||
column.set_min_width(self._column_combo[2])
|
||||
self.columns.append(column)
|
||||
self.tree.append_column(column)
|
||||
# toggle box for primary
|
||||
colno += 1
|
||||
# TODO
|
||||
|
||||
def by_value(self, first, second):
|
||||
"""
|
||||
Method for sorting keys based on the values.
|
||||
"""
|
||||
fvalue = self.cmborigmap[first]
|
||||
svalue = self.cmborigmap[second]
|
||||
return locale.strcoll(fvalue, svalue)
|
||||
|
||||
def get_data(self):
|
||||
return self.obj.get_surname_list()
|
||||
|
||||
@ -117,6 +161,7 @@ class SurnameTab(EmbeddedList):
|
||||
surn.set_prefix(unicode(self.model.get_value(node, 0)))
|
||||
surn.set_surname(unicode(self.model.get_value(node, 1)))
|
||||
surn.set_connector(unicode(self.model.get_value(node, 2)))
|
||||
surn.get_origintype().set(unicode(self.model.get_value(node, 3)))
|
||||
surn.set_primary(self.model.get_value(node, 4))
|
||||
new_list += [surn]
|
||||
return new_list
|
||||
@ -150,16 +195,40 @@ class SurnameTab(EmbeddedList):
|
||||
self.model.remove(node)
|
||||
self.update()
|
||||
|
||||
def edit_start(self, cellr, celle, path, colnr):
|
||||
def on_edit_start(self, cellr, celle, path, colnr):
|
||||
self.curr_col = colnr
|
||||
self.curr_cellr = cellr
|
||||
self.curr_celle = celle
|
||||
|
||||
def edit_inline(self, cell, path, new_text, colnr):
|
||||
|
||||
|
||||
def on_edit_start_cmb(self, cellr, celle, path, colnr):
|
||||
self.on_edit_start(cellr, celle, path, colnr)
|
||||
#set up autocomplete
|
||||
completion = gtk.EntryCompletion()
|
||||
completion.set_model(self.cmborig)
|
||||
completion.set_minimum_key_length(1)
|
||||
completion.set_text_column(1)
|
||||
celle.child.set_completion(completion)
|
||||
#
|
||||
celle.connect('changed', self.on_origcmb_change, path, colnr)
|
||||
|
||||
def on_edit_inline(self, cell, path, new_text, colnr):
|
||||
node = self.model.get_iter(path)
|
||||
self.model.set_value(node, colnr, new_text)
|
||||
self.update()
|
||||
|
||||
|
||||
def on_orig_edited(self, cellr, path, new_text, colnr):
|
||||
self.on_edit_inline(cellr, path, new_text, colnr)
|
||||
|
||||
def on_origcmb_change(self, cmb, path, colnr):
|
||||
act = cmb.get_active()
|
||||
if act == -1:
|
||||
return
|
||||
self.on_orig_edited(None, path,
|
||||
self.cmborig.get_value(
|
||||
self.cmborig.get_iter((act,)),1),
|
||||
colnr)
|
||||
|
||||
def edit_button_clicked(self, obj):
|
||||
(model, node) = self.selection.get_selected()
|
||||
if node:
|
||||
|
Loading…
Reference in New Issue
Block a user