[wxPython-users] TreeCtrl Traversal
Saketh Bhamidipati
saketh.bhamidipati at gmail.com
Fri Jun 16 15:30:55 PDT 2006
On 6/16/06, Saketh Bhamidipati <saketh.bhamidipati at gmail.com> wrote:
>
>
>
> On 6/16/06, Frank Niessink <frank at niessink.com> wrote:
>
> > Saketh Bhamidipati:
> > 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?
>
> Cheers, Frank
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
> These methods are exactly what I was looking for. I'm going to try to
> implement them in my application.
>
The tree.py code is extremely useful!
But there is a slight problem, still, with my coding. Although I am now able
to accomplish the same thing that I had before in 3 lines of code per
method, there are a few issues.
Here are the methods that use the tree.py code (so much shorter!):
def OnShiftDown(self, e):
old =3D self.tree.GetSelection()
self.tree.AppendItem(old, self.GetNextItem(old))
self.DeleteNode(old)
def OnShiftUp(self, e):
old =3D self.tree.GetSelection()
self.tree.PrependItem(old, self.GetPreviousItem(old))
self.DeleteNode(old)
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.
Second, it sometimes skips siblings completely. If there is a node has a
grandparent as a sibling, and I use ShiftDown, it skips the grandparent and
all of its children except for the last one. I think this is because I used
AppendItem, but I'm not sure. The same problem goes for shifting up.
So how can I use InsertItem (or another method) to make a node become its
sibling's first child? Currently, it jumps straight to being the last one.
Help is greatly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200606=
16/316be9b3/attachment.htm
More information about the wxpython-users
mailing list