Nuke: Change context label enhancement (#5887)

* use QAction to change label of context action

* do not handle context label change in nuke assist
This commit is contained in:
Jakub Trllo 2023-11-16 17:22:04 +01:00 committed by GitHub
parent fe8711cf78
commit 19f0a77966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 19 deletions

View file

@ -120,7 +120,7 @@ def deprecated(new_destination):
class Context:
main_window = None
context_label = None
context_action_item = None
project_name = os.getenv("AVALON_PROJECT")
# Workfile related code
workfiles_launched = False

View file

@ -236,9 +236,13 @@ def _install_menu():
if not ASSIST:
label = get_context_label()
Context.context_label = label
context_action = menu.addCommand(label)
context_action.setEnabled(False)
context_action_item = menu.addCommand("Context")
context_action_item.setEnabled(False)
Context.context_action_item = context_action_item
context_action = context_action_item.action()
context_action.setText(label)
# add separator after context label
menu.addSeparator()
@ -348,26 +352,21 @@ def _install_menu():
def change_context_label():
menubar = nuke.menu("Nuke")
menu = menubar.findItem(MENU_LABEL)
if ASSIST:
return
label = get_context_label()
context_action_item = Context.context_action_item
if context_action_item is None:
return
context_action = context_action_item.action()
rm_item = [
(i, item) for i, item in enumerate(menu.items())
if Context.context_label in item.name()
][0]
old_label = context_action.text()
new_label = get_context_label()
menu.removeItem(rm_item[1].name())
context_action = menu.addCommand(
label,
index=(rm_item[0])
)
context_action.setEnabled(False)
context_action.setText(new_label)
log.info("Task label changed from `{}` to `{}`".format(
Context.context_label, label))
old_label, new_label))
def add_shortcuts_from_presets():