From 5d1b6b31e288bf6261ded25f0711209410d8541e Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Thu, 29 Aug 2024 10:34:05 +0100 Subject: [PATCH 1/8] my task sort fields now driven by configuration --- info.yml | 17 +++++++++++++++ python/app/dialog.py | 52 ++++++++++++++++++++------------------------ 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/info.yml b/info.yml index 9c82901a..292c558c 100644 --- a/info.yml +++ b/info.yml @@ -36,6 +36,23 @@ configuration: default_value_tk-maya: "{self}/general_actions.py:{self}/{engine_name}_actions.py" description: Hook which contains all methods for action management. + my_task_sort_fields: + type: list + description: "Controls what fields appear for sorting + " + allows_empty: True + default_value: + - { field_code: 'due_date', display_name: "Due Date", default: True } + - { field_code: 'start_date', display_name: "Start Date" } + - { field_code: 'sg_status_list', display_name: "Status" } + - { field_code: 'step', display_name: "Step"} + - { field_code: 'entity.Asset.code', display_name: "Asset > Name"} + values: + type: dict + items: + field_code: { type: str } + display_name: { type: str } + action_mappings: type: dict description: Associates shotgun objects with actions. The actions are all defined diff --git a/python/app/dialog.py b/python/app/dialog.py index ff3cc1fe..ac0f5281 100644 --- a/python/app/dialog.py +++ b/python/app/dialog.py @@ -1326,30 +1326,25 @@ def _sort_menu_actions(self): Populate the sort menu with actions. """ + sort_fields = self._app.get_setting("my_task_sort_fields") + # Create Sort Menu actions sort_asc = self._entity_field_menu._get_qaction("ascending", "Ascending") sort_desc = self._entity_field_menu._get_qaction("descending", "Descending") separator = self._entity_field_menu.addSeparator() - status_action = self._entity_field_menu._get_qaction("sg_status_list", "Status") - step_action = self._entity_field_menu._get_qaction("step", "Step") - start_date_action = self._entity_field_menu._get_qaction( - "start_date", "Start date" - ) - due_date_action = self._entity_field_menu._get_qaction("due_date", "Due date") + field_sort_actions = [self._entity_field_menu._get_qaction(field["field_code"], field["display_name"]) for field in sort_fields] # Actions group list ordered sort_actions = [ - due_date_action, - start_date_action, - status_action, - separator, sort_asc, sort_desc, + separator, + *field_sort_actions ] - # By default it sort Tasks due date in descending order + # By default it sorts in descending order and the default field is set in the configuration sort_desc.setChecked(True) - due_date_action.setChecked(True) + # Menu sort order actions sort_asc.triggered[()].connect( lambda: self.load_sort_data( @@ -1361,19 +1356,20 @@ def _sort_menu_actions(self): "descending", sort_desc, sort_actions, sort_order="desc" ) ) + # Menu sort field actions - status_action.triggered[()].connect( - lambda: self.load_sort_data("sg_status_list", status_action, sort_actions) - ) - step_action.triggered[()].connect( - lambda: self.load_sort_data("step", step_action, sort_actions) - ) - start_date_action.triggered[()].connect( - lambda: self.load_sort_data("start_date", start_date_action, sort_actions) - ) - due_date_action.triggered[()].connect( - lambda: self.load_sort_data("due_date", due_date_action, sort_actions) - ) + for index, field_sort_action in enumerate(field_sort_actions): + sort_field = sort_fields[index] + + is_default = sort_field.get("default", False) + if is_default: + field_sort_action.setChecked(True) + + field_code = sort_field['field_code'] + field_sort_action.triggered[()].connect( + lambda fc=field_code, fsa=field_sort_action: self.load_sort_data(fc, fsa, sort_actions) + ) + # Add actions to the entity Menu self._entity_field_menu.add_group(sort_actions, "Sort menu") # Remove the separator from the list @@ -1430,11 +1426,11 @@ def load_sort_data(self, field, sort_action, actions_list, **sort_order): # Set checked the current sort order in the Menu if sort_order == "asc": - actions_list[3].setChecked(True) - actions_list[4].setChecked(False) + actions_list[0].setChecked(True) + actions_list[1].setChecked(False) elif sort_order == "desc": - actions_list[4].setChecked(True) - actions_list[3].setChecked(False) + actions_list[0].setChecked(False) + actions_list[1].setChecked(True) # Save the last menu item selected self._current_menu_sort_item = field From de2da4d0719a55f9f1f94da9e8ab9e7ed5a94e14 Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Thu, 29 Aug 2024 10:36:12 +0100 Subject: [PATCH 2/8] ran commit hook on changes --- python/app/dialog.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/python/app/dialog.py b/python/app/dialog.py index ac0f5281..3c877f07 100644 --- a/python/app/dialog.py +++ b/python/app/dialog.py @@ -1332,15 +1332,15 @@ def _sort_menu_actions(self): sort_asc = self._entity_field_menu._get_qaction("ascending", "Ascending") sort_desc = self._entity_field_menu._get_qaction("descending", "Descending") separator = self._entity_field_menu.addSeparator() - field_sort_actions = [self._entity_field_menu._get_qaction(field["field_code"], field["display_name"]) for field in sort_fields] + field_sort_actions = [ + self._entity_field_menu._get_qaction( + field["field_code"], field["display_name"] + ) + for field in sort_fields + ] # Actions group list ordered - sort_actions = [ - sort_asc, - sort_desc, - separator, - *field_sort_actions - ] + sort_actions = [sort_asc, sort_desc, separator, *field_sort_actions] # By default it sorts in descending order and the default field is set in the configuration sort_desc.setChecked(True) @@ -1365,9 +1365,11 @@ def _sort_menu_actions(self): if is_default: field_sort_action.setChecked(True) - field_code = sort_field['field_code'] + field_code = sort_field["field_code"] field_sort_action.triggered[()].connect( - lambda fc=field_code, fsa=field_sort_action: self.load_sort_data(fc, fsa, sort_actions) + lambda fc=field_code, fsa=field_sort_action: self.load_sort_data( + fc, fsa, sort_actions + ) ) # Add actions to the entity Menu From de42fe26aec08d7f345617ab87338a22886b2a47 Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Thu, 29 Aug 2024 11:53:00 +0100 Subject: [PATCH 3/8] fixed default sort bug and default sort settings --- info.yml | 1 - python/app/dialog.py | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/info.yml b/info.yml index 292c558c..dcd91a2b 100644 --- a/info.yml +++ b/info.yml @@ -46,7 +46,6 @@ configuration: - { field_code: 'start_date', display_name: "Start Date" } - { field_code: 'sg_status_list', display_name: "Status" } - { field_code: 'step', display_name: "Step"} - - { field_code: 'entity.Asset.code', display_name: "Asset > Name"} values: type: dict items: diff --git a/python/app/dialog.py b/python/app/dialog.py index 3c877f07..46f80195 100644 --- a/python/app/dialog.py +++ b/python/app/dialog.py @@ -1358,20 +1358,27 @@ def _sort_menu_actions(self): ) # Menu sort field actions + default_set = False for index, field_sort_action in enumerate(field_sort_actions): sort_field = sort_fields[index] + field_code = sort_field["field_code"] is_default = sort_field.get("default", False) if is_default: + default_set = True field_sort_action.setChecked(True) + self._current_menu_sort_item = field_code - field_code = sort_field["field_code"] field_sort_action.triggered[()].connect( lambda fc=field_code, fsa=field_sort_action: self.load_sort_data( fc, fsa, sort_actions ) ) + if not default_set and sort_fields: + field_sort_actions[0].setChecked(True) + self._current_menu_sort_item = sort_fields[0]["field_code"] + # Add actions to the entity Menu self._entity_field_menu.add_group(sort_actions, "Sort menu") # Remove the separator from the list From 4484fcb2b666ee2e9cd69bba0d992b39038c628a Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Fri, 30 Aug 2024 09:47:29 +0100 Subject: [PATCH 4/8] sort field setting now tab generic --- info.yml | 23 +++++++++++++---------- python/app/dialog.py | 7 ++++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/info.yml b/info.yml index dcd91a2b..984341b4 100644 --- a/info.yml +++ b/info.yml @@ -36,21 +36,24 @@ configuration: default_value_tk-maya: "{self}/general_actions.py:{self}/{engine_name}_actions.py" description: Hook which contains all methods for action management. - my_task_sort_fields: - type: list + sort_fields: + type: dict description: "Controls what fields appear for sorting " allows_empty: True default_value: - - { field_code: 'due_date', display_name: "Due Date", default: True } - - { field_code: 'start_date', display_name: "Start Date" } - - { field_code: 'sg_status_list', display_name: "Status" } - - { field_code: 'step', display_name: "Step"} + "tasks": + - { field_code: 'due_date', display_name: "Due Date", default: True } + - { field_code: 'start_date', display_name: "Start Date" } + - { field_code: 'sg_status_list', display_name: "Status" } + - { field_code: 'step', display_name: "Step"} values: - type: dict - items: - field_code: { type: str } - display_name: { type: str } + type: list + values: + type: dict + items: + field_code: { type: str } + display_name: { type: str } action_mappings: type: dict diff --git a/python/app/dialog.py b/python/app/dialog.py index 46f80195..01b0d94b 100644 --- a/python/app/dialog.py +++ b/python/app/dialog.py @@ -929,6 +929,7 @@ def build_entity_tabs(self): "has_description": True, "has_view": True, "has_filter": False, + "tab_name": entity_tab_name, } if entity_tab_name == self.ENTITY_TAB_NOTES: @@ -1298,7 +1299,7 @@ def _sort_menu_setup(self, task_tab_data): ) fields_manager.initialized.connect(self._field_filters) fields_manager.initialize() - self._sort_menu_actions() + self._sort_menu_actions(task_tab_data["tab_name"]) def _field_filters(self): @@ -1321,12 +1322,12 @@ def disabled_filter(field): self._entity_field_menu.set_checked_filter(checked_filter) self._entity_field_menu.set_disabled_filter(disabled_filter) - def _sort_menu_actions(self): + def _sort_menu_actions(self, tab_name): """ Populate the sort menu with actions. """ - sort_fields = self._app.get_setting("my_task_sort_fields") + sort_fields = self._app.get_setting("sort_fields").get(tab_name, []) # Create Sort Menu actions sort_asc = self._entity_field_menu._get_qaction("ascending", "Ascending") From 40f96b85472cd25d199ae100ceb53139559c07e1 Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Fri, 30 Aug 2024 13:17:11 +0100 Subject: [PATCH 5/8] update description --- info.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/info.yml b/info.yml index 984341b4..5bc8267d 100644 --- a/info.yml +++ b/info.yml @@ -38,8 +38,10 @@ configuration: sort_fields: type: dict - description: "Controls what fields appear for sorting - " + description: Controls what fields appear for sorting in the UI. + Currently the sort menu only shows on the tasks tab. + You can add any field that would normally be suitable for sorting a query + by for the tab's given entity type. allows_empty: True default_value: "tasks": From 3b0a06b4f6588364747696815458cdf539dc95b0 Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Mon, 21 Oct 2024 15:21:03 +0100 Subject: [PATCH 6/8] fixing error if sort fields are None --- python/app/dialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/app/dialog.py b/python/app/dialog.py index 01b0d94b..a7ba0ba4 100644 --- a/python/app/dialog.py +++ b/python/app/dialog.py @@ -1337,7 +1337,7 @@ def _sort_menu_actions(self, tab_name): self._entity_field_menu._get_qaction( field["field_code"], field["display_name"] ) - for field in sort_fields + for field in sort_fields or [] ] # Actions group list ordered From 5156a6f8ceb16ffa43c3beac5a6cd9dedab96dfa Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Wed, 23 Oct 2024 10:56:17 +0100 Subject: [PATCH 7/8] standardizing use of quotes in info.yml --- info.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/info.yml b/info.yml index 5bc8267d..9f1f7b08 100644 --- a/info.yml +++ b/info.yml @@ -44,11 +44,12 @@ configuration: by for the tab's given entity type. allows_empty: True default_value: - "tasks": - - { field_code: 'due_date', display_name: "Due Date", default: True } - - { field_code: 'start_date', display_name: "Start Date" } - - { field_code: 'sg_status_list', display_name: "Status" } - - { field_code: 'step', display_name: "Step"} + tasks: + - { field_code: "due_date", display_name: "Due Date", default: True } + - { field_code: "start_date", display_name: "Start Date" } + - { field_code: "sg_status_list", display_name: "Status" } + - { field_code: "step", display_name: "Step"} + - { field_code: "entity.Asset.code", display_name: "Asset Name"} values: type: list values: From 25904a522536a7f939a0a1a084ff907583652d6a Mon Sep 17 00:00:00 2001 From: Philip Scadding Date: Wed, 23 Oct 2024 10:58:46 +0100 Subject: [PATCH 8/8] removed sort field added by mistake --- info.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/info.yml b/info.yml index 9f1f7b08..1f893243 100644 --- a/info.yml +++ b/info.yml @@ -49,7 +49,6 @@ configuration: - { field_code: "start_date", display_name: "Start Date" } - { field_code: "sg_status_list", display_name: "Status" } - { field_code: "step", display_name: "Step"} - - { field_code: "entity.Asset.code", display_name: "Asset Name"} values: type: list values: