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

54 views
Skip to first unread message

Nathan smith

unread,
Jan 22, 2024, 6:52:01 AMJan 22
to wxpytho...@googlegroups.com
Hi Group,


I'm not sure how to explain this one, so please bare with me a little as
I will be talking from a blind person's perspective using a screen reader.

I have two panels, one of which has a wx.TextCtrl on it with a menu bar.

When I press the alt key with nothing else, it opens up the top menu and
allows me to navigate between menus using my arrow keys.


On my second panel I have a wx.Grid which is inside a sizer  and create
a menu bar with the exact same code, bar changes for menu names and
bound functions.

When I do alt with a letter, IE alt f, it goes to the menu I select. If
I press alt on its own, nothing happens.


I've tried binding it through an accelerator table, too but it doesn't
even trigger the event, before I get any more down potentially the wrong
path, could one of you fine folk indicate to me if I've missed something
here?


thanks in advance,

Nathan

Dietmar Schwertberger

unread,
Jan 22, 2024, 1:56:06 PMJan 22
to wxpytho...@googlegroups.com
Hi Nathan,

personally, I'm most of the time using EVT_CHAR_HOOK instead of
accelerators.
I found this easier to customize. But honestly, I don't know whether
this could be used for handling ALT.

From your description I found it a bit hard to follow. Are the two
panels in one frame and the accelerator set for the frame?
A stripped down code sample would be good.

Is the menu a workaround for the lack of accessibility support in wxGrid?
I'm working on adding some support. Of course this will then take some
time until it finds its way from wxWidgets into wxPython.

Regards,

Dietmar

Dietmar Schwertberger

unread,
Jan 24, 2024, 2:02:28 PMJan 24
to Nathan smith, wxpytho...@googlegroups.com
Hi Nathan,

when I wrote "code sample", I meant a sample that's actually runnable to
show the problem.
But from the snippets I could see that the menus are not shown a the
same time. That helped.
I have create a small sample of a frame with a menu, a panel and either
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
they show the same difference.

The menu bars get activated in both cases. I can see that the menu
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
to the menu bar, so I can't navigate. So, for example, even when I press
Escape, the underlines do remain.

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

As workaround, I have bound EVT_CHAR_HOOK and that can catch the ALT key
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
will then trigger the menu.
But when you close the menu, the focus will not be transfered back to
the grid automatically.
Maybe it would be possible to handle an event when the menu is closed
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):
    if event.GetKeyCode()==wx.WXK_ALT and event.GetModifiers()==wx.MOD_ALT:
        self.frame_menubar.GetParent().SetFocus()
    event.Skip()


Regards,

Dietmar

Dietmar Schwertberger

unread,
Jan 24, 2024, 3:58:39 PMJan 24
to wxpytho...@googlegroups.com
wxWidgets bug report and pull request are online:

https://github.com/wxWidgets/wxWidgets/issues/24246
https://github.com/wxWidgets/wxWidgets/pull/24247

Unfortunately, I could not find a pure wxPython workaround for the time
until it's fixed in the builds.

Regards,

Dietmar

Reply all
Reply to author
Forward
0 new messages