wx.AcceleratorTable with a dialog in GTK

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

wx.AcceleratorTable with a dialog in GTK

Iwbnwif Yiw
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.

--
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 email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.AcceleratorTable with a dialog in GTK

Tim Roberts
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, [hidden email]
Providenza & Boekelheide, Inc.

--
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 email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.AcceleratorTable with a dialog in GTK

Iwbnwif Yiw
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.

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. 

--
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 email to [hidden email].
For more options, visit https://groups.google.com/d/optout.