* src/DisplayModels.py: simplify internal iter handling.

Move to a single list instead of multiple dictionaries.


svn: r3439
This commit is contained in:
Don Allingham 2004-08-19 16:49:16 +00:00
parent 27eaa233ab
commit f69866a8b4
2 changed files with 18 additions and 17 deletions

View File

@ -2,6 +2,8 @@
* src/gramps_main.py (import_tool_callback): Set home person. * src/gramps_main.py (import_tool_callback): Set home person.
2004-08-19 Don Allingham <dallingham@users.sourceforge.net> 2004-08-19 Don Allingham <dallingham@users.sourceforge.net>
* src/DisplayModels.py: simplify internal iter handling.
Move to a single list instead of multiple dictionaries.
* src/ChooseParents.py: use get_family_from_handle instead * src/ChooseParents.py: use get_family_from_handle instead
of find_family_from_handle of find_family_from_handle

View File

@ -44,18 +44,12 @@ class BaseModel(gtk.GenericTreeModel):
self.connect('row-deleted',self.on_row_deleted) self.connect('row-deleted',self.on_row_deleted)
def rebuild_data(self): def rebuild_data(self):
self.iter2path = {} self.datalist = []
self.path2iter = {}
if not self.db.is_open(): if not self.db.is_open():
return return
val = 0 self.datalist = self.sort_keys()
keys = self.sort_keys()
for place_handle in keys:
self.iter2path[place_handle] = (val,)
self.path2iter[(val,)] = place_handle
val += 1
def on_row_inserted(self,obj,path,iter): def on_row_inserted(self,obj,path,iter):
self.rebuild_data() self.rebuild_data()
@ -65,7 +59,7 @@ class BaseModel(gtk.GenericTreeModel):
def on_get_flags(self): def on_get_flags(self):
'''returns the GtkTreeModelFlags for this particular type of model''' '''returns the GtkTreeModelFlags for this particular type of model'''
return gtk.TREE_MODEL_LIST_ONLY return gtk.TREE_MODEL_LIST_ONLY | gtk.TREE_MODEL_ITERS_PERSIST
def on_get_n_columns(self): def on_get_n_columns(self):
return 10 return 10
@ -73,42 +67,47 @@ class BaseModel(gtk.GenericTreeModel):
def on_get_path(self, node): def on_get_path(self, node):
'''returns the tree path (a tuple of indices at the various '''returns the tree path (a tuple of indices at the various
levels) for a particular node.''' levels) for a particular node.'''
return self.iter2path[node] return self.datalist.index(node[0])
def on_get_column_type(self,index): def on_get_column_type(self,index):
return gobject.TYPE_STRING return gobject.TYPE_STRING
def on_get_iter(self, path): def on_get_iter(self, path):
return self.path2iter.get(path) try:
return self.datalist[path[0]]
except IndexError:
return None
def on_get_value(self,iter,col): def on_get_value(self,iter,col):
return self.fmap[col](self.map[str(iter)]) return self.fmap[col](self.map[str(iter)])
def on_iter_next(self, node): def on_iter_next(self, node):
'''returns the next node at this level of the tree''' '''returns the next node at this level of the tree'''
path = self.iter2path.get(node) try:
return self.path2iter.get((path[0]+1,)) return self.datalist[self.datalist.index(node)+1]
except IndexError:
return None
def on_iter_children(self,node): def on_iter_children(self,node):
"""Return the first child of the node""" """Return the first child of the node"""
if node == None: if node == None:
return self.path2iter[(0,)] return self.datalist[0]
return None return None
def on_iter_has_child(self, node): def on_iter_has_child(self, node):
'''returns true if this node has children''' '''returns true if this node has children'''
if node == None: if node == None:
return len(self.iter2path) > 0 return len(self.datalist) > 0
return 0 return 0
def on_iter_n_children(self,node): def on_iter_n_children(self,node):
if node == None: if node == None:
return len(self.iter2path) return len(self.datalist)
return 0 return 0
def on_iter_nth_child(self,node,n): def on_iter_nth_child(self,node,n):
if node == None: if node == None:
return self.path2iter.get((n,)) return self.datalist[n]
return None return None
def on_iter_parent(self, node): def on_iter_parent(self, node):