From: Tim Z. <ti...@cc...> - 2005-01-13 00:29:49
|
Hi All, I have just started using PythonCard. I've run into a problem creating a context menu for a text field. The context menu works for other widgets, but when trying it on a text field the standard text context menu overrides my custom one! Is there any way to stop the standard context menu overriding my events? This is the code i have so far ------------------------------ from PythonCard import model import wx, wxPython class MyBackground(model.Background): def on_initialize(self, event): # if you have any initialization # including sizer setup, do it here self.initContextMenu() self.tar = event.target self.allowedContextClick = ['txtTest'] #wx.EVT_RIGHT_UP(self, self.OnRightUp) def initContextMenu(self): self.popup = wx.Menu() mID = wx.NewId() self.popup.Append(mID, 'Test menu item 1', '') wx.EVT_MENU(self, mID, self.on_testMenu_command) def on_testMenu_command(self, event): widget = self.findFocus() print widget.name #def on_txtTest_mouseDown(self, event): # self.PopupMenu(self.popup, event.position) def isAllowedContextClick(self, obj): if obj in self.allowedContextClick: return 1 else: return 0 def on_mouseContextUp(self, event): if self.isAllowedContextClick(event.target.name): x, y = event.target.position pos = x, y+25 self.PopupMenu(self.popup, pos) #event.Skip() if __name__ == '__main__': app = model.Application(MyBackground) app.MainLoop() ---------------------- Thanks Tim Zegir |