wx.AcceleratorTable with a dialog in GTK

I am writing a small barcode / stock app that will run on Linux (Ubuntu and Raspbian).

My barcode scanner emulates a keyboard and can be configured to include a ‘header’ code that is sent prior to the decoded barcode numbers.

I would like to capture this ‘keyboard’ input no matter which control has focus. Initially, I had this working well using a wx.EVT_CHAR_HOOK event in the main application window, but actually I would like to scan the code in a dialog and / or a wizard.

Since, I have read that using wx.EVT_CHAR_HOOK is not encouraged and wx.AcceleratorTable should be used instead.

I have tried to set up an accelerator event using the following code in the dialog’s init method.

    randomId = wx.NewId()
    accel = wx.AcceleratorTable([(wx.ACCEL_CTRL,  ord('Q'),  randomId)])
    self.SetAcceleratorTable(accel)

    self.Bind(wx.EVT_MENU,  self.OnKeyCombo,  id=randomId)

``

The event handler is simply:

def OnKeyCombo(self, event):
    """"""
    print ("You pressed CTRL+Q!")

``

If I put the same code in the main frame, then it works as expected.

Is it possible to use wx.AcceleratorTable with a dialog on GTK? The note in the documentation https://wxpython.org/Phoenix/docs/html/wx.AcceleratorTable.html suggests that it should be okay.

Iwbnwif Yiw wrote:

I am writing a small barcode / stock app that will run on Linux
(Ubuntu and Raspbian).

My barcode scanner emulates a keyboard and can be configured to
include a 'header' code that is sent prior to the decoded barcode numbers.

I would like to capture this 'keyboard' input no matter which control
has focus. Initially, I had this working well using a wx.EVT_CHAR_HOOK
event in the main application window, but actually I would like to
scan the code in a dialog and / or a wizard.

Since, I have read that using wx.EVT_CHAR_HOOK is not encouraged and
wx.AcceleratorTable should be used instead.

If you have something working, why would you bother to change it? Even
if wx.AcceleratorTable is prettier, wx.EVT_CHAR_HOOK works, and will
continue to work.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Unfortunately, neither wx.EVT_CHAR_HOOK nor wx.AcceleratorTable work in a dialog, and I want to scan in dialog. What seems to be even more of a problem is that they don’t even work in a wx.Frame that has been opened from a dialog.

···

On Wednesday, October 11, 2017 at 6:47:16 PM UTC+1, Tim Roberts wrote:

If you have something working, why would you bother to change it? Even

if wx.AcceleratorTable is prettier, wx.EVT_CHAR_HOOK works, and will

continue to work.