question about wxpython CtrlList event binder: wx.EVT_LIST_ITEM_RIGHT_CLICK

K

Kent

Hi there,

I wrote a desktop application with wxPython2.8. And got a problem.
Hope here someone can give some hint. Thanks in advance.

There was a ListCtrl (lc) in my GUI, and it was a bit long, so that
there would be some blank space below ("empty area") in case there
were only a few items.

I bind a function on the event wx.EVT_LIST_ITEM_RIGHT_CLICK, when user
rightclick on the lc item, my function was triggered, and open a popup
menu.

Depends on the item user clicked, the menu items can be different. I
checked the event.getData(), to decide which menu item will show to
user. That is, if user right click on the "empty area", the
event.getData() will be 0. I wrote the appl. under Linux, and tested,
it worked as what I expected.

However, today someone reported a bug, said, under Windows XP, right
clicking on the items of lc, it works fine, but if on the "empty area"
of the lc, nothing happened, no popup menu. I tested under WINXP, the
function was not triggered at all when I right-clicked on the "empty
area".

I tried to bind wx.EVT_RIGHT_DOWN(UP) to the lc, but the function
cannot be triggered under Linux. any suggestion?

Thanks

regards,

Kent
 
M

Mike Driscoll

Hi there,

I wrote a desktop application with wxPython2.8. And got a problem.
Hope here someone can give some hint. Thanks in advance.

I recommend joining the wxPython mailing list and posting there. The
guys there are great and can probably help you out. See
http://wxpython.org/maillist.php

There was a ListCtrl (lc) in my GUI, and it was a bit long, so that
there would be some blank space below ("empty area") in case there
were only a few items.

I bind a function on the event wx.EVT_LIST_ITEM_RIGHT_CLICK, when user
rightclick on the lc item, my function was triggered, and open a popup
menu.

Depends on the item user clicked, the menu items can be different. I
checked the event.getData(), to decide which menu item will show to
user. That is, if user right click on the "empty area", the
event.getData() will be 0. I wrote the appl. under Linux, and tested,
it worked as what I expected.

However, today someone reported a bug, said, under Windows XP, right
clicking on the items of lc, it works fine, but if on the "empty area"
of the lc, nothing happened, no popup menu. I tested under WINXP, the
function was not triggered at all when I right-clicked on the "empty
area".

I tried to bind wx.EVT_RIGHT_DOWN(UP) to the lc, but the function
cannot be triggered under Linux.  any suggestion?

Thanks

regards,

Kent

If you join the wxPython list, they'll probably ask for a small
runnable sample. Here's some instructions for how to do that:
http://wiki.wxpython.org/MakingSampleApps

It would be good to know what mode you are using for your ListCtrl.
List view, report, icon or what? The demo doesn't have any white space
at the end, so I can't test this easily. Are you using a sizer to hold
the widget?

- Mike
 
K

Kent

Hi Mike,

thx for the wxpython maillist link, I will give it a shot. But I would
like to paste the code snippet here as well, hope it can tell
sufficient information. (I added some comments in the class. ) Thank
you.

class TagListCtrl(wx.ListCtrl):
'''
Tag list ListCtrl widget
'''

def __init__(self,parent,id):
# this 'images' is not important, just icons
images = (myGui.ICON_TAG_CUSTOM,
myGui.ICON_TAG_ALL,myGui.ICON_TAG_SEARCH, myGui.ICON_TAG_TRASH,
myGui.ICON_TAG_FAV)

# so the listctrl is in REPORT MODE
wx.ListCtrl.__init__(self,parent,id,style=wx.LC_REPORT|
wx.LC_HRULES| wx.LC_SINGLE_SEL)


#here are some property value init..
self.SetName(myGui.TAG_LIST_NAME)
self.parent = parent
self.mainFrm = self.GetTopLevelParent() # main Frame
il = wx.ImageList(24,24)
for image in images:
il.Add(wx.Bitmap(image,wx.BITMAP_TYPE_PNG))

self.InsertColumn(0,'Tags')
self.AssignImageList(il,wx.IMAGE_LIST_SMALL)

#popup menu
self.popmenu = None

# bind the events
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelect) #selected,
e.g. left click

self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onTagMgmt,self)
# right click, HERE COMES THE PROBLEM

#this function load the item data into the List
self.loadTags()


#this is the function
def onTagMgmt(self,event):
tagId = event.GetData()
# following codes are omitted. just some business logic stuff.
checking the tagId, making decision of showing popup menu items...




Kent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top