Improve name grouping, consistent naming
svn: r12808
This commit is contained in:
parent
31f923bab6
commit
7f0669fac8
@ -387,7 +387,7 @@ class EmbeddedList(ButtonTab):
|
||||
|
||||
This should be overridden in the derrived classes.
|
||||
"""
|
||||
return []
|
||||
raise NotImplementedError
|
||||
|
||||
def column_order(self):
|
||||
"""
|
||||
@ -398,7 +398,7 @@ class EmbeddedList(ButtonTab):
|
||||
|
||||
This should be overridden in the derrived classes.
|
||||
"""
|
||||
return []
|
||||
raise NotImplementedError
|
||||
|
||||
def build_columns(self):
|
||||
"""
|
||||
@ -446,6 +446,12 @@ class EmbeddedList(ButtonTab):
|
||||
self.tree.append_column(column)
|
||||
self.track_ref_for_deletion("columns")
|
||||
|
||||
def construct_model(self):
|
||||
"""
|
||||
Method that creates the model using the passed build_model parameter
|
||||
"""
|
||||
return self.build_model(self.get_data(), self.dbstate.db)
|
||||
|
||||
def rebuild(self):
|
||||
"""
|
||||
Rebuilds the data in the database by creating a new model,
|
||||
@ -454,7 +460,7 @@ class EmbeddedList(ButtonTab):
|
||||
#during rebuild, don't do _selection_changed
|
||||
self.dirty_selection = True
|
||||
try:
|
||||
self.model = self.build_model(self.get_data(), self.dbstate.db)
|
||||
self.model = self.construct_model()
|
||||
except AttributeError, msg:
|
||||
from QuestionDialog import RunDatabaseRepair
|
||||
import traceback
|
||||
|
@ -57,7 +57,6 @@ class GroupEmbeddedList(EmbeddedList):
|
||||
It maintains a gtk.TreeView, including the selection and button sensitivity.
|
||||
"""
|
||||
|
||||
_CANDRAGGROUP = []
|
||||
_WORKGROUP = 0
|
||||
|
||||
def __init__(self, dbstate, uistate, track, name, build_model,
|
||||
@ -72,6 +71,21 @@ class GroupEmbeddedList(EmbeddedList):
|
||||
for col in self.columns[1:]:
|
||||
col.connect('clicked', self.col_click)
|
||||
self.dbsort = True
|
||||
|
||||
def construct_model(self):
|
||||
"""
|
||||
Method that creates the model using the passed build_model parameter
|
||||
Overwrites the EmbeddedList calling sequence by adding the different
|
||||
groups
|
||||
"""
|
||||
return self.build_model(self.get_data(), self.dbstate.db,
|
||||
self.groups())
|
||||
|
||||
def groups(self):
|
||||
"""
|
||||
Return the (group key, group name)s in the order as given by get_data()
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def groupcol_click(self, obj):
|
||||
"""
|
||||
@ -125,8 +139,6 @@ class GroupEmbeddedList(EmbeddedList):
|
||||
if not obj or obj[1] is None:
|
||||
#nothing selected or a grouping selected
|
||||
return
|
||||
if not obj[0] in self._CANDRAGGROUP:
|
||||
return
|
||||
|
||||
# pickle the data, and build the tuple to be passed
|
||||
value = (self._DND_TYPE.drag_type, id(self), obj[1],
|
||||
@ -280,6 +292,12 @@ class GroupEmbeddedList(EmbeddedList):
|
||||
move up outside of workgroup
|
||||
"""
|
||||
pass
|
||||
|
||||
def _move_up_group(self, groupindex):
|
||||
"""
|
||||
move up pressed on the group
|
||||
"""
|
||||
pass
|
||||
|
||||
def _move_down(self, row_from, obj, selmethod=None):
|
||||
"""
|
||||
@ -307,6 +325,12 @@ class GroupEmbeddedList(EmbeddedList):
|
||||
"""
|
||||
pass
|
||||
|
||||
def _move_down_group(self, groupindex):
|
||||
"""
|
||||
move down pressed on the group
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_icon_name(self):
|
||||
"""
|
||||
Specifies the basic icon used for a generic list. Typically,
|
||||
@ -339,6 +363,8 @@ class GroupEmbeddedList(EmbeddedList):
|
||||
pos = self.find_index(ref)
|
||||
if pos[1] > 0 :
|
||||
self._move_up(pos, ref[1])
|
||||
elif ref and ref[1] is None:
|
||||
self._move_up_group(ref[0])
|
||||
|
||||
def down_button_clicked(self, obj):
|
||||
ref = self.get_selected()
|
||||
@ -346,3 +372,5 @@ class GroupEmbeddedList(EmbeddedList):
|
||||
pos = self.find_index(ref)
|
||||
if pos[1] >=0 and pos[1] < len(self.get_data()[pos[0]])-1:
|
||||
self._move_down(pos, ref[1])
|
||||
elif ref and ref[1] is None:
|
||||
self._move_down_group(ref[0])
|
||||
|
@ -55,8 +55,7 @@ class NameEmbedList(GroupEmbeddedList):
|
||||
|
||||
_HANDLE_COL = 2
|
||||
_DND_TYPE = DdTargets.NAME
|
||||
_CANDRAGGROUP = [NameModel._DEFINDEX, NameModel._ALTINDEX]
|
||||
_WORKGROUP = NameModel._ALTINDEX
|
||||
_WORKGROUP = NameModel.ALTINDEX
|
||||
|
||||
_MSG = {
|
||||
'add' : _('Create and add a new name'),
|
||||
@ -91,6 +90,12 @@ class NameEmbedList(GroupEmbeddedList):
|
||||
return ([self.person.get_primary_name()],
|
||||
self.data)
|
||||
|
||||
def groups(self):
|
||||
"""
|
||||
Return the (group key, group name)s in the order as given by get_data()
|
||||
"""
|
||||
return ((None, NameModel.DEFNAME), (None, NameModel.ALTNAME))
|
||||
|
||||
def column_order(self):
|
||||
"""
|
||||
The columns to show as a tuple of tuples containing
|
||||
@ -158,10 +163,10 @@ class NameEmbedList(GroupEmbeddedList):
|
||||
if name and name[1] is not None:
|
||||
try:
|
||||
from Editors import EditName
|
||||
if name[0] == NameModel._ALTINDEX:
|
||||
if name[0] == NameModel.ALTINDEX:
|
||||
EditName(self.dbstate, self.uistate, self.track,
|
||||
name[1], self.edit_callback)
|
||||
elif name[0] == NameModel._DEFINDEX:
|
||||
elif name[0] == NameModel.DEFINDEX:
|
||||
EditName(self.dbstate, self.uistate, self.track,
|
||||
name[1], self.editdef_callback)
|
||||
except Errors.WindowActiveError:
|
||||
@ -181,7 +186,7 @@ class NameEmbedList(GroupEmbeddedList):
|
||||
"""
|
||||
Drop of obj on row that is not WORKGROUP
|
||||
"""
|
||||
if row[0] == NameModel._DEFINDEX:
|
||||
if row[0] == NameModel.DEFINDEX:
|
||||
#drop on default name
|
||||
self.set_default_name(obj)
|
||||
|
||||
@ -190,7 +195,7 @@ class NameEmbedList(GroupEmbeddedList):
|
||||
move from the workgroup to a not workgroup
|
||||
we allow to change the default name like this
|
||||
"""
|
||||
if row_from[0] == self._WORKGROUP and row_to[0] == NameModel._DEFINDEX:
|
||||
if row_from[0] == self._WORKGROUP and row_to[0] == NameModel.DEFINDEX:
|
||||
self.set_default_name(obj)
|
||||
|
||||
def post_rebuild(self):
|
||||
|
@ -54,10 +54,10 @@ NO = _('No')
|
||||
|
||||
class NameModel(gtk.TreeStore):
|
||||
#tree groups defined
|
||||
_DEFINDEX = 0
|
||||
_DEFNAME = _('Default Name')
|
||||
_ALTINDEX = 1
|
||||
_ALTNAME = _('Alternative Names')
|
||||
DEFINDEX = 0
|
||||
DEFNAME = _('Preferred name')
|
||||
ALTINDEX = 1
|
||||
ALTNAME = _('Alternative names')
|
||||
|
||||
_GROUPSTRING = _('%(groupname)s - %(groupnumber)d')
|
||||
|
||||
@ -72,12 +72,20 @@ class NameModel(gtk.TreeStore):
|
||||
COLS = (COL_NAME, COL_TYPE, COL_DATA, COL_FONTWEIGHT, COL_GROUPAS,
|
||||
COL_HASSOURCE, COL_NOTEPREVIEW)
|
||||
|
||||
def __init__(self, obj_list, db):
|
||||
def __init__(self, obj_list, db, groups):
|
||||
"""
|
||||
@param obj_list: A list of lists, every entry is a group, the entries
|
||||
in a group are the data that needs to be shown subordinate to the
|
||||
group
|
||||
@param db: a database objects that can be used to obtain info
|
||||
@param groups: a list of (key, name) tuples. key is a key for the group
|
||||
that might be used. name is the name for the group.
|
||||
"""
|
||||
typeobjs = (x[1] for x in self.COLS)
|
||||
gtk.TreeStore.__init__(self, *typeobjs)
|
||||
self.db = db
|
||||
self.groups = groups
|
||||
for index, group in enumerate(obj_list):
|
||||
|
||||
parentiter = self.append(None, row=self.row_group(index, group))
|
||||
for obj in group:
|
||||
self.append(parentiter, row = self.row(index, obj))
|
||||
@ -100,15 +108,15 @@ class NameModel(gtk.TreeStore):
|
||||
self.notepreview(name)
|
||||
]
|
||||
def colweight(self, index):
|
||||
if index == self._DEFINDEX:
|
||||
if index == self.DEFINDEX:
|
||||
return WEIGHT_BOLD
|
||||
else:
|
||||
return WEIGHT_NORMAL
|
||||
|
||||
def namegroup(self, groupindex, length):
|
||||
if groupindex == self._DEFINDEX:
|
||||
return self._DEFNAME
|
||||
return self._GROUPSTRING % {'groupname': self._ALTNAME,
|
||||
if groupindex == self.DEFINDEX:
|
||||
return self.DEFNAME
|
||||
return self._GROUPSTRING % {'groupname': self.ALTNAME,
|
||||
'groupnumber': length}
|
||||
|
||||
def update_defname(self, defname):
|
||||
@ -116,9 +124,9 @@ class NameModel(gtk.TreeStore):
|
||||
callback if change to the preferred name happens
|
||||
"""
|
||||
#default name is path (0,0)
|
||||
self.remove(self.get_iter((self._DEFINDEX, 0)))
|
||||
self.insert(self.get_iter(self._DEFINDEX), 0,
|
||||
row=self.row(self._DEFINDEX, defname))
|
||||
self.remove(self.get_iter((self.DEFINDEX, 0)))
|
||||
self.insert(self.get_iter(self.DEFINDEX), 0,
|
||||
row=self.row(self.DEFINDEX, defname))
|
||||
|
||||
def hassource(self, name):
|
||||
if len(name.get_source_references()):
|
||||
|
Loading…
Reference in New Issue
Block a user