Help with accelerator table

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

Help with accelerator table

Belaala Toufik
Hello I need your help with this.
I want to control the three sliders objects in the attached file with accelertor table
for the volume slider I want to set the following shortcut .
f9 increase the volume level and f8 decrease the volume level
for the track slider I want to set the following shortcut .
ctrl + left arrow go backward and ctrl + right arrow go forward
and for the rate slider I want to set the following shortcut.
shift + ctrl + left arrow slow the rate and shift + ctrl + right arrow speed up .
It only works with the play button I set the shortcut to the space bar.
Any help please.

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

test_2.py (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Help with accelerator table

Dietmar Schwertberger-2
On 5/3/2018 7:22 PM, Belaala Toufik wrote:
> It only works with the play button I set the shortcut to the space bar.
> Any help please.

I don't think that an accelerator table can create anything else than
menu or button commands.

You could implement a handler for EVT_CHAR_HOOK and then
programmatically increase/decrease the slider values.

The handler for EVT_CHAR_HOOK will be called before EVT_KEY_DOWN, so
don't forget to call event.Skip() for any key combination that you don't
handle.


Regards,

Dietmar


--
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: Help with accelerator table

Dietmar Schwertberger-2
P.S.: You need to bind the handler for the panel or frame, not the controls.

So e.g.

class MainPanel(wx.Panel):
     def __init__(self, parent):
         wx.Panel.__init__(self,parent)
         self.Bind(wx.EVT_CHAR_HOOK, self.on_char)


--
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: Help with accelerator table

Belaala Toufik
Hello .
Thanks for your reply can you give me full example please I don't understand wx very well.


بتاريخ الخميس، 3 مايو، 2018 7:01:00 م UTC+1، كتب Dietmar Schwertberger:
P.S.: You need to bind the handler for the panel or frame, not the controls.

So e.g.

class MainPanel(wx.Panel):
     def __init__(self, parent):
         wx.Panel.__init__(self,parent)
         self.Bind(wx.EVT_CHAR_HOOK, self.on_char)


--
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: Help with accelerator table

Dietmar Schwertberger-2
On 5/4/2018 12:07 PM, Belaala Toufik wrote:
Hello .
Thanks for your reply can you give me full example please I don't understand wx very well.

Indeed, it seems that there's no good example online.

Please find attached your updated example file to handle: "shift + ctrl + right arrow -> increase rate".

The relevant change:

class MainPanel(wx.Panel):
    def __init__(self, parent):
        ...
        self.Bind(wx.EVT_CHAR_HOOK, self.on_char)

    def on_char(self, event):
        if event.ShiftDown() and event.ControlDown() and event.GetKeyCode()==wx.WXK_RIGHT:
            # shift + ctrl + right arrow -> increase rate
            self.rate.SetValue( self.rate.GetValue() + 1 )
        else:
            # don't handle
            event.Skip()


Regards,
Dietmar

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

test_2.py (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Help with accelerator table

Tim Roberts
In reply to this post by Belaala Toufik
Belaala Toufik wrote:

>
> I want to control the three sliders objects in the attached file with
> accelertor table
> for the volume slider I want to set the following shortcut .
> f9 increase the volume level and f8 decrease the volume level
> for the track slider I want to set the following shortcut .
> ctrl + left arrow go backward and ctrl + right arrow go forward
> and for the rate slider I want to set the following shortcut.
> shift + ctrl + left arrow slow the rate and shift + ctrl + right arrow
> speed up .
> It only works with the play button I set the shortcut to the space bar.

Well, what have you tried?  You clearly have the example of the space
bar to show how this is done.  From that example, you ought to be able
to make up the rest of the accelerator table entries.

However, you have to think about what you're doing.  You cannot just
have your accelerator entries call the same handler as the sliders.  The
two events generate different event objects.  Your onVolume handler, for
example, fetches the new volume value from self.volume, but when your
accelerator key fires, that number will not have changed.  Your
accelerator key for F8 and F9 will need to fetch and adjust the current
volume value, like:

    newvol = self.currentVolume + 1
    if newvol < 100:
        self.currentVolume = newvol
        self.media.SetVolume( newvol / 100.0 )
        self.volume.SetValue( newvol )

You can either send the F8 and F9 events to different handlers, or use
the same handler and use event.GetInt() to notice which one you got.   
And since you'll be using those last three lines in several places, you
might consider adding a "def SetVolume( self, xxx )" method so you don't
repeat yourself.

None of what you've asked is very hard, but you shouldn't be asking us
to write it for you.  You have everything you need.

--
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: Help with accelerator table

Tim Roberts
In reply to this post by Dietmar Schwertberger-2
Dietmar Schwertberger wrote:

> On 5/4/2018 12:07 PM, Belaala Toufik wrote:
>> Hello .
>> Thanks for your reply can you give me full example please I don't
>> understand wx very well.
>
> Indeed, it seems that there's no good example online.
>
> Please find attached your updated example file to handle: "shift +
> ctrl + right arrow -> increase rate".
>

Although your method can be made to work, it can also be done with an
accelerator table.  The accelerator entries end up firing wx.EVT_MENU
events, but those work perfectly well even if you don't actually have a
menu.

I tend to think of character hooks as a last resort, when more normal
methods of handling don't work.  I suppose it is personal preference.

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