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.