From 0c455446cfa16dbcf886d06dc3658e37048512fc Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Mon, 26 Feb 2024 12:43:29 +0000 Subject: [PATCH 1/6] Initial working version --- .../tools/launcher/models/actions.py | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/tools/launcher/models/actions.py b/client/ayon_core/tools/launcher/models/actions.py index 53d2b78dc3..cc323e3745 100644 --- a/client/ayon_core/tools/launcher/models/actions.py +++ b/client/ayon_core/tools/launcher/models/actions.py @@ -293,6 +293,23 @@ def refresh(self): self._get_action_objects() self._controller.emit_event("actions.refresh.finished") + def should_start_last_workfile(self, project_name, host_name, task_id): + from ayon_core.lib.applications import should_start_last_workfile + + task_name = None + task_type = None + if task_id is not None: + task = self._controller.get_task_entity(project_name, task_id) + task_name = task["name"] + task_type = task["taskType"] + + return should_start_last_workfile( + project_name, + host_name, + task_name, + task_type + ) + def get_action_items(self, project_name, folder_id, task_id): """Get actions for project. @@ -304,7 +321,6 @@ def get_action_items(self, project_name, folder_id, task_id): Returns: list[ActionItem]: List of actions. """ - not_open_workfile_actions = self._get_no_last_workfile_for_context( project_name, folder_id, task_id) session = self._prepare_session(project_name, folder_id, task_id) @@ -318,8 +334,16 @@ def get_action_items(self, project_name, folder_id, task_id): # Handling of 'force_not_open_workfile' for applications if action_item.is_application: action_item = action_item.copy() + host_name = action_item.identifier.replace( + "application.", "" + ).split("/")[0] + start_last_workfile_default = self.should_start_last_workfile( + project_name, host_name, task_id + ) action_item.force_not_open_workfile = ( - not_open_workfile_actions.get(identifier, False) + not_open_workfile_actions.get( + identifier, not start_last_workfile_default + ) ) output.append(action_item) @@ -359,11 +383,18 @@ def trigger_action(self, project_name, folder_id, task_id, identifier): per_action = self._get_no_last_workfile_for_context( project_name, folder_id, task_id ) - force_not_open_workfile = per_action.get(identifier, False) + action.data["start_last_workfile"] = True + host_name = action_item.identifier.replace( + "application.", "" + ).split("/")[0] + start_last_workfile_default = self.should_start_last_workfile( + project_name, host_name, task_id + ) + force_not_open_workfile = per_action.get( + identifier, not start_last_workfile_default + ) if force_not_open_workfile: action.data["start_last_workfile"] = False - else: - action.data.pop("start_last_workfile", None) action.process(session) except Exception as exc: self.log.warning("Action trigger failed.", exc_info=True) @@ -464,6 +495,10 @@ def _get_action_items(self, project_name): label = action.label or identifier variant_label = getattr(action, "label_variant", None) icon = get_action_icon(action) + host_name = identifier.replace("application.", "").split("/")[0] + force_not_open_workfile = not self.should_start_last_workfile( + project_name, host_name, None + ) item = ActionItem( identifier, label, @@ -471,7 +506,7 @@ def _get_action_items(self, project_name): icon, action.order, is_application, - False + force_not_open_workfile ) action_items[identifier] = item self._action_items[project_name] = action_items From 0bf93a1324a4ae6e7f902aba064d0d55427e050c Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Mon, 26 Feb 2024 12:55:44 +0000 Subject: [PATCH 2/6] Code cosmetics --- .../tools/launcher/models/actions.py | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/client/ayon_core/tools/launcher/models/actions.py b/client/ayon_core/tools/launcher/models/actions.py index cc323e3745..8246bfa007 100644 --- a/client/ayon_core/tools/launcher/models/actions.py +++ b/client/ayon_core/tools/launcher/models/actions.py @@ -334,17 +334,23 @@ def get_action_items(self, project_name, folder_id, task_id): # Handling of 'force_not_open_workfile' for applications if action_item.is_application: action_item = action_item.copy() - host_name = action_item.identifier.replace( - "application.", "" - ).split("/")[0] - start_last_workfile_default = self.should_start_last_workfile( - project_name, host_name, task_id - ) - action_item.force_not_open_workfile = ( - not_open_workfile_actions.get( - identifier, not start_last_workfile_default + + if identifier in not_open_workfile_actions: + action_item.force_not_open_workfile = ( + not_open_workfile_actions[identifier] + ) + else: + host_name = action_item.identifier.replace( + "application.", "" + ).split("/")[0] + start_last_workfile_default = ( + self.should_start_last_workfile( + project_name, host_name, task_id + ) + ) + action_item.force_not_open_workfile = ( + not start_last_workfile_default ) - ) output.append(action_item) return output @@ -384,17 +390,26 @@ def trigger_action(self, project_name, folder_id, task_id, identifier): project_name, folder_id, task_id ) action.data["start_last_workfile"] = True - host_name = action_item.identifier.replace( - "application.", "" - ).split("/")[0] - start_last_workfile_default = self.should_start_last_workfile( - project_name, host_name, task_id - ) - force_not_open_workfile = per_action.get( - identifier, not start_last_workfile_default - ) + + force_not_open_workfile = None + if identifier in per_action: + force_not_open_workfile = per_action[identifier] + else: + host_name = action_item.identifier.replace( + "application.", "" + ).split("/")[0] + start_last_workfile_default = ( + self.should_start_last_workfile( + project_name, host_name, task_id + ) + ) + force_not_open_workfile = per_action.get( + identifier, not start_last_workfile_default + ) + if force_not_open_workfile: action.data["start_last_workfile"] = False + action.process(session) except Exception as exc: self.log.warning("Action trigger failed.", exc_info=True) From de5601e5abbf2ce653fac2bcf8fbab123f326ad9 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 27 Feb 2024 12:03:18 +0100 Subject: [PATCH 3/6] keep initialization of ActionItem untouched --- client/ayon_core/tools/launcher/models/actions.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/ayon_core/tools/launcher/models/actions.py b/client/ayon_core/tools/launcher/models/actions.py index 8246bfa007..b975eb36f1 100644 --- a/client/ayon_core/tools/launcher/models/actions.py +++ b/client/ayon_core/tools/launcher/models/actions.py @@ -507,13 +507,11 @@ def _get_action_items(self, project_name): if is_application: action.project_entities[project_name] = project_entity action.project_settings[project_name] = project_settings + label = action.label or identifier variant_label = getattr(action, "label_variant", None) icon = get_action_icon(action) - host_name = identifier.replace("application.", "").split("/")[0] - force_not_open_workfile = not self.should_start_last_workfile( - project_name, host_name, None - ) + item = ActionItem( identifier, label, @@ -521,7 +519,7 @@ def _get_action_items(self, project_name): icon, action.order, is_application, - force_not_open_workfile + False ) action_items[identifier] = item self._action_items[project_name] = action_items From b7889303c0d54c8ecbd112f6ec662f9762030dff Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 27 Feb 2024 12:04:08 +0100 Subject: [PATCH 4/6] move all the logic to '_should_start_last_workfile' --- .../tools/launcher/models/actions.py | 71 +++++++++---------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/client/ayon_core/tools/launcher/models/actions.py b/client/ayon_core/tools/launcher/models/actions.py index b975eb36f1..59f6897200 100644 --- a/client/ayon_core/tools/launcher/models/actions.py +++ b/client/ayon_core/tools/launcher/models/actions.py @@ -293,9 +293,19 @@ def refresh(self): self._get_action_objects() self._controller.emit_event("actions.refresh.finished") - def should_start_last_workfile(self, project_name, host_name, task_id): + def _should_start_last_workfile( + self, + project_name, + task_id, + identifier, + host_name, + not_open_workfile_actions + ): from ayon_core.lib.applications import should_start_last_workfile + if identifier in not_open_workfile_actions: + return not_open_workfile_actions[identifier] + task_name = None task_type = None if task_id is not None: @@ -303,12 +313,14 @@ def should_start_last_workfile(self, project_name, host_name, task_id): task_name = task["name"] task_type = task["taskType"] - return should_start_last_workfile( + output = should_start_last_workfile( project_name, host_name, task_name, task_type ) + not_open_workfile_actions[identifier] = output + return output def get_action_items(self, project_name, folder_id, task_id): """Get actions for project. @@ -334,23 +346,16 @@ def get_action_items(self, project_name, folder_id, task_id): # Handling of 'force_not_open_workfile' for applications if action_item.is_application: action_item = action_item.copy() - - if identifier in not_open_workfile_actions: - action_item.force_not_open_workfile = ( - not_open_workfile_actions[identifier] - ) - else: - host_name = action_item.identifier.replace( - "application.", "" - ).split("/")[0] - start_last_workfile_default = ( - self.should_start_last_workfile( - project_name, host_name, task_id - ) - ) - action_item.force_not_open_workfile = ( - not start_last_workfile_default - ) + start_last_workfile = self._should_start_last_workfile( + project_name, + task_id, + identifier, + action.application.host_name, + not_open_workfile_actions + ) + action_item.force_not_open_workfile = ( + not start_last_workfile + ) output.append(action_item) return output @@ -389,26 +394,14 @@ def trigger_action(self, project_name, folder_id, task_id, identifier): per_action = self._get_no_last_workfile_for_context( project_name, folder_id, task_id ) - action.data["start_last_workfile"] = True - - force_not_open_workfile = None - if identifier in per_action: - force_not_open_workfile = per_action[identifier] - else: - host_name = action_item.identifier.replace( - "application.", "" - ).split("/")[0] - start_last_workfile_default = ( - self.should_start_last_workfile( - project_name, host_name, task_id - ) - ) - force_not_open_workfile = per_action.get( - identifier, not start_last_workfile_default - ) - - if force_not_open_workfile: - action.data["start_last_workfile"] = False + start_last_workfile = self._should_start_last_workfile( + project_name, + task_id, + identifier, + action.application.host_name, + per_action + ) + action.data["start_last_workfile"] = start_last_workfile action.process(session) except Exception as exc: From 06ae29761440788cb47ea0f8477ccedd48a444f9 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 27 Feb 2024 14:10:34 +0100 Subject: [PATCH 5/6] do not cache all values and fix output value --- client/ayon_core/tools/launcher/models/actions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/ayon_core/tools/launcher/models/actions.py b/client/ayon_core/tools/launcher/models/actions.py index 59f6897200..463d363e3a 100644 --- a/client/ayon_core/tools/launcher/models/actions.py +++ b/client/ayon_core/tools/launcher/models/actions.py @@ -304,7 +304,7 @@ def _should_start_last_workfile( from ayon_core.lib.applications import should_start_last_workfile if identifier in not_open_workfile_actions: - return not_open_workfile_actions[identifier] + return not not_open_workfile_actions[identifier] task_name = None task_type = None @@ -319,7 +319,6 @@ def _should_start_last_workfile( task_name, task_type ) - not_open_workfile_actions[identifier] = output return output def get_action_items(self, project_name, folder_id, task_id): From 5b04bf1c6c4a2295103e892b323ace4f3ba9731f Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 27 Feb 2024 14:11:02 +0100 Subject: [PATCH 6/6] update view on refresh --- client/ayon_core/tools/launcher/ui/actions_widget.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/ayon_core/tools/launcher/ui/actions_widget.py b/client/ayon_core/tools/launcher/ui/actions_widget.py index 6667b4ed5f..617f3b0c91 100644 --- a/client/ayon_core/tools/launcher/ui/actions_widget.py +++ b/client/ayon_core/tools/launcher/ui/actions_widget.py @@ -358,6 +358,8 @@ def _set_row_height(self, rows): def _on_model_refresh(self): self._proxy_model.sort(0) + # Force repaint all items + self._view.update() def _on_animation(self): time_now = time.time()