ExtendedHotkeys v1.2


 
This location is for Registered Users Only.
Perhaps you need to login or register.
Contributor: Alex Hughes
Website: alex-hughes.com
ExtendedHotkeys provides a new type of hotkey configuration into Nuke. It allows you to define a hotkey that does different things based on how many times you click it.
Requirements:
11.0, 10.5, 10.0 or later
Linux, Windows
02 Jun 2021
63

ExtendedHotkeys for Nuke
ExtendedHotkeys is a quick plugins for the Foundry's Nuke application.

 

A better information description page can be found here: https://github.com/Ahuge/extended_hotkeys

 

What does it do
ExtendedHotkeys provides a new type of hotkey configuration into Nuke.
It allows you to define a hotkey that does different things based on how many times you click it.

For example, one of the artists I know plays StarCraft and is used to double tapping the 1 key to center his screen so he asked me to create him a hotkey that would center his node graph on whatever node his viewer was looking through.
This provided easy enough because Nuke allows you to override the 1 hotkey.
Unfortunately this will get rid of his ability to set his 1 input to a node and therefore renders the entire hotkey useless.

I came up with a system that would allow him to press the 1 key once and have it work like normal but if he presses it twice in quick succession, it will instead execute the custom 'center on node' function.

I later expanded this into a more generic system that would allow you to have as many extra functions as you want.
That system is now ExtendedHotkeys


How do I use it
If you load the extended_hotkeys init.py file, it will add itself to the nuke module as nuke.addExtendedCommand

You can then call it like this:


def
_print_quick(): print('Wow! Such fast!')

def _print_second(): print('You called the second hotkey!')

def _print_last(): print('You made it to the last hotkey!')
toolbar = nuke.menu('Nodes').menu('Other') nuke.addExtendedCommand(toolbar, 'Special Command', [_print_quick, _print_second, _print_last], 'v')

 

The addExtendedCommand function has a very similar spec to nuke.Menu.addCommand.

The main difference is the implicit first arg self must be passed in manually.
Other differences include:
- command kwarg is now commands and can be a list too.
- timeout has been added and is in ms.

def addExtendedCommand(menu, name, commands, shortcut=None, icon=None, tooltip=None, index=None, readonly=None, shortcutContext=None, timeout=1000):
    '''
  addExtendedCommand(...)
    self.addCommand(name, command, shortcut, icon, tooltip, index, readonly) -> The menu/toolbar item that was added to hold the command.
    Add a new command to this menu/toolbar. Note that when invoked, the command is automatically enclosed in an undo group, so that undo/redo functionality works. Optional arguments can be specified by name.
    Note that if the command argument is not specified, then the command will be auto-created as a 'nuke.createNode()' using the name argument as the node to create.

    Example:
    menubar = nuke.menu('Nuke')
    fileMenu = menubar.findItem('File')
    fileMenu.addCommand('NewCommand', 'print 10', shortcut='t')

    @param name: The name for the menu/toolbar item. The name may contain submenu names delimited by '/' or '', and submenus are created as needed.
    @param commands: Optional. The commands to add to the menu/toolbar. This can be a string to evaluate or a Python Callable (function, method, etc) to run or a list of either.
    @param shortcut: Optional. The keyboard shortcut for the command, such as 'R', 'F5' or 'Ctrl-H'. Note that this overrides pre-existing other uses for the shortcut.
    @param icon: Optional. An icon for the command. This should be a path to an icon in the nuke.pluginPath() directory. If the icon is not specified, Nuke will automatically try to find an icon with the name argument and .png appended to it.
    @param tooltip: Optional. The tooltip text, displayed on mouseover for toolbar buttons.
    @param index: Optional. The position to insert the new item in, in the menu/toolbar. This defaults to last in the menu/toolbar.
    @param readonly: Optional. True/False for whether the item should be available when the menu is invoked in a read-only context.
    @param shortcutContext: Optional. Sets the shortcut context (0==Window, 1=Application, 2=DAG).
    @param timeout: Optional. Only comes active if you pass multiple commands. Sets the timeout for our internal timer on your new hotkey. It's the total time between your first click to your last click to trigger all your callbacks for the hotkey.
    @return: The menu/toolbar item that was added to hold the command.
    '''

Helpers
There is also a helpers module provided with ExtendedHotkeys.
It must be manually imported as a python module with `from extended_hotkeys import helpers`.
Helpers contains a few useful functions to aid in extending existing hotkeys.

helpers.path_to_hotkey
path_to_hotkey will take a string path in the form of 

/

/  of any length where

is the name of a Nuke menu and is the resulting item you want to return.

 For example:

path_to_hotkey('Nodes/Color/Grade')

  will return the menu item to create a grade.

There are some special menu items you may not know about.
Check out 

nuke.hotkeys()

 to see them all.

There is some special case work being done for the 'Viewer/Input/' hotkeys because they don't seem to be perfectly mapped to the menuItem.

For reference:
    'Viewer/Input/' will return the action that gets called when you press .

helpers.jump_to_input
jump_to_input takes an input number and when called will center your viewer on whichever node your viewer is connected to at index

:param number: The 0 indexed number corresponding to the input you want
:type number: int
:return: A lazy function that will evaluate the input at index when called.
:rettype: types.FunctionType

helpers.viewer_hotkey
viewer_hotkey will return a types.FunctionType object that simulates pressing a number on your keyboard when you have a viewer.
It is probably better to call `path_to_hotkey('Viewer/Input/') instead of `viewer_hotkey()` because the former deals with turning the `1` on your keyboard into index `0` for the viewer.


Contributing
Everyone is encouraged to contribute!
Especially people that are new to contributing on github!

I am specifically interested in reporting bugs or implementing any other 'special edge cases' like the viewer hotkeys.

Please login in order to download these files.

Comments   

 
+2 # bin zhuang 2019-03-18 02:47
well could you make a tutorial to demonstrate how to use it ?
thanks
 
 
0 # Alex Hughes 2019-03-27 19:58
Yes will do!

There is a brief demo on my github that might help in the meantime


https://github.com/Ahuge/extended_hotkeys
 
 
0 # bin zhuang 2019-03-28 08:36
I put the init.py file into the .nuke folder
and then write the sample code you give
error :
core.py line 188
" NoneType object has no attribute 'addcommand' "
 
 
0 # bang meng 2019-03-18 15:49
很棒的思路,很酷的想法
 
 
0 # Alex Hughes 2019-03-27 19:59
Thanks
 
 
0 # Bernd M 2020-01-14 22:37
Interesting idea and execution. Just thinking about some ways how to use it... maybe C could be a CC and second tap a camera or something... let's see how to make this intuitive for me
 

You have no rights to post comments

We have 3949 guests and 93 members online