Parsing nuke.hotkeys() for Hotkey Viewer
This is my approach to make my Nuke Hotkey Tool.
nuke.hotkeys() returns text.
split '\n' and print repr()
Nuke has several menu 'Nuke', 'Nodes', 'Pane', 'Viewer' etc.
menuItem is actual item under menu and menuItem can have shortcuts.
looks like menuitem have '\t' and after '\t' hotkeys if exists.
menu and menuItem hierachy is based on spaces.
looks like menu startswith single ' ' space.
each menuItem under menu startswith four ' ' spaces.
each line itself doesn't contain any information about parent or top menu
but we can calculate by check how many spaces each line have.
so first I checked how many hierarchy step each line is and printed it.
step = (len(line) - len(line.lstrip())-1)/4
print repr(line), step
This will print space count.
Each hierachy has 4 spaces so above number divided by 4 means hierarchy level.
menuItem with shortcut have '\t' character and the shortcut followed '\t' character.
But sometimes there is only '\t' character and no shortcut key.
line.split('\t') is menu or menuItem name
line.split('\t')[-1] is shortcut key.
Let's store the info into the a list.
Then I have everything I need to make hotkey assignment and browse.
menu name and menuItem in the list and keys.
In next tutorial, I would write how to make GUI with QT in Nuke and matching those key information to gui.
Tae Hyung Lee