hi all.
I have a frame with no menu to give you the choice to destroy the frame pressing ESC.
Is it possible do that?
what is the event associated with the frame (wx.EVT_…?):
class LoadCal(wx.Frame):
def init (self,parent,posxy):
wx.Frame.init (self,parent,-1,‘cal’,size=(190,140))
self.SetFont(wx.Font(8,wx.SWISS,wx.NORMAL,wx.NORMAL,False))
self.Bind(wx.calendar.EVT_CALENDAR, self.OnCalSelected, id=cal.GetId())
self.Bind(wx.EVT_?.., self.OnEventX)
def OnEventX(self, evt):
if evt.GetKeyCode() == wx.WXK_ESCAPE: #
self.Destroy()
···
–
Fabio Spadaro
www.fabiospadaro.com
Cody
December 9, 2009, 5:02pm
4
Hi,
But I do not use menu ...
You don't need a menu to use an AcceleratorTable.
example:
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Test",
style=wx.DEFAULT_FRAME_STYLE)
self._panel = wx.Panel(self)
self._tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('q'),
wx.ID_CLOSE)])
self.SetAcceleratorTable(self._tbl)
self.Bind(wx.EVT_MENU, self.OnAccel, id=wx.ID_CLOSE)
def OnAccel(self, evt):
print "HELLO"
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()
Regards,
Cody
(p.s please don't top post)
···
On Wed, Dec 9, 2009 at 10:38 AM, Fabio Spadaro <fabiolinospad@gmail.com> wrote:
Robin
December 9, 2009, 8:28pm
5
I'm not sure if it was fixed before or after the current release, but there was a bug on Windows where the accelerator table would not work if there wasn't a menubar on the frame.
···
On 12/9/09 9:02 AM, Cody Precord wrote:
Hi,
On Wed, Dec 9, 2009 at 10:38 AM, Fabio Spadaro<fabiolinospad@gmail.com> wrote:
But I do not use menu ...
You don't need a menu to use an AcceleratorTable.
--
Robin Dunn
Software Craftsman
Cody
December 9, 2009, 8:38pm
6
Hi,
Hi,
But I do not use menu ...
You don't need a menu to use an AcceleratorTable.
I'm not sure if it was fixed before or after the current release, but
there was a bug on Windows where the accelerator table would not work if
there wasn't a menubar on the frame.
Looks like it was fixed quite sometime ago
(wxTrac has been migrated to GitHub Issues - wxWidgets ) works fine on 2.8.10 for me.
Escape does not seem to work on Windows though using this approach.
Using EVT_CHAR_HOOK does work though.
self.Bind(wx.EVT_CHAR_HOOK, self.OnHook)
def OnHook(self, evt):
if evt.GetKeyCode() == wx.WXK_ESCAPE:
print "ESCAPED"
else:
evt.Skip()
Cody
···
On Wed, Dec 9, 2009 at 2:28 PM, Robin Dunn <robin@alldunn.com> wrote:
On 12/9/09 9:02 AM, Cody Precord wrote:
On Wed, Dec 9, 2009 at 10:38 AM, Fabio Spadaro<fabiolinospad@gmail.com> wrote:
your example does wotk but I would like to work with wx.WXK_ESCAPE instead ctrl-Q.
is it possible?
···
2009/12/9 Cody Precord codyprecord@gmail.com
Hi,
On Wed, Dec 9, 2009 at 10:38 AM, Fabio Spadaro fabiolinospad@gmail.com wrote:
But I do not use menu …
You don’t need a menu to use an AcceleratorTable.
example:
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Test",
style=wx.DEFAULT_FRAME_STYLE)
self._panel = wx.Panel(self)
self._tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('q'),
wx.ID_CLOSE)])
self.SetAcceleratorTable(self._tbl)
self.Bind(wx.EVT_MENU, self.OnAccel, id=wx.ID_CLOSE)
def OnAccel(self, evt):
print "HELLO"
if name == “main ”:
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()
Regards,
Cody
(p.s please don’t top post)
–
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
–
Fabio Spadaro
www.fabiospadaro.com
Hi.
Using EVT_CHAR_HOOK it does work.
Thanks
···
2009/12/9 Cody Precord codyprecord@gmail.com
Hi,
On Wed, Dec 9, 2009 at 2:28 PM, Robin Dunn robin@alldunn.com wrote:
On 12/9/09 9:02 AM, Cody Precord wrote:
Hi,
On Wed, Dec 9, 2009 at 10:38 AM, Fabio Spadarofabiolinospad@gmail.com wrote:
But I do not use menu …
You don’t need a menu to use an AcceleratorTable.
I’m not sure if it was fixed before or after the current release, but
there was a bug on Windows where the accelerator table would not work if
there wasn’t a menubar on the frame.
Looks like it was fixed quite sometime ago
(http://trac.wxwidgets.org/ticket/9784 ) works fine on 2.8.10 for me.
Escape does not seem to work on Windows though using this approach.
Using EVT_CHAR_HOOK does work though.
self.Bind(wx.EVT_CHAR_HOOK, self.OnHook)
def OnHook(self, evt):
if evt.GetKeyCode() == wx.WXK_ESCAPE:
print “ESCAPED”
else:
evt.Skip()
Cody
–
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
–
Fabio Spadaro
www.fabiospadaro.com