Keybind with arguments

  • phillc54
  • phillc54's Avatar Topic Author
  • Away
  • Platinum Member
  • Platinum Member
More
22 Jan 2020 09:49 #155414 by phillc54
Keybind with arguments was created by phillc54
Is it possible to pass arguments to a keybind function.
Rather than having multiple functions for say 0~8 I would like to call one function and pass the number as the argument.

Please Log in or Create an account to join the conversation.

More
22 Jan 2020 10:16 #155416 by cmorley
Replied by cmorley on topic Keybind with arguments
Not currently unless you code keybinding yourself, but I think I could add that to qtvcp's stock key binding library.

I'm thinking you call a function to register a dict of keys:values and a function name.
something like :

klist ={'Key_0':0,'Key_1':1}
KEYBIND.add_function_keylist(klist, 'on_keycall_custom')

and the function would be:
def on_keycall_custom(self,event,state,shift,cntrl,value):

Is that sorta what you are thinking?

Chris

Please Log in or Create an account to join the conversation.

  • phillc54
  • phillc54's Avatar Topic Author
  • Away
  • Platinum Member
  • Platinum Member
More
22 Jan 2020 10:33 #155418 by phillc54
Replied by phillc54 on topic Keybind with arguments
TBH I hadn't thought too much on the how, I was just hoping for a way to save a bit of repetition.

I think what you proposed would work fine.

I ditched the old QtVCP screen I did for PlasmaC, it was much too cluttered and I have started a modified version of QtAxis although now I have seen QtDragon...

Please Log in or Create an account to join the conversation.

More
22 Jan 2020 11:31 #155420 by cmorley
Replied by cmorley on topic Keybind with arguments
ok pushed some keybinding code and qt_cnc (the default screen) showcases it.
if you run default in a terminal and press f9 f10 or f11 it will print a message in the terminal - all from one function.

The code to add to handler file:
(the value can be any python object here we used strings and an integer)

KEYBIND.add_call('Key_F9','on_keycall_custom','f9 pressed tesst')
KEYBIND.add_call('Key_F10','on_keycall_custom',10)
KEYBIND.add_call('Key_F11','on_keycall_custom','f11 pressed test')

and the function:

def on_keycall_custom(self,event,state,shift,cntrl,value):
if state:
print 'custom keycall function value: ',value
The following user(s) said Thank You: phillc54

Please Log in or Create an account to join the conversation.

  • phillc54
  • phillc54's Avatar Topic Author
  • Away
  • Platinum Member
  • Platinum Member
More
22 Jan 2020 11:54 #155421 by phillc54
Replied by phillc54 on topic Keybind with arguments
Thanks Chris, that was quick, looks ideal.
I won't get much time for a couple of days but when I do I'll report back.

Please Log in or Create an account to join the conversation.

  • phillc54
  • phillc54's Avatar Topic Author
  • Away
  • Platinum Member
  • Platinum Member
More
24 Jan 2020 00:34 #155604 by phillc54
Replied by phillc54 on topic Keybind with arguments
That update does exactly what I was after, thanks again.

Please Log in or Create an account to join the conversation.

More
24 Jan 2020 07:28 #155635 by cmorley
Replied by cmorley on topic Keybind with arguments
It was a great idea!

Chris
The following user(s) said Thank You: phillc54

Please Log in or Create an account to join the conversation.

Moderators: cmorley
Time to create page: 0.065 seconds
Powered by Kunena Forum