From b875ee244b4da86ea03b5e826eb39fc4cba1f05b Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Mon, 9 Feb 2026 12:17:13 +0000 Subject: [PATCH 1/3] Added test case --- tests/test_tree_widget.py | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test_tree_widget.py b/tests/test_tree_widget.py index f6137c06..e96aae16 100644 --- a/tests/test_tree_widget.py +++ b/tests/test_tree_widget.py @@ -13,6 +13,55 @@ class TestPublishTreeWidget(PublishApiTestBase): + def test_all_check_state(self): + """ + If we have a bunch of active tasks followed by a bunch of inactive tasks, the addition + of the inactive tasks does not trigger an update of the parent's checkbox (because the update + relies on the checkbox.state_changed and the default is unchecked, so inactive tasks do not + trigger a state change). Test that we are forcing a recalculation to keep the parent's check_state + correct in all situations + """ + tree = self.manager.tree + context = self.manager.context + local_plugin, remote_plugin = self.manager._load_publish_plugins(context) + + item = tree.root_item.create_item("item.parent", "Parent", "Parent") + item.add_task(local_plugin).active = True + item.add_task(remote_plugin).active = False + item = item.create_item("item.child", "Child", "Child") + item.add_task(local_plugin) + item.add_task(remote_plugin) + item = item.create_item("item.grandchild", "Grand Child", "Grand Child") + item.add_task(local_plugin) + item.add_task(remote_plugin) + + tree_widget = self.PublishTreeWidget(None) + tree_widget.set_publish_manager(self.manager) + tree_widget.build_tree() + + from sgtk.platform.qt import QtCore, QtGui + + def iter_check_states(plugin): + yield from ( + tree_item.check_state + for it in QtGui.QTreeWidgetItemIterator(tree_widget) + if ( + (tree_item := it.value()) + and isinstance( + task := tree_item.get_publish_instance(), self.api.PublishTask + ) + and task.plugin == plugin + ) + ) + + tree_widget.set_check_state_for_all_plugins(local_plugin, QtCore.Qt.Checked) + for check_state in iter_check_states(local_plugin): + assert check_state == QtCore.Qt.Checked + + tree_widget.set_check_state_for_all_plugins(remote_plugin, QtCore.Qt.Unchecked) + for check_state in iter_check_states(remote_plugin): + assert check_state == QtCore.Qt.Unchecked + def test_parent_partially_checked(self): """ If we have a bunch of active tasks followed by a bunch of inactive tasks, the addition From 79267422c3516f83e7c2ece38b45f76efdf03043 Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Mon, 9 Feb 2026 11:33:39 +0000 Subject: [PATCH 2/3] Squashed 9bae2cd..8d52283 --- .../publish_tree_widget/publish_tree_widget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tk_multi_publish2/publish_tree_widget/publish_tree_widget.py b/python/tk_multi_publish2/publish_tree_widget/publish_tree_widget.py index a8910628..b3e9d8ef 100644 --- a/python/tk_multi_publish2/publish_tree_widget/publish_tree_widget.py +++ b/python/tk_multi_publish2/publish_tree_widget/publish_tree_widget.py @@ -472,7 +472,7 @@ def set_check_state_for_all_plugins(self, plugin, state): :param plugin: Plugin for which tasks should be manipulated :param state: checkstate to set. """ - logger.debug("Setting state %d for all plugin %s" % (state, plugin)) + logger.debug("Setting state %s for all plugin %s" % (state, plugin)) def _check_r(parent): for child_index in range(parent.childCount()): From 08f50732749678e7d40565f46f24db5fc299a4fd Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Mon, 9 Feb 2026 12:24:40 +0000 Subject: [PATCH 3/3] Tidied iter_check_states in test --- tests/test_tree_widget.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/test_tree_widget.py b/tests/test_tree_widget.py index e96aae16..a9e013bd 100644 --- a/tests/test_tree_widget.py +++ b/tests/test_tree_widget.py @@ -42,17 +42,11 @@ def test_all_check_state(self): from sgtk.platform.qt import QtCore, QtGui def iter_check_states(plugin): - yield from ( - tree_item.check_state - for it in QtGui.QTreeWidgetItemIterator(tree_widget) - if ( - (tree_item := it.value()) - and isinstance( - task := tree_item.get_publish_instance(), self.api.PublishTask - ) - and task.plugin == plugin - ) - ) + for it in QtGui.QTreeWidgetItemIterator(tree_widget): + tree_item = it.value() + task = tree_item.get_publish_instance() + if isinstance(task, self.api.PublishTask) and task.plugin == plugin: + yield tree_item.check_state tree_widget.set_check_state_for_all_plugins(local_plugin, QtCore.Qt.Checked) for check_state in iter_check_states(local_plugin):