I am trying to create methods to shift nodes in a tree in four directions - up, down, left, and right, like in Leo. I have created two methods that work to an extent. They fail in traversing across siblings and in traversing upwards. I have not yet begun to work on the left and right methods.
Hi Saketh,
For the ComboTreeBox I was working on (see a previous message of mine, few days ago), I needed easier navigation of a tree. In particular I wanted to be able to find the next 'lower' item, whether it was a sibling or a child. Also, I wanted to be able to find the next 'higher' item, whether it would be a sibling or the parent or the child of a sibling. So I extended TreeCtrl a bit to provide those methods. Maybe they will help in your project?
I am trying to create methods to shift nodes in a tree in four
directions - up, down, left, and right, like in Leo. I have created two
methods that work to an extent. They fail in traversing across siblings
and in traversing upwards. I have not yet begun to work on the left and
right methods.
Hi Saketh,
For the ComboTreeBox I was working on (see a previous message of mine,
few days ago), I needed easier navigation of a tree. In particular I
wanted to be able to find the next ‘lower’ item, whether it was a
sibling or a child. Also, I wanted to be able to find the next ‘higher’
item, whether it would be a sibling or the parent or the child of a
sibling. So I extended TreeCtrl a bit to provide those methods. Maybe
def OnShiftDown(self, e):
old = self.tree.GetSelection()
self.tree.AppendItem(old, self.GetNextItem (old))
self.DeleteNode(old)
First, maybe this is nothing, but why are you calling AppendItem on self.tree and GetNextItem on self?
Second, the documentation for TreeCtrl.AppendItem says:
wxTreeItemId AppendItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selImage = -1, wxTreeItemData* data = NULL)
but you are providing two TreeItemId's to AppendItem...
First, if a node has grandparents (Grandparent -> parent -> node), I can't shift it so that it becomes Grandparent -> node -> parent, regardless of whether I use either down or up. This is a predicament that I faced before I used the tree.py code as well.
It's hard to give suggestions without seeing all code.
This may sound foolish, but I just realized that my application needs no support for grandchildren. It only goes down one level beyond the root node. Thus, my OnShiftDown and OnShiftUp code looks like this now:
def OnShiftDown(self, e):
old = self.tree.GetSelection()
target = self.tree.GetNextSibling(old)
if not target.IsOk():
return
new = self.tree.InsertItem(parent = target, idPrevious = old, text = self.tree.GetItemText(old), data = self.tree.GetItemData(old))
self.tree.SelectItem(new)
self.DeleteNode(old)
def OnShiftUp(self, e):
old = self.tree.GetSelection()
target = self.tree.GetItemParent(old)
if not target.IsOk():
return
new = self.tree.InsertItem
(parent = target, idPrevious = old, text = self.tree.GetItemText(old), data = self.tree.GetItemData(old))
self.tree.SelectItem(new)
self.DeleteNode(old)
All that I want it to do is shift above and below siblings. For example, if “Top” is above “Middle” is above “Bottom”, then two successive OnShiftDowns should put Top below Bottom. However, this is not working so well. I am currently trying to resolve this issue, because right now it just makes the node the sibling’s child.