Frank Millman wrote:
I wanted to use keyboard shortcuts for the two icons. As far as I can tell,
you cannot do this without adding a menu bar, but I found a neat (ugly?)
solution. I created two wxButtons, set up event handlers to invoke the same
methods as the icons, and positioned them at (1000,1000), which is off the
screen so they are invisible. I created an Accelerator Table to set up the
shortcuts - Alt-P and Alt-N.
There is no need for the buttons. Using a wxAcceleratorTable will deliver EVT_MENU events even if there is no menu. Just adding the following in MyToolBar.__init__ is enough:
EVT_MENU(panel, prev_id, panel.grid.OnPrev)
EVT_MENU(panel, next_id, panel.grid.OnNext)
So far so good. However, I also use a grid cell editor, so pressing Alt-P or
Alt-N gets processed by the editor first. This is where the problem arose. I
traced the problem to the following method.
def IsAcceptedKey(self, evt):
if sys.platform == 'win32':
return (not (evt.ControlDown() or evt.AltDown()) and
evt.GetKeyCode() != WXK_SHIFT)
else:
return evt.GetKeyCode() not in (WXK_SHIFT, WXK_ALT, WXK_CONTROL)
You will see that I use different routines for MSW and GTK2 - this is my
workaround. Without it, the first routine causes GTK2 to crash with a
segmentation fault, and the second routine causes MSW to crash with
'Python.exe has generated errors and will be closed by Windows'. If I omit
the method altogether, GTK2 still crashes, but MSW works ok without it.
Both work okay without it for me.
On both platforms, the crash occurs inside the NewPage() routine, at the
point where it is appending rows. If I comment out the calls to NewPage(),
no errors occur.
Adding this to the begining of NewPage will probably help:
if self.IsCellEditControlEnabled():
self.DisableCellEditControl()
An afterthought - it is possible that the problem is caused not by the
different platforms, but by the different versions of wxPython. You will see
above that I am using 2.4.0.2u on MSW, and 2.4.1.2u on GTK2. Can anyone
confirm this? If so, my workaround must test for the version instead of the
platform. What is the correct syntax for testing for 'version < x'? I seem
to recall a recent discussion about getting at the underlying components of
the version number.
Before 2.4.1.2 the only thing available with all version components is the wxPython.wx.__version__ string. Starting with 2.4.1.2 you also have a wxVERSION tuple and a wxVERSION_STRING string.
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!