1. remove leftover from using nodeid as iter

2. fix error in add on placetreeview: preset values with node.name of parents


svn: r14051
This commit is contained in:
Benny Malengier 2010-01-12 21:50:37 +00:00
parent 2b40e23794
commit 61de0898af
3 changed files with 36 additions and 43 deletions

View File

@ -59,6 +59,7 @@ from gettext import gettext as _
# Constants
#
#-------------------------------------------------------------------------
COUNTRYLEVELS = {
'default': [_('<Countries>'), _('<States>'), _('<Counties>'),
_('<Places>')]

View File

@ -791,12 +791,10 @@ class TreeBaseModel(gtk.GenericTreeModel):
node = self.nodemap.node(node.children[index][1])
return node
def on_get_path(self, nodeid):
def on_get_path(self, node):
"""
Returns a path from a given node.
"""
nodeid = id(nodeid)
node = self.nodemap.node(nodeid)
pathlist = []
while node.parent is not None:
parent = self.nodemap.node(node.parent)
@ -816,24 +814,19 @@ class TreeBaseModel(gtk.GenericTreeModel):
else:
return None
def on_iter_next(self, nodeid):
def on_iter_next(self, node):
"""
Get the next node with the same parent as the given node.
"""
nodeid = id(nodeid)
node = self.nodemap.node(nodeid)
val = node.prev if self.__reverse else node.next
return self.nodemap.node(val) if val is not None else val
def on_iter_children(self, nodeid):
def on_iter_children(self, node):
"""
Get the first child of the given node.
"""
if nodeid is None:
if node is None:
node = self.tree[None]
else:
nodeid = id(nodeid)
node = self.nodemap.node(nodeid)
if node.children:
if self.__reverse:
size = len(node.children)
@ -843,37 +836,28 @@ class TreeBaseModel(gtk.GenericTreeModel):
else:
return None
def on_iter_has_child(self, nodeid):
def on_iter_has_child(self, node):
"""
Find if the given node has any children.
"""
if nodeid is None:
if node is None:
node = self.tree[None]
else:
nodeid = id(nodeid)
node = self.nodemap.node(nodeid)
return True if node.children else False
def on_iter_n_children(self, nodeid):
def on_iter_n_children(self, node):
"""
Get the number of children of the given node.
"""
if nodeid is None:
if node is None:
node = self.tree[None]
else:
nodeid = id(nodeid)
node = self.nodemap.node(nodeid)
return len(node.children)
def on_iter_nth_child(self, nodeid, index):
def on_iter_nth_child(self, node, index):
"""
Get the nth child of the given node.
"""
if nodeid is None:
if node is None:
node = self.tree[None]
else:
nodeid = id(nodeid)
node = self.nodemap.node(nodeid)
if node.children:
if len(node.children) > index:
if self.__reverse:
@ -886,11 +870,9 @@ class TreeBaseModel(gtk.GenericTreeModel):
else:
return None
def on_iter_parent(self, nodeid):
def on_iter_parent(self, node):
"""
Get the parent of the given node.
"""
nodeid = id(nodeid)
node = self.nodemap.node(nodeid)
return self.nodemap.node(node.parent) if node.parent is not None else \
None

View File

@ -30,7 +30,7 @@ Place Tree View
#-------------------------------------------------------------------------
from gui.views.listview import LISTTREE
from gui.views.placebaseview import PlaceBaseView
from gui.views.treemodels import PlaceTreeModel
from gui.views.treemodels.placetreemodel import PlaceTreeModel, COUNTRYLEVELS
import gen.lib
import Errors
from gui.editors import EditPlace
@ -149,30 +149,40 @@ class PlaceTreeView(PlaceBaseView):
place = gen.lib.Place()
model, pathlist = self.selection.get_selected_rows()
level = [u"", u"", u""]
level1 = level2 = level3 = u""
if len(pathlist) == 1:
path = pathlist[0]
node = model.on_get_iter(path)
parent = model.on_iter_parent(node)
value = model.on_get_value(node, 0)
if len(path) == 1:
level1 = value
level[0] = node.name
elif len(path) == 2:
level2 = value
level1 = parent[0]
level[1] = node.name
parent = model.on_iter_parent(node)
level[0] = parent.name
elif len(path) == 3:
level3 = value
level2 = parent[0]
level1 = parent[1]
level[2] = node.name
parent = model.on_iter_parent(node)
level[1] = parent.name
parent = model.on_iter_parent(parent)
level[0] = parent.name
else:
level3 = parent[0]
level2 = parent[1]
level1 = parent[2]
parent = model.on_iter_parent(node)
level[2] = parent.name
parent = model.on_iter_parent(parent)
level[1] = parent.name
parent = model.on_iter_parent(parent)
level[0] = parent.name
for ind in [0, 1, 2]:
if level[ind] and level[ind] == COUNTRYLEVELS['default'][ind+1]:
level[ind] = u""
place.get_main_location().set_country(level[0])
place.get_main_location().set_state(level[1])
place.get_main_location().set_county(level[2])
try:
place.get_main_location().set_country(level1)
place.get_main_location().set_state(level2)
place.get_main_location().set_county(level3)
EditPlace(self.dbstate, self.uistate, [], place)
except Errors.WindowActiveError:
pass