shortcuteditor-nuke icon indicating copy to clipboard operation
shortcuteditor-nuke copied to clipboard

Context support

Open herronelou opened this issue 6 years ago • 3 comments

Hi there. Is there any plans to update with shortcutContext support for Nuke 8+ ?

herronelou avatar Jul 21 '17 19:07 herronelou

Good point, this would be useful to add - although annoyingly it doesn't seem like the necessary API exists to do this:

https://docs.thefoundry.co.uk/nuke/105/pythonreference/nuke.MenuItem-class.html The MenuItem has the setShortcut method relied on the by shortcut-editor currently, but no setContext or similar

dbr avatar Jul 27 '17 01:07 dbr

Requested this API from Foundry - "ID 158638 - setShortcut() should have functionality to set shortcut Context"

dbr avatar Aug 21 '20 06:08 dbr

It looks like the context can be identified and modified via the command's Qt action:

from PySide2 import QtCore

x = nuke.menu('Nodes').addCommand('Test/Test X', 'print("x")', 'X', shortcutContext=0)
y = nuke.menu('Nodes').addCommand('Test/Test Y', 'print("y")', 'Y', shortcutContext=1)
z = nuke.menu('Nodes').addCommand('Test/Test Z', 'print("z")', 'Z', shortcutContext=2)

print(x.action().shortcutContext())
print(y.action().shortcutContext())
print(z.action().shortcutContext())

x.action().setShortcutContext(QtCore.Qt.ShortcutContext.WidgetWithChildrenShortcut)
z.action().setShortcutContext(QtCore.Qt.ShortcutContext.ApplicationShortcut)
y.action().setShortcutContext(QtCore.Qt.ShortcutContext.WindowShortcut)

herronelou avatar Dec 25 '22 00:12 herronelou