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:
parent
2b40e23794
commit
61de0898af
@ -59,6 +59,7 @@ from gettext import gettext as _
|
|||||||
# Constants
|
# Constants
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
COUNTRYLEVELS = {
|
COUNTRYLEVELS = {
|
||||||
'default': [_('<Countries>'), _('<States>'), _('<Counties>'),
|
'default': [_('<Countries>'), _('<States>'), _('<Counties>'),
|
||||||
_('<Places>')]
|
_('<Places>')]
|
||||||
|
@ -791,12 +791,10 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
node = self.nodemap.node(node.children[index][1])
|
node = self.nodemap.node(node.children[index][1])
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def on_get_path(self, nodeid):
|
def on_get_path(self, node):
|
||||||
"""
|
"""
|
||||||
Returns a path from a given node.
|
Returns a path from a given node.
|
||||||
"""
|
"""
|
||||||
nodeid = id(nodeid)
|
|
||||||
node = self.nodemap.node(nodeid)
|
|
||||||
pathlist = []
|
pathlist = []
|
||||||
while node.parent is not None:
|
while node.parent is not None:
|
||||||
parent = self.nodemap.node(node.parent)
|
parent = self.nodemap.node(node.parent)
|
||||||
@ -816,24 +814,19 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
else:
|
else:
|
||||||
return None
|
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.
|
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
|
val = node.prev if self.__reverse else node.next
|
||||||
return self.nodemap.node(val) if val is not None else val
|
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.
|
Get the first child of the given node.
|
||||||
"""
|
"""
|
||||||
if nodeid is None:
|
if node is None:
|
||||||
node = self.tree[None]
|
node = self.tree[None]
|
||||||
else:
|
|
||||||
nodeid = id(nodeid)
|
|
||||||
node = self.nodemap.node(nodeid)
|
|
||||||
if node.children:
|
if node.children:
|
||||||
if self.__reverse:
|
if self.__reverse:
|
||||||
size = len(node.children)
|
size = len(node.children)
|
||||||
@ -843,37 +836,28 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def on_iter_has_child(self, nodeid):
|
def on_iter_has_child(self, node):
|
||||||
"""
|
"""
|
||||||
Find if the given node has any children.
|
Find if the given node has any children.
|
||||||
"""
|
"""
|
||||||
if nodeid is None:
|
if node is None:
|
||||||
node = self.tree[None]
|
node = self.tree[None]
|
||||||
else:
|
|
||||||
nodeid = id(nodeid)
|
|
||||||
node = self.nodemap.node(nodeid)
|
|
||||||
return True if node.children else False
|
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.
|
Get the number of children of the given node.
|
||||||
"""
|
"""
|
||||||
if nodeid is None:
|
if node is None:
|
||||||
node = self.tree[None]
|
node = self.tree[None]
|
||||||
else:
|
|
||||||
nodeid = id(nodeid)
|
|
||||||
node = self.nodemap.node(nodeid)
|
|
||||||
return len(node.children)
|
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.
|
Get the nth child of the given node.
|
||||||
"""
|
"""
|
||||||
if nodeid is None:
|
if node is None:
|
||||||
node = self.tree[None]
|
node = self.tree[None]
|
||||||
else:
|
|
||||||
nodeid = id(nodeid)
|
|
||||||
node = self.nodemap.node(nodeid)
|
|
||||||
if node.children:
|
if node.children:
|
||||||
if len(node.children) > index:
|
if len(node.children) > index:
|
||||||
if self.__reverse:
|
if self.__reverse:
|
||||||
@ -886,11 +870,9 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def on_iter_parent(self, nodeid):
|
def on_iter_parent(self, node):
|
||||||
"""
|
"""
|
||||||
Get the parent of the given 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 \
|
return self.nodemap.node(node.parent) if node.parent is not None else \
|
||||||
None
|
None
|
||||||
|
@ -30,7 +30,7 @@ Place Tree View
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gui.views.listview import LISTTREE
|
from gui.views.listview import LISTTREE
|
||||||
from gui.views.placebaseview import PlaceBaseView
|
from gui.views.placebaseview import PlaceBaseView
|
||||||
from gui.views.treemodels import PlaceTreeModel
|
from gui.views.treemodels.placetreemodel import PlaceTreeModel, COUNTRYLEVELS
|
||||||
import gen.lib
|
import gen.lib
|
||||||
import Errors
|
import Errors
|
||||||
from gui.editors import EditPlace
|
from gui.editors import EditPlace
|
||||||
@ -149,30 +149,40 @@ class PlaceTreeView(PlaceBaseView):
|
|||||||
place = gen.lib.Place()
|
place = gen.lib.Place()
|
||||||
|
|
||||||
model, pathlist = self.selection.get_selected_rows()
|
model, pathlist = self.selection.get_selected_rows()
|
||||||
|
level = [u"", u"", u""]
|
||||||
level1 = level2 = level3 = u""
|
level1 = level2 = level3 = u""
|
||||||
if len(pathlist) == 1:
|
if len(pathlist) == 1:
|
||||||
path = pathlist[0]
|
path = pathlist[0]
|
||||||
node = model.on_get_iter(path)
|
node = model.on_get_iter(path)
|
||||||
parent = model.on_iter_parent(node)
|
|
||||||
value = model.on_get_value(node, 0)
|
value = model.on_get_value(node, 0)
|
||||||
|
|
||||||
if len(path) == 1:
|
if len(path) == 1:
|
||||||
level1 = value
|
level[0] = node.name
|
||||||
elif len(path) == 2:
|
elif len(path) == 2:
|
||||||
level2 = value
|
level[1] = node.name
|
||||||
level1 = parent[0]
|
parent = model.on_iter_parent(node)
|
||||||
|
level[0] = parent.name
|
||||||
elif len(path) == 3:
|
elif len(path) == 3:
|
||||||
level3 = value
|
level[2] = node.name
|
||||||
level2 = parent[0]
|
parent = model.on_iter_parent(node)
|
||||||
level1 = parent[1]
|
level[1] = parent.name
|
||||||
|
parent = model.on_iter_parent(parent)
|
||||||
|
level[0] = parent.name
|
||||||
else:
|
else:
|
||||||
level3 = parent[0]
|
parent = model.on_iter_parent(node)
|
||||||
level2 = parent[1]
|
level[2] = parent.name
|
||||||
level1 = parent[2]
|
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:
|
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)
|
EditPlace(self.dbstate, self.uistate, [], place)
|
||||||
except Errors.WindowActiveError:
|
except Errors.WindowActiveError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user