ANN: CustomTreeCtrl For wxPython ;-)
27 answers - 2863 bytes -

Hello NG,
I would like to announce my latest child, CustomTreeCtrl.
CustomTreeCtrl is a class that mimics the behavior of wx.TreeCtrl, with
almost the same base functionalities plus some more enhancements. This class
does not rely on the native control, as it is a full owner-drawn tree
control.
Apart of the base functionalities of CustomTreeCtrl (described below), in
addition to the standard wx.TreeCtrl behavior this class supports:
* CheckBox-type items;
* RadioButton-type items;
* HyperLink-type items: they look like an hyperlink, with the proper mouse
cursor on hovering;
* Multiline text items;
* Enabling/disabling items (together with their plain or grayed out icons);
* Whatever non-toplevel widget can be attached next to an item;
* Default selection style, gradient (horizontal/vertical) selection style
and Windows Vista selection style;
* Customized drag and drop images built on the fly;
* Setting the CustomTreeCtrl item buttons to a personalized imagelist;
* Setting the CustomTreeCtrl check/radio item icons to a personalized
imagelist;
* Changing the style of the lines that connect the items (in terms of
wx.Penstyles);
* Using an image as a CustomTreeCtrl background (currently only in "tile"
mode).
And a lot more. Check the demo for an almost complete review of the
functionalities.
The demo by itself is *very* huge, as I wanted to show the basic
functionalities and the new one, as completely as possible (even if the demo
does not show all the possibilities). In the demo, you can use the options
on the left wx.ScrolledWindow and the right mouse button on the
CustomTreeCtrl to activate other methods.
I appreciate any comment, suggestion, idea and bug report (patches are far
more welcomed :-) ). Noting that the code by itself is quite long, it is
highly possible that some bug is loudly laughing at me and I didn't spot it
I tested the code on Windows XP, Python 2.3/2.4 and wxPython 2.6.3.2. It
should work also with older version of wxPython, but I am not sure. I have
no idea of its behavior on GTK and Mac, though I am expecting (as usual) a
gazillion of problems on that amazing platform that is Mac. If someone is
able to run it on other platforms than Windows, I would like to ask him/her
if he/she can please send me some screenshots of it.
You can find the source, the demo, the epydoc-generated documentation and
some screenshots in the usual place:
#customtree
, if you prefer in italian:
#customtree
Enjoy, and happy wxPythoning ;-)
Andrea.
P.S. Please don't tell me it's not Pythonic it doesn't mean anything to
me, plus the code is heavily based on the C++ generic wxWidgets
implementation :-)
No.1 | | 1705 bytes |
| 
May 18, 2006, at 3:10 PM, Andrea Gavana wrote:
Hello NG,
I would like to announce my latest child, CustomTreeCtrl.
<snip>
I tested the code on Windows XP, Python 2.3/2.4 and wxPython
2.6.3.2. It should work also with older version of wxPython, but I
am not sure. I have no idea of its behavior on GTK and Mac, though
I am expecting (as usual) a gazillion of problems on that amazing
platform that is Mac. If someone is able to run it on other
platforms than Windows, I would like to ask him/her if he/she can
please send me some screenshots of it.
the Mac, CustomTreeCtrl.py is broken at line 1822. It should be
platform, major, minor = wx.GVersion()
It will then run the demo. But it throws an exception:
L:~/ jjackson$ pythonw
CTDemo.py
Traceback (most recent call last):
File "/
CustomTreeCtrl.py", line 4494, in Paint
self.PaintLevel(self._anchor, dc, 0, y)
File "/
CustomTreeCtrl.py", line 4321, in PaintLevel
pen = wx.Pen(((item.IsSelected() and self._hasFocus) and
[self._borderPen] or [wx.TRANSPARENT])[0])
File "//", line 322,
in __init__
newobj = _gdi_.new_Pen(*args, **kwargs)
TypeError: Expected a wxColour object or a string containing a colour
name or '#RRGGBB'.
The tree doesn't show at all on the Mac, and the buttons on the left
don't arrange properly after scrolling. Looks like a sizer problem
for the buttons.
Shouldn't the "Themes" buttons be a radio set rather than check
buttons, as one of the themes is always active?
(I'll send a screen shot to Andrea directly.)
John Jackson
No.2 | | 447 bytes |
| 
Andrea Gavana wrote:
Hello NG,
I would like to announce my latest child, CustomTreeCtrl.
WW, fantastic control Andrea!
linux (deb 3.1 + wx 2.6.x) all work except into the left side of demo
where I see the buttons cut:
Bye,
Michele
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.3 | | 1558 bytes |
| 
Fri, 19 May 2006 00:10:43 +0200, "Andrea Gavana" <andrea.gavana (AT) gmail (DOT) comwrote:
>Hello NG,
I would like to announce my latest child, CustomTreeCtrl.
>
>
>CustomTreeCtrl is a class that mimics the behavior of wx.TreeCtrl, with
>almost the same base functionalities plus some more enhancements. This class
>does not rely on the native control, as it is a full owner-drawn tree
>control.
Hello Andrea,
i agree totally with Michele,
simply wow, such a complex and vast demo in addition!
and also the documentation.
sentence about the control: the cursor movment is not optimal.
Waht I mean is (on Windows XP):
Start the demo =cursor down (item0 is marked), press cursor right to open
the subbranch =cursor down (item0-a is active) =cursor right.
1) So now if you press cursor down, nothing happens (I would expect to select item0-b.
2) if you press cursor left, I would expect to close the current branch but it jump to item0.
It could be of course:
1) it is intended to work so.
2) I oversaw some settings switch to adjust this.
You should have the wxPython contribution award (at least for the second quarter
of 2006 beside Robin of course) for your work! :-)
I think the wxWidgets users could be becoming envious
to see alle the wxPython controls you and some others
have created.
The Python binding can soon more than the C++ wxWidgets itself!!! :)
No.4 | | 2431 bytes |
| 
Andrea Gavana wrote:
Hello NG,
I would like to announce my latest child, CustomTreeCtrl.
All I can say is, "Wow!"
ok, maybe I can say a bit more. ;-)
Linux I'm getting a strange effect where the mouse cursor momentarily
disappears each time the mouse moves over the tree window. When moving
fast the cursor ends up not being visible at all. Are you doing
anything on mouse move events or in idle handlers that could possibly
have an affect like that? (Perhaps forcing a refresh, changing cursor,
etc.) I've seen it happen in a few other apps too, although not quite
as bad, so it may be some funky configuration issue for my system. but
it would still be nice to figure out why it happens and see if a
workaround would be possible.
In the demo you should really let the buttons have their default height.
There are too many variations of themes to be able to guess ahead of
time how tall is tall enough.
Mac you can't set the background colour of wx.Buttons so the ones
that you are using for colour selection are just ugly.
wx.lib.colourselect would work better.
I think that it would be better to not create new values for the TR_*,
wxEVT_*, EVT_* and etc. that have the same names as used with the
wx.TreeCtrl. Instead just make assignments from the values that already
exist in the wx module. This way if somebody mistakenly uses
wx.EVT_TREE_ITEM_ACTIVATED instead of
the event will still be caught by
their handler because the event types will be equivalent.
For other constants and such in the module that are for internal use
only, it would be nice to rename them with a leading underscore so
epydoc won't make an entry for them in the document.
Is there a way to toggle check or radio items with the keyboard?
Mac there is a bug where the cursor keys are not reporting their WXK_
values in the EVT_CHAR event. You should use EVT_KEY_DWN instead.
Mac doesn't support user-dash pens very well. A better default may be a
solid line, with a lighter grey colour.
In Your Docstrings And Comments The Every Word Is Capitalized Style Is
Difficult To Read. :-)
For consistency with the other events EVT_TREE_ITEM_CHECK should
probably be EVT_TREE_ITEM_CHECKED.
I guess that's it for now. again Andrea you've amazed us all!
No.5 | | 296 bytes |
| 
Robin Dunn wrote:
Mac there is a bug where the cursor keys are not reporting their WXK_
values in the EVT_CHAR event. You should use EVT_KEY_DWN instead.
Uh oh I just noticed that you do it the same way as the generic C++
tree control, so wxMac has the same problem there too!
No.6 | | 4307 bytes |
| 
Hello Robin & NG,
>All I can say is, "Wow!"
Hehehehehe, this is probably the first time that you say "wow" to one of my
controls :-)
Linux I'm getting a strange effect where the mouse cursor momentarily
>disappears each time the mouse moves over the tree window. When moving
>fast the cursor ends up not being visible at all. Are you doing
>anything on mouse move events or in idle handlers that could possibly
>have an affect like that?
Yes, there is a constant call to self.SetCursor(wx.StockCursor(
wx.CURSR_ARRW)) to try to handle the hyperlink items. I will see if I can
get rid of it.
>In the demo you should really let the buttons have their default height.
>There are too many variations of themes to be able to guess ahead of
>time how tall is tall enough.
, I will do it.
Mac you can't set the background colour of wx.Buttons so the ones
>that you are using for colour selection are just ugly.
>wx.lib.colourselect would work better.
Ah, another Mac surprise I have never used wx.lib.colourselect, I will
give it a try.
>I think that it would be better to not create new values for the TR_*,
>wxEVT_*, EVT_* and etc. that have the same names as used with the
>wx.TreeCtrl. Instead just make assignments from the values that already
>exist in the wx module. This way if somebody mistakenly uses
>wx.EVT_TREE_ITEM_ACTIVATED instead of
the event will still be caught by
>their handler because the event types will be equivalent.
Mhm, this is not very clear to me do you mean I should get rid of all
the:
wxEVT_TREE_ITEM_HYPERLINK = wx.NewEventType()
And:
EVT_TREE_BEGIN_DRAG = wx.PyEventBinder(wxEVT_TREE_BEGIN_DRAG, 1)
? (I put these events as an example). Should I remove all of them? And what
about the events that does not exist in wx, like wxEVT_TREE_ITEM_CHECKING
and wxEVT_TREE_ITEM_HYPERLINK? I would end up in having mixed things, like
wx.EVT_TREE_SEL_CHANGED and in the
demo and in the applications that used this control or have I
misunderstood what you meant?
>For other constants and such in the module that are for internal use
>only, it would be nice to rename them with a leading underscore so
>epydoc won't make an entry for them in the document.
Mhm, ok, I will change things like NIMAGE to _NIMAGE.
Is there a way to toggle check or radio items with the keyboard?
Not at the moment, but I was thinking about it the problem is that the
spacebar char is already used to send wxEVT_TREE_ITEM_ACTIVATED together
with the return key should I use the spacebar also to check the
check/radio items and sending the appropriate event?
Mac there is a bug where the cursor keys are not reporting their WXK_
>values in the EVT_CHAR event. You should use EVT_KEY_DWN instead.
No problem, will do it.
>Mac doesn't support user-dash pens very well. A better default may be a
>solid line, with a lighter grey colour.
, I will make a switch to do that on Mac, because on Windows I like the
dashed pen.
>In Your Docstrings And Comments The Every Word Is Capitalized Style Is
>Difficult To Read. :-)
Ah, I am sorry for that, I am still to used in writing docstrings that way,
but I understand that is wrong. I will change them accordingly.
>For consistency with the other events EVT_TREE_ITEM_CHECK should
>probably be EVT_TREE_ITEM_CHECKED.
, will do it.
>I guess that's it for now. again Andrea you've amazed us all!
Thank you, I am happy to contribute to the community I only wish that, if
someone makes improvements/patches to those owner-drawn controls, he/she
will contribute them back.
Thank you very much for your useful comments!
Andrea.
No.7 | | 2254 bytes |
| 
Andrea Gavana wrote:
Hello Robin & NG,
>All I can say is, "Wow!"
Hehehehehe, this is probably the first time that you say "wow" to one of
my controls :-)
Linux I'm getting a strange effect where the mouse cursor momentarily
>disappears each time the mouse moves over the tree window. When moving
>fast the cursor ends up not being visible at all. Are you doing
>anything on mouse move events or in idle handlers that could possibly
>have an affect like that?
Yes, there is a constant call to
self.SetCursor(wx.StockCursor(wx.CURSR_ARRW)) to try to handle the
hyperlink items. I will see if I can get rid of it.
Ah, I didn't look in that part. You can probably set a flag or two that
will help you only change the cursor when entering or leaving the area
where a hyperlink item is located.
>I think that it would be better to not create new values for the TR_*,
>wxEVT_*, EVT_* and etc. that have the same names as used with the
>wx.TreeCtrl. Instead just make assignments from the values that already
>exist in the wx module. This way if somebody mistakenly uses
>wx.EVT_TREE_ITEM_ACTIVATED instead of
the event will still be caught by
>their handler because the event types will be equivalent.
Mhm, this is not very clear to me do you mean I should get rid of all
Not get rid of them, just initialize them from their wx counterparts so
they have the same values. Like this:
wxEVT_TREE_BEGIN_DRAG = wx.wxEVT_TREE_BEGIN_DRAG
and
EVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG
And
what about the events that does not exist in wx, like
Leave them as they are.
Is there a way to toggle check or radio items with the keyboard?
Not at the moment, but I was thinking about it the problem is that
the spacebar char is already used to send wxEVT_TREE_ITEM_ACTIVATED
together with the return key should I use the spacebar also to check
the check/radio items and sending the appropriate event?
I think that is what most people would expect.
No.8 | | 710 bytes |
| 
Hello Robin,
thank you for your suggestions. I am probably missing something here:
>Not get rid of them, just initialize them from their wx counterparts so
>they have the same values. Like this:
>
>wxEVT_TREE_BEGIN_DRAG = wx.wxEVT_TREE_BEGIN_DRAG
>
>and
>
>EVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG
import wx
wx.wxEVT_TREE_BEGIN_DRAG
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute 'wxEVT_TREE_BEGIN_DRAG'
Huh?!?!? None of the wx.wxEVT_TREE* exist I am surely misunderstanding
something
No.9 | | 3205 bytes |
| 
Me too. I tried to fix this, and ended up with this (there are three
new event types):
wxEVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG.evtType[0]
wxEVT_TREE_ITEM_MENU = wx.EVT_TREE_ITEM_MENU.evtType[0]
wxEVT_TREE_ITEM_CHECKING = wx.NewEventType()
wxEVT_TREE_ITEM_CHECK = wx.NewEventType()
wxEVT_TREE_ITEM_HYPERLINK = wx.NewEventType()
and
EVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG
EVT_TREE_ITEM_MENU = wx.EVT_TREE_ITEM_MENU
EVT_TREE_ITEM_CHECKING = wx.PyEventBinder(wxEVT_TREE_ITEM_CHECKING, 1)
EVT_TREE_ITEM_CHECK = wx.PyEventBinder(wxEVT_TREE_ITEM_CHECK, 1)
EVT_TREE_ITEM_HYPERLINK = wx.PyEventBinder(wxEVT_TREE_ITEM_HYPERLINK, 1)
I've also run into these problems -- I'm trying to use the control as
a drop-in replacement for wxTreeCtrl:
-- There's no I method: (maybe no longer needed):
def I(self):
""" Returns Whether The Item Is Not. """
return True
-- TRs needed redefining:
TR_MULTIPLE = wx.TR_MULTIPLE
TR_HAS_BUTTNS = wx.TR_HAS_BUTTNS
TR_HIDE_RT = wx.TR_HIDE_RT
TR_FULL_RW_HIGHLIGHT = wx.TR_FULL_RW_HIGHLIGHT
-- In the demo, if you hide the root, and then push the recreate button:
[Session started at 2006-05-20 06:29:12 -0700.]
Traceback (most recent call last):
File "CTDemo.py", line 1079, in RecreateTree
self.tree = CustomTreeCtrl(self.treeParentPanel, -1, log=self.log)
File "CTDemo.py", line 1594, in __init__
self.Expand(self.root)
File "/Volumes/Banff-5/2983/beta 1.0.9.5 build 1095/CustomTreeCtrl/
CustomTreeCtrl.py", line 3391, in Expand
raise "\nERRR: Can't Expand An Hidden Root. "
ERRR: Can't Expand An Hidden Root.
if something goes wrong in the demo, it doesn't recover very well
because the tree gets destroyed in Recreate:
def RecreateTree(self, event):
I've added things such as:
def CheckStyle(self, event):
if hasattr(self, 'tree'):
self.tree.ChangeStyle(self.treestyles)
event.Skip()
but that doesn't always solve the problem.
I haven't been able to get drag 'n drop working.
May 20, 2006, at 6:12 AM, Andrea Gavana wrote:
Hello Robin,
thank you for your suggestions. I am probably missing something
here:
>
>Not get rid of them, just initialize them from their wx
counterparts so
>they have the same values. Like this:
>
>wxEVT_TREE_BEGIN_DRAG = wx.wxEVT_TREE_BEGIN_DRAG
>
>and
>
>EVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG
>
import wx
wx.wxEVT_TREE_BEGIN_DRAG
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute
'wxEVT_TREE_BEGIN_DRAG'
Huh?!?!? None of the wx.wxEVT_TREE* exist I am surely
misunderstanding something
John Jackson
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.10 | | 554 bytes |
| 
May 19, 2006, at 4:23 PM, Andrea Gavana wrote:
I've started using the control in my project, and I found that you
have changed a couple of methods for
SetItemPyData = SetPyData
GetItemPyData = GetPyData
Since it would be nice if this were a drop-in replacement for the wx
control, perhaps add these two lines?
John Jackson
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.11 | | 3107 bytes |
| 
Hello John,
thanks for the info on the events. I will modify them.
>I've also run into these problems -- I'm trying to use the control as
>a drop-in replacement for wxTreeCtrl:
>
There's no I method: (maybe no longer needed):
You don't need it anymore. It does not make any sense in Python to check if
an item is or not: if the item exist, then it is , otherwise you will
get "None" as answer. In this respect, every time that you wrote something
like this in wx.TreeCtrl:
if item.I():
# do something
Now you will have in CustomTreeCtrl:
if item:
# do something
TRs needed redefining:
>
>TR_MULTIPLE = wx.TR_MULTIPLE
>TR_HAS_BUTTNS = wx.TR_HAS_BUTTNS
>TR_HIDE_RT = wx.TR_HIDE_RT
>TR_FULL_RW_HIGHLIGHT = wx.TR_FULL_RW_HIGHLIGHT
Yes, Robin already suggested it, I am doing the conversion right now.
In the demo, if you hide the root, and then push the recreate button:
>
>Traceback (most recent call last):
File "CTDemo.py", line 1079, in RecreateTree
self.tree = CustomTreeCtrl(self.treeParentPanel, -1, log=self.log)
File "CTDemo.py", line 1594, in __init__
self.Expand(self.root)
File "/Volumes/Banff-5/2983/beta 1.0.9.5 build 1095/CustomTreeCtrl/
>CustomTreeCtrl.py", line 3391, in Expand
raise "\nERRR: Can't Expand An Hidden Root. "
>
>ERRR: Can't Expand An Hidden Root.
Yes, this was a flaw in my demo: before calling self.Expand(self.root), I
should check if the control has TR_HIDE_RT flag activated. It just take an
"if" condition to do that. I will do it.
>I haven't been able to get drag 'n drop working.
Ah, this one I don't know here it is working. Do you see the "Beginning
Drag" text string in the log window whan you start dragging? Have you
enabled the events EVT_TREE_BEGIN_DRAG and EVT_TREE_END_DRAG in the
checkboxes?
>I've started using the control in my project, and I found that you
>have changed a couple of methods for
>
SetItemPyData = SetPyData
GetItemPyData = GetPyData
>
>Since it would be nice if this were a drop-in replacement for the wx
>control, perhaps add these two lines?
That's the first time that I have heard about SetItemPyData and
GetItemPyData. I always use SetPyData and GetPyData. The wxPython demo uses
them, and also the docs shows that:
void SetItemData(const wxTreeItemId& item, wxTreeItemData* data)
Sets the item client data.
wxPython note: wxPython provides the following shortcut method:
SetPyData(item, obj) Associate the given Python with the
wxTreeItemData for the given item Id.
I see that the two methods you mentioned actually exist, so I will add them
Andrea.
No.12 | | 1725 bytes |
| 
Andrea Gavana wrote:
Hello Robin,
thank you for your suggestions. I am probably missing something here:
>Not get rid of them, just initialize them from their wx counterparts so
>they have the same values. Like this:
>
>wxEVT_TREE_BEGIN_DRAG = wx.wxEVT_TREE_BEGIN_DRAG
>
>and
>
>EVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG
import wx
wx.wxEVT_TREE_BEGIN_DRAG
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute 'wxEVT_TREE_BEGIN_DRAG'
Huh?!?!? None of the wx.wxEVT_TREE* exist I am surely
misunderstanding something
No, it was my fault. I had forgotten that the tree event constants in
the wx package all have a _CMMAND_ in the name. Here is the full list:
%constant wxEventType wxEVT_CMMAND_TREE_BEGIN_DRAG;
%constant wxEventType wxEVT_CMMAND_TREE_BEGIN_RDRAG;
%constant wxEventType ;
%constant wxEventType ;
%constant wxEventType wxEVT_CMMAND_TREE_DELETE_ITEM;
%constant wxEventType wxEVT_CMMAND_TREE_GET_INF;
%constant wxEventType wxEVT_CMMAND_TREE_SET_INF;
%constant wxEventType ;
%constant wxEventType ;
%constant wxEventType ;
%constant wxEventType ;
%constant wxEventType wxEVT_CMMAND_TREE_SEL_CHANGED;
%constant wxEventType wxEVT_CMMAND_TREE_SEL_CHANGING;
%constant wxEventType wxEVT_CMMAND_TREE_KEY_DWN;
%constant wxEventType ;
%constant wxEventType ;
%constant wxEventType ;
%constant wxEventType wxEVT_CMMAND_TREE_END_DRAG;
%constant wxEventType ;
%constant wxEventType ;
%constant wxEventType wxEVT_CMMAND_TREE_ITEM_MENU;
No.13 | | 773 bytes |
| 
Andrea Gavana wrote:
>I've started using the control in my project, and I found that you
>have changed a couple of methods for
>
SetItemPyData = SetPyData
GetItemPyData = GetPyData
>
>Since it would be nice if this were a drop-in replacement for the wx
>control, perhaps add these two lines?
That's the first time that I have heard about SetItemPyData and
GetItemPyData. I always use SetPyData and GetPyData. The wxPython demo
uses them, and also the docs shows that:
The Get/SetItemPyData were added a while back in order to be more
consistent with the names of other methods, and the Get/SetPyData were
left as aliases for compatibility.
No.14 | | 859 bytes |
| 
Andrea Gavana wrote:
Hello John,
>Adding an event.Skip() solved the problem.
>
>But I'm wondering if this is the correct design -- shouldn't
>event.Allow() be enough?
I don't know, I have never used DnD in wx.TreeCtrl. The implementation
of CustomTreeCtrl in this respect is the same as the generic C++ version
of wx.TreeCtrl maybe Robin could explain better which the default
behaviour should be
I think you may have misread the generic treectrl code. It has this line:
if ( GetEventHandler()->ProcessEvent(nevent) && nevent.IsAllowed() )
And you have this:
if not self.GetEventHandler().ProcessEvent(nevent) and nevent.IsAllowed():
So you need to drop the "not". The code is different, but the MSW
treectrl behaves the same way.
No.15 | | 518 bytes |
| 
Hello John,
>It does work in the demo, at least as far as the drag. I don't see
>the drop working -- the order of the items isn't changing. Is that
>because it isn't implemented in the demo?
Correct. I have not implemented the actual *operation* that the DnD should
do. To do that, I should take some code from the wiki and implement the
actual DnD operation I don't think this is strictly related to the
control itself
Andrea.
No.16 | | 475 bytes |
| 
Hello John,
>Adding an event.Skip() solved the problem.
>
>But I'm wondering if this is the correct design -- shouldn't
>event.Allow() be enough?
I don't know, I have never used DnD in wx.TreeCtrl. The implementation of
CustomTreeCtrl in this respect is the same as the generic C++ version of
wx.TreeCtrl maybe Robin could explain better which the default behaviour
should be
Andrea.
No.17 | | 930 bytes |
| 
I should correct this. I haven't been able to get it working in my
code, where I've dropped in your control.
It does work in the demo, at least as far as the drag. I don't see
the drop working -- the order of the items isn't changing. Is that
because it isn't implemented in the demo?
May 20, 2006, at 6:51 AM, Andrea Gavana wrote:
>I haven't been able to get drag 'n drop working.
>
Ah, this one I don't know here it is working. Do you see the
"Beginning Drag" text string in the log window whan you start
dragging? Have you enabled the events EVT_TREE_BEGIN_DRAG and
EVT_TREE_END_DRAG in the checkboxes?
John Jackson
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.18 | | 1394 bytes |
| 
Andrea,
K, I found what I was doing. For some reason, in the wx.TreeCtrl,
the begin drag handler only required an event.Allow() to work. It
worked without an event.Skip().
Adding an event.Skip() solved the problem.
But I'm wondering if this is the correct design -- shouldn't
event.Allow() be enough?
May 20, 2006, at 8:57 AM, John Jackson wrote:
I should correct this. I haven't been able to get it working in my
code, where I've dropped in your control.
It does work in the demo, at least as far as the drag. I don't see
the drop working -- the order of the items isn't changing. Is that
because it isn't implemented in the demo?
May 20, 2006, at 6:51 AM, Andrea Gavana wrote:
>
>>I haven't been able to get drag 'n drop working.
>>
>Ah, this one I don't know here it is working. Do you see the
>"Beginning Drag" text string in the log window whan you start
>dragging? Have you enabled the events EVT_TREE_BEGIN_DRAG and
>EVT_TREE_END_DRAG in the checkboxes?
>
John Jackson
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.19 | | 1190 bytes |
| 
Robin, that was great. Fixed things up.
Andrea, thanks for the great control. It's working very nicely. I've
been able to fix the problems I was having with the C++ native control.
May 20, 2006, at 9:45 AM, Robin Dunn wrote:
Andrea Gavana wrote:
>Hello John,
>>Adding an event.Skip() solved the problem.
>>
>>But I'm wondering if this is the correct design -- shouldn't
>>event.Allow() be enough?
>I don't know, I have never used DnD in wx.TreeCtrl. The
>implementation of CustomTreeCtrl in this respect is the same as
>the generic C++ version of wx.TreeCtrl maybe Robin could
>explain better which the default behaviour should be
>
I think you may have misread the generic treectrl code. It has
this line:
if ( GetEventHandler()->ProcessEvent(nevent) && nevent.IsAllowed() )
And you have this:
if not self.GetEventHandler().ProcessEvent(nevent) and
nevent.IsAllowed():
So you need to drop the "not". The code is different, but the MSW
treectrl behaves the same way.
--
No.20 | | 2936 bytes |
| 
Hello NG,
just a note to say that a new version of CustomTreeCtrl is
available (0.4). This version include the fixes that John sent me,
and:
Linux I'm getting a strange effect where the mouse cursor momentarily
disappears each time the mouse moves over the tree window. When moving
fast the cursor ends up not being visible at all. Are you doing
anything on mouse move events or in idle handlers that could possibly
have an affect like that? (Perhaps forcing a refresh, changing cursor,
etc.)
I have got rid of that SetCursor, you may try it now and see if the
problem persists
In the demo you should really let the buttons have their default height.
There are too many variations of themes to be able to guess ahead of
time how tall is tall enough.
Done. Now the buttons have their default size.
Mac you can't set the background colour of wx.Buttons so the ones
that you are using for colour selection are just ugly.
wx.lib.colourselect would work better.
Done.
I think that it would be better to not create new values for the TR_*,
wxEVT_*, EVT_* and etc. that have the same names as used with the
wx.TreeCtrl. Instead just make assignments from the values that already
exist in the wx module. This way if somebody mistakenly uses
wx.EVT_TREE_ITEM_ACTIVATED instead of
the event will still be caught by
their handler because the event types will be equivalent.
Done. I used the existing events where applicable, and cutom events otherwise.
For other constants and such in the module that are for internal use
only, it would be nice to rename them with a leading underscore so
epydoc won't make an entry for them in the document.
Done.
Is there a way to toggle check or radio items with the keyboard?
Yes, now there is. You can press the space bar to toggle/untoggle the
check or radio items. I hope this is what you intended.
Mac there is a bug where the cursor keys are not reporting their WXK_
values in the EVT_CHAR event. You should use EVT_KEY_DWN instead.
Done.
Mac doesn't support user-dash pens very well. A better default may be a
solid line, with a lighter grey colour.
, I made a switch for the Mac: by default, it now uses a continuous
medium grey pen, while on MSW and GTK it still uses the user-dash pen.
In Your Docstrings And Comments The Every Word Is Capitalized Style Is
Difficult To Read. :-)
Done. Sorry for that.
For consistency with the other events EVT_TREE_ITEM_CHECK should
probably be EVT_TREE_ITEM_CHECKED.
Done.
You can find the source, demo and documentation in the usual place:
#customtree
, if you prefer in italian:
#customtree
I guess that's it for now. again Andrea you've amazed us all!
Thank you :-)
No.21 | | 1806 bytes |
| 
Hello NG,
just an update about the newest version of CustomTreeCtrl (0.7),
which can be found in the usual places:
#customtree
, if you prefer in italian:
#customtree
This update fixes some typos in the docstrings and other problems
identified by John Jackson:
1) GetItemFont returns now wx.NullFont instead of None if an item does
not have a font assigned;
2) Added a new method SetItemItalic (with his companion IsItalic);
3) Fix for a bug in GetNextVisible();
About the following problem:
<John Jackson>
>I have been able to reproduce the problem on Windows. It happens if
>you hide the root, and set both the style and the ctstyle to include
>wx.TR_HIDE_RT.
>Perhaps you can get rid of the ctstyle and just use a single style.
You should not do something like this. The "style" parameter is
reserved for the underlying wx.ScrolledWindow, while "ctstyle" is for
the TreeCtrl itself. Using a single style and setting up the things as
in the demo:
style=wx.SUNKEN_BRDER|CT.TR_HAS_BUTTNS|CT.TR_HAS_V ARIABLE_RW_HEIGHT
Will result in a clashing of styles between the tree and the
scrolledwindow, and you will experience the problem you exposed. Plus,
the Window style for the scrolledwindow is interfering with the tree
style. Just use the ctstyle parameter as it is, without setting the
style parameter if you are happy with the default behaviour of
wx.ScrolledWindow.
Andrea.
"Imagination Is The Weapon In The War Against Reality."
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.22 | | 497 bytes |
| 
Andrea Gavana wrote:
Hello NG,
just an update about the newest version of CustomTreeCtrl (0.7),
_drawingfunction = wx.RendererNative.Get().DrawTreeItemButton
At least wxGTK will have a problem with getting the renderer before the
App object is created. You should move this into a function that is
executed later, such as when the first CustomTreeCtrl is created. (And
I'll add code that raises an exception if Get is called before the app
object exists.)
No.23 | | 1488 bytes |
| 
May 26, 2006, at 2:48 AM, Andrea Gavana wrote:
About the following problem:
>
><John Jackson>
>I have been able to reproduce the problem on Windows. It happens if
>you hide the root, and set both the style and the ctstyle to include
>wx.TR_HIDE_RT.
>Perhaps you can get rid of the ctstyle and just use a single style.
>
You should not do something like this. The "style" parameter is
reserved for the underlying wx.ScrolledWindow, while "ctstyle" is for
the TreeCtrl itself. Using a single style and setting up the things as
in the demo:
style=wx.SUNKEN_BRDER|CT.TR_HAS_BUTTNS|CT.TR_HAS_V ARIABLE_RW_HEIGHT
Will result in a clashing of styles between the tree and the
scrolledwindow, and you will experience the problem you exposed. Plus,
the Window style for the scrolledwindow is interfering with the tree
style. Just use the ctstyle parameter as it is, without setting the
style parameter if you are happy with the default behaviour of
wx.ScrolledWindow.
Andrea,
If I use
self.tree = CT.CustomTreeCtrl(self, -1, ctstyle=wx.TR_HIDE_RT)
then I still see the problem on both Windows and Mac S X: the scroll
bar set incorrectly.
John Jackson
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.24 | | 1083 bytes |
| 
Hello Robin,
At least wxGTK will have a problem with getting the renderer before the
App object is created. You should move this into a function that is
executed later, such as when the first CustomTreeCtrl is created.
Thanks, I didn't know that now it's fixed. I have put that call
inside the CustomTreeCtrl __init__ function.
(And
I'll add code that raises an exception if Get is called before the app
object exists.)
Mhm, I am not sure it is necessaryCustomTreeCtrl is a subclass of
wx.ScrolledWindow: if the app doesn't exist, no way to initialize a
wx.ScrolledWindow. In order to call the __init__ function, the app is
required to exist unless I am missing something here, as usual.
Thank you for your bug reports and the suggestions!
Andrea.
"Imagination Is The Weapon In The War Against Reality."
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.25 | | 753 bytes |
| 
Hello John,
If I use
self.tree = CT.CustomTreeCtrl(self, -1, ctstyle=wx.TR_HIDE_RT)
then I still see the problem on both Windows and Mac S X: the scroll
bar set incorrectly.
you are right, thanks for pointing this out. . I was calling twice
a recursive function when the style was TR_HIDE_RT, so the scrollbar
calculations were wrong. Could you please try the newer version
(downloadable from my website)? I have just uploaded it
Thank you.
Andrea.
"Imagination Is The Weapon In The War Against Reality."
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.26 | | 942 bytes |
| 
Yes! It works just fine now.
Thanks!
May 26, 2006, at 1:05 PM, Andrea Gavana wrote:
Hello John,
>
>If I use
>>
>self.tree = CT.CustomTreeCtrl(self, -1,
>ctstyle=wx.TR_HIDE_RT)
>>
>then I still see the problem on both Windows and Mac S X: the scroll
>bar set incorrectly.
>
you are right, thanks for pointing this out. . I was calling twice
a recursive function when the style was TR_HIDE_RT, so the scrollbar
calculations were wrong. Could you please try the newer version
(downloadable from my website)? I have just uploaded it
Thank you.
Andrea.
John Jackson
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.27 | | 635 bytes |
| 
Andrea Gavana wrote:
>(And
>I'll add code that raises an exception if Get is called before the app
>object exists.)
Mhm, I am not sure it is necessaryCustomTreeCtrl is a subclass of
wx.ScrolledWindow: if the app doesn't exist, no way to initialize a
wx.ScrolledWindow. In order to call the __init__ function, the app is
required to exist unless I am missing something here, as usual.
Right, but if I had been generating an exception there before then I
wouldn't have needed to tell you that it was a problem, the exception
would have told you. ;-)