Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update startup.py #69

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions python/tk_nuke/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def __sgtk_on_save_callback():
logger.debug("New context computed to be: %r" % new_ctx)

# now restart the engine with the new context
__engine_refresh(new_ctx)
if curr_ctx != new_ctx:
__engine_refresh(new_ctx)

except Exception:
logger.exception("An exception was raised during addOnScriptSave callback.")
Expand Down Expand Up @@ -208,7 +209,8 @@ def sgtk_on_load_callback():
logger.debug("Current context: %r" % (curr_ctx,))
logger.debug("New context: %r" % (new_ctx,))
# Now switch to the context appropriate for the file
__engine_refresh(new_ctx)
if curr_ctx != new_ctx:
__engine_refresh(new_ctx)

elif file_name != "Root" and engine is None:
# we have no engine, this maybe because the integration disabled itself,
Expand Down
11 changes: 5 additions & 6 deletions python/tk_nuke/menu_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,13 @@ def create_menu(self, add_commands=True):
# Get icon if specified - default to tank icon if not specified.
icon = cmd.properties.get("icon", self._shotgun_logo)
command_context = cmd.properties.get("context")
hotkey = cmd.properties.get("hotkey")

# If the app recorded a context that it wants the command to be associated
# with, we need to check it against the current engine context. If they
# don't match then we don't add it.
if command_context is None or command_context is self.engine.context:
node_menu_handle.addCommand(cmd.name, cmd.callback, icon=icon)
node_menu_handle.addCommand(cmd.name, cmd.callback, hotkey, icon=icon)

def create_disabled_menu(self, cmd_name, msg):
"""
Expand Down Expand Up @@ -578,12 +579,13 @@ def create_menu(self, add_commands=True):
# Get icon if specified - default to tank icon if not specified.
icon = cmd.properties.get("icon", self._shotgun_logo)
command_context = cmd.properties.get("context")
hotkey = cmd.properties.get("hotkey")

# If the app recorded a context that it wants the command to be associated
# with, we need to check it against the current engine context. If they
# don't match then we don't add it.
if command_context is None or command_context is self.engine.context:
node_menu_handle.addCommand(cmd.name, cmd.callback, icon=icon)
node_menu_handle.addCommand(cmd.name, cmd.callback, hotkey, icon=icon)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

elif cmd.type == "context_menu":
cmd.add_command_to_menu(self._context_menu)
else:
Expand Down Expand Up @@ -1013,10 +1015,7 @@ def add_command_to_menu(self, menu, enabled=True, icon=None, hotkey=None):
# NOTE: setting the new callback lambda on the object to resolve
# a crash on close happening in Nuke 11. Likely a GC issue, and having
# the callable associated with an object resolves it.
if hotkey:
menu.addCommand(self.name, self.callback, hotkey, icon=icon)
else:
menu.addCommand(self.name, self.callback, icon=icon)
menu.addCommand(self.name, self.callback, hotkey, icon=icon)


# -----------------------------------------------------------------------------
62 changes: 51 additions & 11 deletions startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class NukeLauncher(SoftwareLauncher):
"NukeAssist",
"NukeStudio",
"NukeX",
"Hiero",
]

# This dictionary defines a list of executable template strings for each
Expand Down Expand Up @@ -110,6 +111,40 @@ def scan_software(self):

return softwares

def _scan_software_entities(self):
filters = [
['sg_status_list', 'is', 'act'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

['engine', 'in', ['tk-nuke', 'tk-hiero', 'tk-nukestudio']],
{
'filter_operator': 'any',
'filters': [
['sg_mac_template', 'is_not', None],
['sg_linux_template', 'is_not', None],
['sg_windows_template', 'is_not', None],
]
}
]
os_template = {'win32': 'sg_windows_template',
'linux2': 'sg_linux_template',
'darwin': 'sg_mac_template'}
fields = ['sg_mac_template',
'sg_linux_template',
'sg_windows_template']
results = self.shotgun.find("Software", filters, fields)

templ_list = []
for result in results:
if result.get(os_template[sys.platform]):
try:
templ_list.extend(result.get(
os_template[sys.platform]).split('\n'))
except AttributeError as e:
self.logger.error(
'AttributeError on template \'{}\': {}'.format(result.get('code'), e))
pass

return templ_list

def _find_software(self):
"""
Finds all Nuke software on disk.
Expand All @@ -129,15 +164,18 @@ def _find_software(self):
)

# Certain platforms have more than one location for installed software
for template in executable_templates:
self.logger.debug("Processing template %s.", template)
# Extract all products from that executable.
for executable, tokens in self._glob_and_match(
template, self.COMPONENT_REGEX_LOOKUP
):
self.logger.debug("Processing %s with tokens %s", executable, tokens)
for sw in self._extract_products_from_path(executable, tokens):
yield sw
match_templates = executable_templates
match_templates.extend(self._scan_software_entities())

for template in match_templates:
if template is not None:
self.logger.debug("Processing template %s.", template)
# Extract all products from that executable.
for executable, tokens in self._glob_and_match(template, self.COMPONENT_REGEX_LOOKUP):
self.logger.debug(
"Processing %s with tokens %s", executable, tokens)
for sw in self._extract_products_from_path(executable, tokens):
yield sw

def _extract_products_from_path(self, executable_path, match):
"""
Expand Down Expand Up @@ -268,7 +306,8 @@ def prepare_launch(self, exec_path, args, file_to_open=None):
required_env["TANK_CONTEXT"] = sgtk.Context.serialize(self.context)
required_env["TANK_ENGINE"] = self.engine_name

self.logger.debug("Launch environment: %s", pprint.pformat(required_env))
self.logger.debug("Launch environment: %s",
pprint.pformat(required_env))
self.logger.debug("Launch arguments: %s", required_args)

return LaunchInformation(exec_path, required_args, required_env)
Expand Down Expand Up @@ -317,7 +356,8 @@ def _get_plugin_startup_env(self, plugin_names, app_path, app_args, file_to_open
plugin_path = os.path.join(self.disk_location, "plugins", plugin_name)

if os.path.exists(plugin_path):
self.logger.debug("Plugin '%s' found at '%s'", plugin_name, plugin_path)
self.logger.debug("Plugin '%s' found at '%s'",
plugin_name, plugin_path)
startup_paths.append(plugin_path)
else:
self.logger.warning(
Expand Down