wxTree Drag n Drop

David Woods wrote:

In my experience, Drag and Drop is a rather tricky beast in any language.

Also, I've had much better luck with Drag and Drop within a wxTreeCtrl on
Windows than on other platforms. If you are writing something
cross-platform, and you get something reasonable to work on Mac or *nix,
please share your code with me or put it on the Wiki, as it will help me
solve a big problem I will need to tackle in about a month.

Hi David

Be careful what you ask for - you might get it :slight_smile:

Attached is my version of Drag and Drop. It works on MSW and on GTK1 and 2.
I have not tried Mac, but perhaps someone can try it and see what happens.

Unfortunately it is rather large, but it is doing quite a lot. Check the
tooltips on the toolbar to see what functionality is available. I use F3 to
allow a manual DnD, but the mouse works in the usual way as well.

There were a number of differences between the platforms, including a few
GTK bugs regarding editing labels. In some cases I preferred the MSW
approach, in others I preferred GTK. You will see a number of places where I
have overridden behaviour to get all platforms to work the same.

In my live app the data in the tree comes from an underlying database. For
this sample, I have replaced it with a list. It was fun getting it working -
gave me a chance to practise list comprehensions.

The context for this tree is that it is linked to a table of general ledger
accounts. The accounts can have any arbitrary account number, but the user
wishes to define sequences and groupings for reporting purposes. The tree
has a user-defined depth - for this sample I have set it to 3 (or 4 if you
include the root item). The bottom level maps to an actual gl account, the
other levels are purely abstract levels created by the user to provide
sequence and grouping.

Hope it is of some use. Feel free to ask any questions.

Regards

Frank Millman

ps My toolbar uses very arbitrary icons. Does anyone know of a decent
library of toolbar icons? I have tried a couple of free ones that I found on
the web, but they were pretty mickey-mouse. Alternatively, can anyone
recommend a tool for designing my own? (I am an accountant, not a graphics
designer, so nothing too complicated please). Thanks.

tree6.py (22.2 KB)