moving tree items arround

Hi,

Are there any convenience functions to move arround a tree item toghether
with its children (sub-items attached to it) ?

All I can find are the delete and add item methods ? Is that all ? Wouldn't
be nice to have such methods ? Are there any established methods to do this
? I need to be able to drag an sub-item with all its children from one item
and make it the sub-item of another item:

A simple example would be moving item 1.1 from item 1 to item 2.1

    item 1
      + item 1.1
          + item 1.1.1
          + item 1.1.2
    item 2
      + item 2.1

to:

    item 1
    item 2
      + item 2.1
          + item 1.1
              + item 1.1.1
              + item 1.1.2

TIA,

Ionutz

I do the exact same thing in one of my apps. What I've done is stored a
PyData object (wxTreeCtrl::SetPyData()) with each tree item. This PyData
obj holds references to the PyData objects of each of the target object's
children. When I start the drag, I stick the PyData obj of the item being
dragged into a Dictionary where the key is the item text of the item being
dragged (wxTreeCtrl::GetItemText()). Once I've dropped the item, I go back
and pull its PyData obj out of the Dictionary, inspect it for children, then
reconstruct the children in the tree using wxTreeCtrl::AppendItem().

My drop target is a subclass of wxPyDropTarget. When I initialize the drop
target, I pass it a reference to the wxTreeCtrl obj that was the drag source
(could be the same or a different tree as the drop target). A reference to
the dictionary can then be obtained from the reference to the drag source.

As I re-read this, it sounds more complicated than it really is. Let me
know if it doesn't make sense.

Paul Gardella
BBN Technologies

···

-----Original Message-----
From: borco@go.ro [mailto:borco@go.ro]
Sent: Monday, September 15, 2003 7:52 AM
To: wxPython-users@lists.wxwindows.org
Subject: [wxPython-users] moving tree items arround

Hi,

Are there any convenience functions to move arround a tree item toghether
with its children (sub-items attached to it) ?

All I can find are the delete and add item methods ? Is that all ? Wouldn't
be nice to have such methods ? Are there any established methods to do this
? I need to be able to drag an sub-item with all its children from one item
and make it the sub-item of another item:

A simple example would be moving item 1.1 from item 1 to item 2.1

    item 1
      + item 1.1
          + item 1.1.1
          + item 1.1.2
    item 2
      + item 2.1

to:

    item 1
    item 2
      + item 2.1
          + item 1.1
              + item 1.1.1
              + item 1.1.2

TIA,

Ionutz

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

I am also doing my own micro-management as the items are going to actually
represent objects in a OO database (using e4py/metakit package - this is not
done yet) and I got stuck when moving sub-trees from one item to another.

I have started now with a new object derived from wx.TreeCtrl and hope to
get it right now (cleaner, too :slight_smile:

What I do is basically store in every tree itema python object called Data
that has the position in its parent Data (a 0-based integer), the expanded
state and a list with children. Adding a new child to an item will also add
a new Data to the children list of the associated Data object. Vertically
moving an item is done changing the position in the python Data objects and
resorting the items based on the position. The part that didn't work very
good was that when I was moving a subtree from an item to another.

I guess my solution is using more memory, as I store information about the
state of all objects from the tree. However, from a first look at what
you've wrote I don't see how you can move up and down items in your tree
with your algorithm...

What I whant to have in the end is a tree like that from Leo editor, where
you can move an item arround in the tree as you see fit.

Ionutz

PS: I'll post on the list the code when it's done (for code review :slight_smile:

···

----- Original Message -----
From: "Paul Gardella" <pgardell@bbn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Tuesday, September 16, 2003 19:50
Subject: RE: [wxPython-users] moving tree items arround

I do the exact same thing in one of my apps. What I've done is stored a
PyData object (wxTreeCtrl::SetPyData()) with each tree item. This PyData
obj holds references to the PyData objects of each of the target object's
children. When I start the drag, I stick the PyData obj of the item being
dragged into a Dictionary where the key is the item text of the item being
dragged (wxTreeCtrl::GetItemText()). Once I've dropped the item, I go

back

and pull its PyData obj out of the Dictionary, inspect it for children,

then

reconstruct the children in the tree using wxTreeCtrl::AppendItem().

My drop target is a subclass of wxPyDropTarget. When I initialize the

drop

target, I pass it a reference to the wxTreeCtrl obj that was the drag

source

(could be the same or a different tree as the drop target). A reference

to

the dictionary can then be obtained from the reference to the drag source.

As I re-read this, it sounds more complicated than it really is. Let me
know if it doesn't make sense.

Paul Gardella
BBN Technologies