First, thanks for answering my last question about
background images in panels.
My question is about popup menus. I'm trying to
implement a wxListCtrl and am using the demo code as a
starting point. The popup menu that appears has to be
variable in length, so the straightforward method used
in the demo won�t work. The problem is that I get a
wxCommandEvent when I select from the popup rather
then a wxMenuEvent. FYI, I'm using 2.3.2.1 because I'm
having troubles integrating anything newer with the
free odbc driver (which is really old).
The wxWindows help file states:
···
-----------
If the menu is part of a menubar, then wxMenuBar event
processing is used.
With a popup menu, there is a variety of ways to
handle a menu selection event
(wxEVT_COMMAND_MENU_SELECTED).
1) Derive a new class from wxMenu and define event
table entries using the EVT_MENU macro.
2) Set a new event handler for wxMenu, using an object
whose class has EVT_MENU entries.
3) Provide EVT_MENU handlers in the window which pops
up the menu, or in an ancestor of this window.
4) Define a callback of type wxFunction, which you
pass to the wxMenu constructor. The callback takes a
reference to the menu, and a reference to a
wxCommandEvent. This method is deprecated and should
not be used in the new code, it is provided for
backwards compatibility only.
-------------
I'm not exactly sure how to do this. Are they any code
samples that I could copy from? I've looked at the
archive and I can't find anything exactly like this.
Thanks, Seth.
--------
my code
--------
from wxPython.wx import *
from wxPython.lib.mixins.listctrl import
wxColumnSorterMixin
import images
class ListEdit(wxPanel, wxColumnSorterMixin):
...
def CreateControls(self):
tID = wxNewId()
self.list = wxListCtrl(self, tID,
style=wxLC_REPORT|wxSUNKEN_BORDER)
self.list.InsertColumn(0, "Name")
self.list.InsertColumn(1, "Link")
...
for x in range(len(items)):
key, data = items[x]
self.list.InsertStringItem(x, data[0])
self.list.SetStringItem(x, 1, data[1])
self.list.SetItemData(x, key)
self.list.SetColumnWidth(0, 200)
self.list.SetColumnWidth(1, 200)
EVT_RIGHT_DOWN(self.list, self.OnRightDown)
# for wxMSW
EVT_COMMAND_RIGHT_CLICK(self.list, tID,
self.OnRightClick)
# for wxGTK
EVT_RIGHT_UP(self.list, self.OnRightClick)
...
def OnRightDown(self, event):
self.x = event.GetX()
self.y = event.GetY()
event.Skip()
def OnRightClick(self, event):
menu = wxMenu()
for x in range(len(self.htrList)):
item = wxMenuItem(menu, x,
self.htrList[x])
menu.AppendItem(item)
EVT_MENU(self, x, self.OnPopup)
self.PopupMenu(menu, wxPoint(self.x, self.y))
menu.Destroy()
event.Skip()
def OnPopup(self, event):
#all of these print statements result in either 0,
null, or ""
print event # = wxCommandEvent
menuId = event.GetInt()
print menuId
menuId = event.GetString()
print menuId
menuId = event.GetClientData()
print menuId
menuId = event.GetExtraLong()
print menuId
# what I want to do is get an wxMenuEvent
# event.GetMenuId()
print "menuId =" + str(menuId)
htrText = self.htrList[menuId]
item = self.list.GetNextItem(-1,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)
print "item = " + str(item)
self.list.SetStringItem(item, 1, htrText)
self.list.SetItemData(item, menuId)
self.Refresh
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com