When searching for an entry, the data view ctrl is selecting the wrong item if it’s currently nested.
Here’s an example showing either the bug or hopefully what I’m doing wrong.
dvSample.py (7.61 KB)
When searching for an entry, the data view ctrl is selecting the wrong item if it’s currently nested.
Here’s an example showing either the bug or hopefully what I’m doing wrong.
dvSample.py (7.61 KB)
When searching for an entry, the data view ctrl is selecting the wrong
item if it's currently nested.Here's an example showing either the bug or hopefully what I'm doing wrong.
def onEnter(self, event):
searchFor = self.searchBox.GetValue()
searchCol = 0
id = self.dataCtrl.GetSelection()
try:
item = self.dataCtrl.model.ItemToObject(id)
except KeyError:
item = None
if item is None:
for i,v in zip(self.data.iterkeys(),self.data.itervalues()):
I'm not sure if iterkeys and itervalues are guaranteed to give you the items in the same order, but either way, this would be more efficient:
for i,v in self.data.iteritems():
if searchFor in v.data[searchCol]:
node = self.dataCtrl.model.data[i]
item = self.dataCtrl.model.ObjectToItem(node)
self.dataCtrl.Select(item)
break
else:
match = False
for topNode in self.data.iterkeys():
subnodes = [subnode for subnode in topNode.subnodes]
subnodes.insert(0,topNode)
for node in subnodes:
if node is not item and searchFor in node.data[searchCol]:
item = self.dataCtrl.model.ObjectToItem(node)
self.dataCtrl.Select(item)
self.dataCtrl.ExpandAncestors(item)
I'm not sure I understand what is the intent of this else: block of code. Are you wanting to look just at the children of the selected node? If so then you probably shouldn't be iterating over all the top nodes, and since all of the child nodes have the same value in the first col then continuing to use searchCol=0 doesn't make much sense either.
print 'found it and selecting',node.data,item
print 'selected item',self.dataCtrl.model.ItemToObject(self.dataCtrl.GetSelection()),self.dataCtrl.GetSelection()
return
BTW, at least on OSX the model must be attached to the dvc before you can add columns.
On 8/19/12 12:53 PM, Chris Mitchell wrote:
--
Robin Dunn
Software Craftsman
When searching for an entry, the data view ctrl is selecting the wrong
item if it’s currently nested.
Here’s an example showing either the bug or hopefully what I’m doing wrong.
def onEnter(self, event):
searchFor = self.searchBox.GetValue()
searchCol = 0
id = self.dataCtrl.GetSelection()
try:
item = self.dataCtrl.model.ItemToObject(id)
except KeyError:
item = None
if item is None:
for i,v in zip(self.data.iterkeys(),self.data.itervalues()):
I’m not sure if iterkeys and itervalues are guaranteed to give you the
items in the same order, but either way, this would be more efficient:for i,v in self.data.iteritems():
It’s an ordered dict, so it should be the same.
if searchFor in v.data[searchCol]:
node = self.dataCtrl.model.data[i]
item = self.dataCtrl.model.ObjectToItem(node)
self.dataCtrl.Select(item)
break
else:
match = False
for topNode in self.data.iterkeys():
subnodes = [subnode for subnode in topNode.subnodes]
subnodes.insert(0,topNode)
for node in subnodes:
if node is not item and searchFor in node.data[searchCol]:
item = self.dataCtrl.model.ObjectToItem(node)
self.dataCtrl.Select(item)
self.dataCtrl.ExpandAncestors(item)
I’m not sure I understand what is the intent of this else: block of
code. Are you wanting to look just at the children of the selected
node? If so then you probably shouldn’t be iterating over all the top
nodes, and since all of the child nodes have the same value in the first
col then continuing to use searchCol=0 doesn’t make much sense either.
The goal is to search for an entry in the data of a given column. If the user is currently selecting an item, the search will continue from that point onwards. Also, since the items are all nested (since they will be grouped), the dictionary contains only the topmost elements, so the subnodes are iterated over. This is more an illustrative point, since in the actual application the user can group by a given column, and search based on another column. What should occur in this scenario is the topmost element is selected. On the next search, the topmost element is expanded, and the first child is selected. On the next search, the second child is selected, and so on for subsequent searches.
print 'found it and selecting',node.data,item
print 'selected item',self.dataCtrl.model.ItemToObject(self.dataCtrl.GetSelection()),self.dataCtrl.GetSelection()
return
BTW, at least on OSX the model must be attached to the dvc before you
can add columns.
This shows the issue to me, the item that was selected in the code above is not the same item as reported as being currently selected.
On Monday, August 20, 2012 1:23:19 PM UTC-4, Robin Dunn wrote:
On 8/19/12 12:53 PM, Chris Mitchell wrote:
–
Robin DunnSoftware Craftsman
Another issue just cropped up while testing this code under Ubuntu 11.10:
On expanding an element, the attached error message appears and the nested tree structure is absent. I’m praying this is a problem in my code and not a gtk library bug. Any insight into this or what may be causing it would be great.
Chris
python dump.txt (6.39 KB)
On Monday, August 20, 2012 5:56:30 PM UTC-4, Chris Mitchell wrote:
On Monday, August 20, 2012 1:23:19 PM UTC-4, Robin Dunn wrote:
On 8/19/12 12:53 PM, Chris Mitchell wrote:
When searching for an entry, the data view ctrl is selecting the wrong
item if it’s currently nested.
Here’s an example showing either the bug or hopefully what I’m doing wrong.
def onEnter(self, event):
searchFor = self.searchBox.GetValue()
searchCol = 0
id = self.dataCtrl.GetSelection()
try:
item = self.dataCtrl.model.ItemToObject(id)
except KeyError:
item = None
if item is None:
for i,v in zip(self.data.iterkeys(),self.data.itervalues()):
I’m not sure if iterkeys and itervalues are guaranteed to give you the
items in the same order, but either way, this would be more efficient:for i,v in self.data.iteritems():
It’s an ordered dict, so it should be the same.
if searchFor in v.data[searchCol]:
node = self.dataCtrl.model.data[i]
item = self.dataCtrl.model.ObjectToItem(node)
self.dataCtrl.Select(item)
break
else:
match = False
for topNode in self.data.iterkeys():
subnodes = [subnode for subnode in topNode.subnodes]
subnodes.insert(0,topNode)
for node in subnodes:
if node is not item and searchFor in node.data[searchCol]:
item = self.dataCtrl.model.ObjectToItem(node)
self.dataCtrl.Select(item)
self.dataCtrl.ExpandAncestors(item)
I’m not sure I understand what is the intent of this else: block of
code. Are you wanting to look just at the children of the selected
node? If so then you probably shouldn’t be iterating over all the top
nodes, and since all of the child nodes have the same value in the first
col then continuing to use searchCol=0 doesn’t make much sense either.
The goal is to search for an entry in the data of a given column. If the user is currently selecting an item, the search will continue from that point onwards. Also, since the items are all nested (since they will be grouped), the dictionary contains only the topmost elements, so the subnodes are iterated over. This is more an illustrative point, since in the actual application the user can group by a given column, and search based on another column. What should occur in this scenario is the topmost element is selected. On the next search, the topmost element is expanded, and the first child is selected. On the next search, the second child is selected, and so on for subsequent searches.
print 'found it and selecting',node.data,item
print 'selected item',self.dataCtrl.model.ItemToObject(self.dataCtrl.GetSelection()),self.dataCtrl.GetSelection()
return
BTW, at least on OSX the model must be attached to the dvc before you
can add columns.
This shows the issue to me, the item that was selected in the code above is not the same item as reported as being currently selected.
–
Robin DunnSoftware Craftsman