I have a menu containing several items, all with accelerator shortcuts defined using the tab character convenience method. Like this:
Increase volume\tCtrl+Up
So far so good. However, two of my accelerators use the shortcusts Ctrl+Left and Ctrl+Right, respectively. My problem is that while focused on a TextCtrl, those shortcuts already have an expected function - in text fields, Ctrl+Left and Ctrl+Right should navigate by word. The majority of my users will utilise the keyboard very heavily so it's key that these functions work as expected.
So far, I've worked out that I can intercept all keys before they're processed for accelerator usage by binding a handler for wxEVT_CHAR_HOOK. But I'm not quite sure how to precede from that point. I want to define a set of shortcuts that should be passed through to the TextCtrl, but allow other accelerators to be processed normally if they don't have a TextCtrl-specific function. For instance, Ctrl+Left and Ctrl+Right should be processed by the TextCtrl because they navigate by word, but Ctrl+O should trigger its associated menu command because the TextCtrl has no use for that particular shortcut.
Changing the shortcuts (e.g. to Alt+Left instead of Ctrl+Left) isn't an option here as the application allows the users to interactively change the accelerators. Disabling the problematic menu items when a TextCtrl has focus also won't work, because the associated accelerator shortcuts still don't carry out their intended functions inside the TextCtrl (i.e. disabling the menu item with accelerator Ctrl+Left doesn't magically make the TextCtrl process that key combination properly). The latter point seems like a bug in wx, but it is how it is.
If you're encountering this problem under Windows, overriding wxWindow::MSWShouldPreProcessMessage()
and returning false for the key combinations in question should fix it. This is, however, a C++-only solution, I don't know if even wxPhoenix provides a way to override virtual methods from Python (and almost certain that classic wxPython does not).
Arguably, the library version in wxTextCtrl::MSWShouldPreProcessMessage()
should be already doing this, so perhaps you could modify wxWidgets itself (and submit a patch with your changes to not have to maintain them yourself).