Re: wx.grid.Grid v.s.s Menu Bars

Dietmar Schwertberger <[email protected]> Wed, 24 Jan 2024 20:02:19 +0100
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
Hi Nathan,

when I wrote "code sample", I meant a sample that's actually runnable to=20
show the problem.
But from the snippets I could see that the menus are not shown a the=20
same time. That helped.
I have create a small sample of a frame with a menu, a panel and either=20
a text or a grid control or both.

The samples actually behave different in the way that you described.
I have also checked two C++ samples from the wxWidgets repository and=20
they show the same difference.

The menu bars get activated in both cases. I can see that the menu=20
access keys are underlined after the first Alt key press.
But when the grid has the focus, no further keys presses seem to be sent=20
to the menu bar, so I can't navigate. So, for example, even when I press=20
Escape, the underlines do remain.

I will check whether I can fix the wxWidgets bug, but it takes time=20
until a fix propagates into wxPython.

As workaround, I have bound EVT_CHAR_HOOK and that can catch the ALT key=20
for the grid.
Unfortunately, I don't see a quick way to transfer the focus to the MenuBar=
.
It's possible to set focus to the frame from the event handler and this=20
will then trigger the menu.
But when you close the menu, the focus will not be transfered back to=20
the grid automatically.
Maybe it would be possible to handle an event when the menu is closed=20
and then set the focus again.

These are the code snippets:

self.grid_1.Bind(wx.EVT_CHAR_HOOK, self.evt_char_hook_grid)

def evt_char_hook_grid(self, event):
 =C2=A0=C2=A0=C2=A0 if event.GetKeyCode()=3D=3Dwx.WXK_ALT and event.GetModi=
fiers()=3D=3Dwx.MOD_ALT:
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 self.frame_menubar.GetParent().=
SetFocus()
 =C2=A0=C2=A0=C2=A0 event.Skip()


Regards,

Dietmar

--=20
You received this message because you are subscribed to the Google Groups "=
wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
wxpython-users/cc32f97b-5d8b-4735-aaf7-40e764cd9f93%40schwertberger.de.