Skip to content

Commit d74f019

Browse files
committed
move run_tool startup and action logic back to the dcc and separate run tool and subscribe action in client
1 parent 60d0617 commit d74f019

File tree

2 files changed

+71
-53
lines changed
  • libs/framework-core/source/ftrack_framework_core/client
  • projects/framework-maya/source/ftrack_framework_maya

2 files changed

+71
-53
lines changed

libs/framework-core/source/ftrack_framework_core/client/__init__.py

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,45 @@ def _on_launch_action_callback(self, event):
405405
options = event['data']['options']
406406
options['event_data'] = {'selection': selection}
407407

408-
self.run_tool(name, label, True, False, dialog_name, options)
408+
self.run_tool(name, dialog_name, options)
409+
410+
def subscribe_action_tool(
411+
self,
412+
name,
413+
label=None,
414+
dialog_name=None,
415+
options=None,
416+
session_identifier_func=None,
417+
):
418+
'''
419+
Subscribe the given tool to the ftrack.action.discover and
420+
ftrack.action.launch events.
421+
'''
422+
if not options:
423+
options = dict()
424+
# TODO: we don't support dock_fn in here because is not serializable
425+
self.remote_session.event_hub.subscribe(
426+
u'topic=ftrack.action.discover and '
427+
u'source.user.username="{0}"'.format(self.session.api_user),
428+
partial(
429+
self._on_discover_action_callback,
430+
name,
431+
label,
432+
dialog_name,
433+
options,
434+
session_identifier_func,
435+
),
436+
)
437+
438+
self.remote_session.event_hub.subscribe(
439+
u'topic=ftrack.action.launch and '
440+
u'data.name={0} and '
441+
u'source.user.username="{1}" and '
442+
u'data.host_id={2}'.format(
443+
name, self.session.api_user, self.host_id
444+
),
445+
self._on_launch_action_callback,
446+
)
409447

410448
@track_framework_usage(
411449
'FRAMEWORK_RUN_TOOL',
@@ -415,13 +453,9 @@ def _on_launch_action_callback(self, event):
415453
def run_tool(
416454
self,
417455
name,
418-
label=None,
419-
run=False,
420-
action=False,
421456
dialog_name=None,
422457
options=None,
423458
dock_func=False,
424-
session_identifier_func=None,
425459
):
426460
'''
427461
Client runs the tool passed from the DCC config, can run run_dialog
@@ -432,35 +466,6 @@ def run_tool(
432466
if not options:
433467
options = dict()
434468

435-
if action:
436-
# TODO: we don't support dock_fn in here because is not serializable
437-
self.remote_session.event_hub.subscribe(
438-
u'topic=ftrack.action.discover and '
439-
u'source.user.username="{0}"'.format(self.session.api_user),
440-
partial(
441-
self._on_discover_action_callback,
442-
name,
443-
label,
444-
dialog_name,
445-
options,
446-
session_identifier_func,
447-
),
448-
)
449-
450-
self.remote_session.event_hub.subscribe(
451-
u'topic=ftrack.action.launch and '
452-
u'data.name={0} and '
453-
u'source.user.username="{1}" and '
454-
u'data.host_id={2}'.format(
455-
name, self.session.api_user, self.host_id
456-
),
457-
self._on_launch_action_callback,
458-
)
459-
460-
if not run:
461-
return
462-
# TODO: if run_on is not action, simply continue and execute the tool
463-
464469
if dialog_name:
465470
self.run_dialog(
466471
dialog_name,

projects/framework-maya/source/ftrack_framework_maya/__init__.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,31 @@ def get_ftrack_menu(menu_name='ftrack', submenu_name=None):
9898
def on_run_tool_callback(
9999
client_instance,
100100
tool_name,
101-
label,
102-
run,
103-
action,
104101
dialog_name=None,
105-
options=dict,
102+
options=None,
106103
maya_args=None,
107104
):
108105
client_instance.run_tool(
109106
tool_name,
110-
label,
111-
run,
112-
action,
113107
dialog_name,
114108
options,
115109
dock_func=dock_maya_right if dialog_name else None,
110+
)
111+
112+
113+
@run_in_main_thread
114+
def on_subscribe_action_tool_callback(
115+
client_instance,
116+
tool_name,
117+
label,
118+
dialog_name=None,
119+
options=None,
120+
):
121+
client_instance.subscribe_action_tool(
122+
tool_name,
123+
label,
124+
dialog_name,
125+
options,
116126
session_identifier_func=get_maya_session_identifier,
117127
)
118128

@@ -217,24 +227,27 @@ def bootstrap_integration(framework_extensions_path):
217227
on_run_tool_callback,
218228
client_instance,
219229
tool.get('name'),
220-
label,
221-
True,
222-
action,
223230
tool.get('dialog_name'),
224231
tool['options'],
225232
)
226233
),
227234
image=":/{}.png".format(tool['icon']),
228235
)
229-
on_run_tool_callback(
230-
client_instance,
231-
tool.get('name'),
232-
label,
233-
run_on == "startup",
234-
action,
235-
tool.get('dialog_name'),
236-
tool['options'],
237-
)
236+
if run_on == "startup":
237+
on_run_tool_callback(
238+
client_instance,
239+
tool.get('name'),
240+
tool.get('dialog_name'),
241+
tool['options'],
242+
)
243+
if action:
244+
on_subscribe_action_tool_callback(
245+
client_instance,
246+
tool.get('name'),
247+
label,
248+
tool.get('dialog_name'),
249+
tool['options'],
250+
)
238251

239252
return client_instance
240253

0 commit comments

Comments
 (0)