[wxpython-users] Accelerator table and wx.NewId(): bug ?
Mike Driscoll
mike at pythonlibrary.org
Sun Sep 7 13:05:47 PDT 2008
Hi Diego,
> Hi all.
>
> I just noticed that setting an entry in an accelerator table with a
> custom id (an id that doesn't belong to an existing menu item) doesn't
> work anymore in wxPython 2.8.8.1 (I tried it with some previous
> version and it worked):
>
> newId = wx.NewId()
> self.Bind(wx.EVT_MENU, self.OnCtrlQ, id=newId)
> acct = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord("q"), newId)])
> self.SetAcceleratorTable(acct)
>
> self.OnCtrlQ is never called (I tried all possible variations, such as
> using "Q", executing the code in __init__ or after the creation of all
> child controls, and so on).
>
> Is that a bug ? If not, is there a solution ?
> Thanks in advance, Diego.
>
>
I'm getting the exact same behavior unless I actually have a menu
instantiated. Uncomment the code below and it works (at least on WinXP,
Py2.5.2, wx 2.8.8.1)
<code>
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")
# Add a panel so it looks the correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
## menuBar = wx.MenuBar()
## fileMenu = wx.Menu()
## exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
## "Exit the application")
## menuBar.Append(fileMenu, "File")
## self.SetMenuBar(menuBar)
exitId = wx.NewId()
self.Bind(wx.EVT_MENU, self.onExit, id=exitId )
accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('Q'),
exitId )])
self.SetAcceleratorTable(accel_tbl)
def onExit(self, event):
print 'in onExit'
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
</code>
I'm not sure what the deal is...
-------------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org
More information about the wxpython-users
mailing list