With help from Karsten Hilbert (of gnumed fame) I added a third mixin
to TreeMixin.py. This mixin, called ExpansionState, allows you to save
and restore the expansion state of items in a tree control. The demo
illustrates this by keeping the expansion state of the three tree
controls in the notebook in sync.
Comments and feedback welcome!
Cheers, Frank
About TreeMixin:
This module provides three mixin classes that can be used with tree
controls:
- VirtualTree is a class that, when mixed in with a tree control,
makes the tree control virtual, similar to a ListCtrl in virtual mode.
A virtual tree control builds the tree itself by means of callbacks,
so the programmer is freed from the burden of building the tree herself.
- DragAndDrop is a mixin class that helps with dragging and dropping of
items. The graphical part of dragging and dropping tree items is done by
this mixin class. You only need to implement the OnDrop method that is
called when the drop happens.
- ExpansionState is a mixin that can be queried for the expansion state of
all items in the tree to restore it later.
All mixin classes work with wx.TreeCtrl, wx.gizmos.TreeListCtrl,
and wx.lib.customtree.CustomTreeCtrl. They can be used together or
separately.
The VirtualTree and DragAndDrop mixins force the wx.TR_HIDE_ROOT style.
Im not really sure how these mailing lists work, so please forgive me if Im
misusing this service or not.
I currently have a fully functional wxPython GUI, but this GUI serves as the
interface for a 3-Dimensional program written with the panda 3d engine
(www.panda3d.org). The problem is that both panda and wxPython need to occupy
an infinite main loop (wxPython's app.MainLoop) I would like to know how to
break down the app.MainLoop() and do the same things it does (i.e. handle
events), once per frame in my 3D application's main loop.
How would I go about doing this. I was told that in earlier versions of
wxPython we could use the following once per frame:
while app.Pending()
app.Dispatch()
but that no longer seems to work (I get a small unresponsive wxPython window
without any widgets)
On Sun, Feb 18, 2007 at 12:28:22AM +0100, Frank Niessink wrote:
With help from Karsten Hilbert (of gnumed fame) I added a third mixin
to TreeMixin.py. This mixin, called ExpansionState, allows you to save
and restore the expansion state of items in a tree control. The demo
illustrates this by keeping the expansion state of the three tree
controls in the notebook in sync.
Wow, this keeps getting better! Cool to see you fixed the HitTest thing. Also I love the new mix in idea, we had been doing that ourselves but I would rather use a mix in for this.
Do you have any ideas for enabling multiple selections with the DragAndDrop mixin? I changed it myself as it was trivially easy, just changing OnBeginDrag, and then StopDragging iterate over and call SelectItem on each. But it would be neat to have some method to do it. I would be happy to implement this if you had an idea. I don't know much about "talking" to mixins, I guess there could be a method like SetEnableMultipleSelections or something, and you call that with True in your trees init? Then the DragAndDrop would of course have this implemented and do the correct thing, probably just setting a boolean for appropriate places to check.
With help from Karsten Hilbert (of gnumed fame) I added a third mixin
to TreeMixin.py. This mixin, called ExpansionState, allows you to save
and restore the expansion state of items in a tree control. The demo
illustrates this by keeping the expansion state of the three tree
controls in the notebook in sync.
Comments and feedback welcome!
Cheers, Frank
About TreeMixin:
This module provides three mixin classes that can be used with tree
controls:
- VirtualTree is a class that, when mixed in with a tree control,
makes the tree control virtual, similar to a ListCtrl in virtual mode.
A virtual tree control builds the tree itself by means of callbacks,
so the programmer is freed from the burden of building the tree herself.
- DragAndDrop is a mixin class that helps with dragging and dropping of
items. The graphical part of dragging and dropping tree items is done by
this mixin class. You only need to implement the OnDrop method that is
called when the drop happens.
- ExpansionState is a mixin that can be queried for the expansion state of
all items in the tree to restore it later.
All mixin classes work with wx.TreeCtrl, wx.gizmos.TreeListCtrl,
and wx.lib.customtree.CustomTreeCtrl. They can be used together or
separately.
The VirtualTree and DragAndDrop mixins force the wx.TR_HIDE_ROOT style.
Im not really sure how these mailing lists work, so please forgive me if Im misusing this service or not.
I currently have a fully functional wxPython GUI, but this GUI serves as the interface for a 3-Dimensional program written with the panda 3d engine (www.panda3d.org). The problem is that both panda and wxPython need to occupy an infinite main loop (wxPython's app.MainLoop) I would like to know how to break down the app.MainLoop() and do the same things it does (i.e. handle events), once per frame in my 3D application's main loop.
How would I go about doing this. I was told that in earlier versions of wxPython we could use the following once per frame:
while app.Pending()
app.Dispatch()
but that no longer seems to work (I get a small unresponsive wxPython window without any widgets)
Nice ! Makes me want Debian to have wx2.8 packages
even more badly than before - to enjoy what I helped a
little bit to get there ... The other reason is AUI, BTW.
Karsten
···
On Mon, Feb 19, 2007 at 11:49:57AM -0800, Robin Dunn wrote:
>I think this is excellent stuff and well written, too, with
>demo, tests and all. It'd be really useful to get that into
>the wxPython tree.
Best would be if the mixin class queries the tree control instead of
having a separate flag. self.HasFlag(wx.TR_MULTIPLE) should work for
all three tree controls. I'll give it a try.
Cheers, Frank
···
2007/2/19, Rooney, Mike (ext. 324) <mxr@qvii.com>:
Do you have any ideas for enabling multiple selections with the DragAndDrop mixin? I changed it myself as it was trivially easy, just changing OnBeginDrag, and then StopDragging iterate over and call SelectItem on each. But it would be neat to have some method to do it. I would be happy to implement this if you had an idea. I don't know much about "talking" to mixins, I guess there could be a method like SetEnableMultipleSelections or something, and you call that with True in your trees init? Then the DragAndDrop would of course have this implemented and do the correct thing, probably just setting a boolean for appropriate places to check.
Oh boy, now I'll have to create patches. What diff options did you prefer Robin?
Cheers, Frank
···
2007/2/19, Robin Dunn <robin@alldunn.com>:
Karsten Hilbert wrote:
> On Sun, Feb 18, 2007 at 11:52:45AM +0100, Frank Niessink wrote:
>
>>> Any URL we can look at ?
>> Oops, forgot to attach the package. Sorry.
>
> I think this is excellent stuff and well written, too, with
> demo, tests and all. It'd be really useful to get that into
> the wxPython tree.
Good idea, I didn't even think of that! That wouldn't solve the case of a user who wants to allow selecting multiple items but not dragging/moving them of more than one. However that might be a small use case and they can just override a few methods if so.
Keep up the great work! I am excited to try the ExpandState mixin as well.
···
-----Original Message-----
From: fniessink@gmail.com [mailto:fniessink@gmail.com]On Behalf Of Frank
Niessink
Sent: Monday, February 19, 2007 3:36 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] TreeMixin v0.6
2007/2/19, Rooney, Mike (ext. 324) <mxr@qvii.com>:
Do you have any ideas for enabling multiple selections with the DragAndDrop mixin? I changed it myself as it was trivially easy, just changing OnBeginDrag, and then StopDragging iterate over and call SelectItem on each. But it would be neat to have some method to do it. I would be happy to implement this if you had an idea. I don't know much about "talking" to mixins, I guess there could be a method like SetEnableMultipleSelections or something, and you call that with True in your trees init? Then the DragAndDrop would of course have this implemented and do the correct thing, probably just setting a boolean for appropriate places to check.
Best would be if the mixin class queries the tree control instead of
having a separate flag. self.HasFlag(wx.TR_MULTIPLE) should work for
all three tree controls. I'll give it a try.
Cheers, Frank
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Hi Mike, please send me your code. I spent a couple of hours trying to
get dragging of multiple items at once working, but I kept coding
myself in a corner.
Thanks, Frank
···
2007/2/19, Rooney, Mike (ext. 324) <mxr@qvii.com>:
Do you have any ideas for enabling multiple selections with the DragAndDrop mixin? I changed it myself as it was trivially easy, just changing OnBeginDrag, and then StopDragging iterate over and call SelectItem on each. But it would be neat to have some method to do it. I would be happy to implement this if you had an idea. I don't know much about "talking" to mixins, I guess there could be a method like SetEnableMultipleSelections or something, and you call that with True in your trees init? Then the DragAndDrop would of course have this implemented and do the correct thing, probably just setting a boolean for appropriate places to check.
Sure, here is what I have done. I only made a trivial change to OnBeginDrag, and changed StopDragging to iterate over the list. The only thing that won't work is IsValidDropTarget, since we override that I didn't change anything in the treemixin. Are we talking about the same thing then?
2007/2/19, Rooney, Mike (ext. 324) <mxr@qvii.com>:
Do you have any ideas for enabling multiple selections with the DragAndDrop mixin? I changed it myself as it was trivially easy, just changing OnBeginDrag, and then StopDragging iterate over and call SelectItem on each. But it would be neat to have some method to do it. I would be happy to implement this if you had an idea. I don't know much about "talking" to mixins, I guess there could be a method like SetEnableMultipleSelections or something, and you call that with True in your trees init? Then the DragAndDrop would of course have this implemented and do the correct thing, probably just setting a boolean for appropriate places to check.
Hi Mike, please send me your code. I spent a couple of hours trying to
get dragging of multiple items at once working, but I kept coding
myself in a corner.
I got this small error while testing the demo
Traceback (most recent call last):
File “…/treemixin.py”, line 412, in OnBeginDrag
self._dragItem = self.GetSelections()[0]
IndexError: list index out of range
···
On 2/20/07, Rooney, Mike (ext. 324)mxr@qvii.com wrote:
Sure, here is what I have done. I only made a trivial change to OnBeginDrag, and changed StopDragging to iterate over the list. The only thing that won’t work is IsValidDropTarget, since we override that I didn’t change anything in the treemixin. Are we talking about the same thing then?
Do you have any ideas for enabling multiple selections with the DragAndDrop mixin? I changed it myself as it was trivially easy, just changing OnBeginDrag, and then StopDragging iterate over and call SelectItem on each. But it would be neat to have some method to do it. I would be happy to implement this if you had an idea. I don’t know much about “talking” to mixins, I guess there could be a method like SetEnableMultipleSelections or something, and you call that with True in your trees init? Then the DragAndDrop would of course have this implemented and do the correct thing, probably just setting a boolean for appropriate places to check.
Hi Mike, please send me your code. I spent a couple of hours trying to
get dragging of multiple items at once working, but I kept coding
myself in a corner.
Karsten Hilbert wrote:
> On Sun, Feb 18, 2007 at 11:52:45AM +0100, Frank Niessink wrote:
>
>>> Any URL we can look at ?
>> Oops, forgot to attach the package. Sorry.
>
> I think this is excellent stuff and well written, too, with
> demo, tests and all. It'd be really useful to get that into
> the wxPython tree.
It's already there.
Oh boy, now I'll have to create patches. What diff options did you prefer Robin?
Unified diff format (-u), see the bottom of this page: http://wxpython.org/codeguidelines.php. Currently the code is only on the branch with the WX_2_8_BRANCH tag.
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Yes, we are. You just left out the hard parts IsValidDropTarget
becomes more complicated because you have to make sure that none of
the dragged items will be dropped on its own parent or one of its
children. But that's doable. I ran into two other difficulties. One is
to keep the demo working with multiple items being dragged. The other
is that the tree controls behave differently while dragging. Some
change the selection, others don't (forgot which does what exactly). I
couldn't get it to work correctly for all controls. I'll probably give
it another try next week.
Cheers, Frank
···
2007/2/20, Rooney, Mike (ext. 324) <mxr@qvii.com>:
Sure, here is what I have done. I only made a trivial change to OnBeginDrag, and changed StopDragging to iterate over the list. The only thing that won't work is IsValidDropTarget, since we override that I didn't change anything in the treemixin. Are we talking about the same thing then?
Yes, thanks. I've fixed that. I'll post a new version today.
Cheers, Frank
···
2007/2/20, roee shlomo <roee88@gmail.com>:
Thanks Frank, it looks great
I got this small error while testing the demo
Traceback (most recent call last):
File ".../treemixin.py", line 412, in OnBeginDrag
self._dragItem = self.GetSelections()[0]
IndexError: list index out of range