Context menus in HyperTreeList

22 views
Skip to first unread message

cool-RR

unread,
Sep 25, 2010, 7:18:41 AM9/25/10
to wxPython-users, andrea...@gmail.com
Hello,

I'm using the HyperListCtrl widget and I ran into some problems
regarding context menus.

First I will describe how I'd expect the context menus on
HyperListCtrl to behave, so it'll be easier to know whether I'm
getting a bug or that the problem is in my expectations. (Probably I'm
misunderstanding how it's supposed to work, so please correct me.)

I expect to be able to raise a context menu in the HyperListCtrl. That
context menu may be associated with a tree item (right-clicking on a
tree item) or not (right-clicking in empty space.)

I expect to be able to raise the context menu either by:
1. Right-clicking, or
2. Pressing the menu key or Shift-F10 on Windows and Linux, or
3. Pressing the Mac shortcut on Mac. (I think it's Function+Ctrl+5,
not sure.)

(By the way, Andrea, I think you should replace the line:
elif keyCode == wx.WXK_MENU:
with this line
elif keyCode in (wx.WXK_MENU, wx.WXK_WINDOWS_MENU):
Not sure about it though, correct me if I'm wrong.)

I saw that in `customtreectrl.py` there is an event called
`EVT_TREE_ITEM_MENU`, with a description: "The context menu for the
selected item has been requested, either by a right click or by using
the menu key."

So I expect that I simply need to bind to this event in my
HyperListCtrl subclass, and in the handler I could get the item for
which the context menu was requested by using `event.GetItem()`. And I
bind `EVT_CONTEXT_MENU` to the method which raises the generic context
menu.

But it seems not to work that way. Look at this runnable sample:

http://gist.github.com/596745

Here are the problems:
* Right-clicking either on the items or in the free space doesn't do
anything. It doesn't raise neither an `EVT_TREE_ITEM_MENU` nor an
`EVT_CONTEXT_MENU`.
* Pressing the menu key / Shift-F10, either with an item selected or
not, raises `EVT_CONTEXT_MENU`.

Please tell me what I'm getting wrong.


Ram.

Noethys

unread,
Sep 25, 2010, 1:11:29 PM9/25/10
to wxPython-users
Hi

Try :

self.hypertreelist.Bind(...)

instead of

self.Bind(...)

Bye

cool-RR

unread,
Sep 25, 2010, 1:25:54 PM9/25/10
to wxPython-users
Thanks Noethys, that was a mistake on my part and I now updated the
sample to do `self.hypertreelist.Bind`. However, this doesn't solve
the problems, they happen exactly the same way after this fix.


Ram.

Noethys

unread,
Sep 26, 2010, 4:13:03 AM9/26/10
to wxPython-users
and with :

self.hypertreelist.GetMainWindow().Bind(...)

cool-RR

unread,
Sep 26, 2010, 7:01:13 AM9/26/10
to wxPython-users
Tried it, doesn't change anything. (Didn't add to online sample.)


Ram.

cool-RR

unread,
Oct 1, 2010, 9:57:10 AM10/1/10
to wxPython-users
Anyone has any idea about this?


Ram.

Stefano Bartaletti

unread,
Oct 1, 2010, 10:06:38 AM10/1/10
to wxpytho...@googlegroups.com
If I remember correctly this shoudl work (did it long time ago, should inspect
my sources):

self.hypertreelist.GetMainWindow().Bind(wx.EVT_RIGHT_UP, <your function>)

--
Enjoy freedom!

http://www.debian.org

cool-RR

unread,
Oct 1, 2010, 10:09:28 AM10/1/10
to wxPython-users
On Oct 1, 4:06 pm, Stefano Bartaletti <stefano.bartale...@gmail.com>
wrote:
`EVT_RIGHT_UP` is problematic because a context menu can be raised
also with the keyboard using the menu key or Shift-F10. Also, I'd
expect to get the item directly in the event, which I think
`EVT_RIGHT_UP` doesn't provide. (I know I can get it easily with
`HitTest`, I'll do that if I have to, but I assume that's
HyperTreeList's responsibility.)


Ram.

cool-RR

unread,
Oct 2, 2010, 11:45:54 AM10/2/10
to wxPython-users
Never mind, I created my own subclass of HyperTreeList that hacks
around the problem.


Ram.
Reply all
Reply to author
Forward
0 new messages