From 6463935420ea95c2debfad6d81cc0d5925bb7f37 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Fri, 12 Aug 2016 16:46:50 +0100 Subject: [PATCH 1/8] action icons visible --- pyblish_lite/delegate.py | 11 +++++++++++ pyblish_lite/model.py | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/pyblish_lite/delegate.py b/pyblish_lite/delegate.py index 2dfc6d6..68061b1 100644 --- a/pyblish_lite/delegate.py +++ b/pyblish_lite/delegate.py @@ -36,6 +36,7 @@ "record": awesome["circle"], "file": awesome["file"], "error": awesome["exclamation-triangle"], + "action": awesome["adn"], } @@ -93,6 +94,16 @@ def paint(self, painter, option, index): painter.setPen(QtGui.QPen(font_color)) painter.drawText(label_rect, label) + # Draw icon + if index.data(model.ActionIconVisible): + icon = icons["action"] + icon_rect = QtCore.QRectF(option.rect.adjusted( + label_rect.width() + 1, label_rect.height() / 3, 0, 0)) + + painter.setFont(fonts["smallAwesome"]) + painter.setPen(QtGui.QPen(colors["idle"])) + painter.drawText(icon_rect, icon) + # Draw checkbox pen = QtGui.QPen(check_color, 1) painter.setPen(pen) diff --git a/pyblish_lite/model.py b/pyblish_lite/model.py index bd74e09..f5d7901 100644 --- a/pyblish_lite/model.py +++ b/pyblish_lite/model.py @@ -62,6 +62,7 @@ # Available and context-sensitive actions Actions = QtCore.Qt.UserRole + 9 +ActionIconVisible = QtCore.Qt.UserRole + 13 Docstring = QtCore.Qt.UserRole + 12 # LOG RECORDS @@ -193,6 +194,30 @@ def data(self, index, role): if role == Icon: return awesome.get(getattr(item, "icon", "")) + if role == ActionIconVisible: + + # Can only run actions on active plug-ins. + if not item.active: + return + + actions = list(item.actions) + + # Context specific actions + for action in actions: + if action.on == "failed" and not item._has_failed: + actions.remove(action) + if action.on == "succeeded" and not item._has_succeeded: + actions.remove(action) + if action.on == "processed" and not item._has_processed: + actions.remove(action) + if action.on == "notProcessed" and item._has_processed: + actions.remove(action) + + if actions: + return True + + return False + if role == Actions: # Can only run actions on active plug-ins. From 6c6d9967ad57fbff8bda2b7b0196862ce8db8435 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Mon, 15 Aug 2016 10:54:56 +0100 Subject: [PATCH 2/8] working version of action icons --- pyblish_lite/control.py | 7 ++++--- pyblish_lite/delegate.py | 16 ++++++++++++++-- pyblish_lite/model.py | 38 +++++++++++++++++++++++++++++++++++++- pyblish_lite/window.py | 17 ++++++++++++++++- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/pyblish_lite/control.py b/pyblish_lite/control.py index f1c140a..928f2e3 100644 --- a/pyblish_lite/control.py +++ b/pyblish_lite/control.py @@ -32,7 +32,8 @@ class Controller(QtCore.QObject): was_reset = QtCore.Signal() was_validated = QtCore.Signal() was_published = QtCore.Signal() - was_acted = QtCore.Signal() + was_acted = QtCore.Signal(dict) + action_processing = QtCore.Signal(object) # Emitted when processing has finished finished = QtCore.Signal() @@ -87,11 +88,11 @@ def publish(self): def act(self, plugin, action): context = self.context + self.action_processing.emit(plugin) def on_next(): result = pyblish.plugin.process(plugin, context, None, action.id) - self.was_processed.emit(result) - util.defer(500, self.was_acted.emit) + self.was_acted.emit(result) util.defer(100, on_next) diff --git a/pyblish_lite/delegate.py b/pyblish_lite/delegate.py index 68061b1..c647f0f 100644 --- a/pyblish_lite/delegate.py +++ b/pyblish_lite/delegate.py @@ -94,14 +94,26 @@ def paint(self, painter, option, index): painter.setPen(QtGui.QPen(font_color)) painter.drawText(label_rect, label) - # Draw icon + # Draw action icon if index.data(model.ActionIconVisible): icon = icons["action"] icon_rect = QtCore.QRectF(option.rect.adjusted( label_rect.width() + 1, label_rect.height() / 3, 0, 0)) painter.setFont(fonts["smallAwesome"]) - painter.setPen(QtGui.QPen(colors["idle"])) + state = index.data(model.ActionState) + color = colors["inactive"] + if state == "idle": + color = colors["idle"] + if state == "processing": + color = colors["active"] + if state == "succeeded": + color = colors["ok"] + if state == "failed": + color = colors["warning"] + + painter.setPen(QtGui.QPen(color)) + painter.drawText(icon_rect, icon) # Draw checkbox diff --git a/pyblish_lite/model.py b/pyblish_lite/model.py index f5d7901..5deb8ec 100644 --- a/pyblish_lite/model.py +++ b/pyblish_lite/model.py @@ -63,6 +63,11 @@ # Available and context-sensitive actions Actions = QtCore.Qt.UserRole + 9 ActionIconVisible = QtCore.Qt.UserRole + 13 +ActionState = QtCore.Qt.UserRole + 14 +ActionIdle = QtCore.Qt.UserRole + 15 +ActionProcessing = QtCore.Qt.UserRole + 16 +ActionFailed = QtCore.Qt.UserRole + 17 +ActionSucceeded = QtCore.Qt.UserRole + 18 Docstring = QtCore.Qt.UserRole + 12 # LOG RECORDS @@ -139,6 +144,10 @@ def __init__(self, parent=None): HasProcessed: "_has_processed", HasSucceeded: "_has_succeeded", HasFailed: "_has_failed", + ActionIdle: "_action_idle", + ActionProcessing: "_action_processing", + ActionFailed: "_action_failed", + ActionSucceeded: "_action_succeeded", } def store_checkstate(self): @@ -183,6 +192,11 @@ def append(self, item): item._has_failed = False item._type = "plugin" + item._action_idle = True + item._action_processing = False + item._action_succeeded = False + item._action_failed = False + return super(Plugin, self).append(item) def data(self, index, role): @@ -194,6 +208,21 @@ def data(self, index, role): if role == Icon: return awesome.get(getattr(item, "icon", "")) + if role == ActionState: + + state = "inactive" + + if item._action_idle: + state = "idle" + if item._action_processing: + state = "processing" + if item._action_failed: + state = "failed" + if item._action_succeeded: + state = "succeeded" + + return state + if role == ActionIconVisible: # Can only run actions on active plug-ins. @@ -293,11 +322,18 @@ def setData(self, index, value, role): else: self.dataChanged.emit(index, index, [role]) - def update_with_result(self, result): + def update_with_result(self, result, action=False): item = result["plugin"] index = self.items.index(item) index = self.createIndex(index, 0) + + if action: + self.setData(index, False, ActionProcessing) + self.setData(index, result["success"], ActionSucceeded) + self.setData(index, not result["success"], ActionFailed) + return + self.setData(index, False, IsIdle) self.setData(index, False, IsProcessing) self.setData(index, True, HasProcessed) diff --git a/pyblish_lite/window.py b/pyblish_lite/window.py index fc0bf1b..92d2167 100644 --- a/pyblish_lite/window.py +++ b/pyblish_lite/window.py @@ -490,6 +490,8 @@ def __init__(self, controller, parent=None): controller.was_acted.connect(self.on_was_acted) controller.finished.connect(self.on_finished) + controller.action_processing.connect(self.on_action_processing) + # Discovery happens synchronously during reset, that's # why it's important that this connection is triggered # right away. @@ -811,11 +813,24 @@ def on_was_processed(self, result): models["instances"].update_with_result(result) models["terminal"].update_with_result(result) - def on_was_acted(self): + def on_action_processing(self, plugin): + plugin_model = self.data["models"]["plugins"] + index = plugin_model.items.index(plugin) + index = plugin_model.createIndex(index, 0) + plugin_model.setData(index, False, model.ActionIdle) + plugin_model.setData(index, True, model.ActionProcessing) + plugin_model.setData(index, False, model.ActionSucceeded) + plugin_model.setData(index, False, model.ActionFailed) + + def on_was_acted(self, result): buttons = self.data["buttons"] buttons["reset"].show() buttons["stop"].hide() + models = self.data["models"] + models["plugins"].update_with_result(result, action=True) + models["terminal"].update_with_result(result) + self.on_finished() def on_finished(self): From 615ecd1d19ea9430ae58a450bf20afcfa45cf13c Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Tue, 16 Aug 2016 10:50:47 +0100 Subject: [PATCH 3/8] moved action items --- pyblish_lite/model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyblish_lite/model.py b/pyblish_lite/model.py index 5deb8ec..abb0602 100644 --- a/pyblish_lite/model.py +++ b/pyblish_lite/model.py @@ -144,10 +144,6 @@ def __init__(self, parent=None): HasProcessed: "_has_processed", HasSucceeded: "_has_succeeded", HasFailed: "_has_failed", - ActionIdle: "_action_idle", - ActionProcessing: "_action_processing", - ActionFailed: "_action_failed", - ActionSucceeded: "_action_succeeded", } def store_checkstate(self): @@ -179,6 +175,10 @@ def __init__(self): self.schema.update({ IsChecked: "active", Docstring: "__doc__", + ActionIdle: "_action_idle", + ActionProcessing: "_action_processing", + ActionFailed: "_action_failed", + ActionSucceeded: "_action_succeeded", }) def append(self, item): From 45d96d9b27e32de52b530ef7ab40613741dffe50 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Thu, 18 Aug 2016 08:05:03 +0100 Subject: [PATCH 4/8] Remove action_processing There are a few things I changed unneccessarily, such as your choice of model roles, but we should take another look at those as well. As you can see, most of what needs to happen happens with just two roles; isVisible and hasError. This is similar to how pyblish-qml does things. --- pyblish_lite/control.py | 2 -- pyblish_lite/delegate.py | 24 +++++++++++------------- pyblish_lite/window.py | 37 ++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/pyblish_lite/control.py b/pyblish_lite/control.py index 928f2e3..b7a6e2b 100644 --- a/pyblish_lite/control.py +++ b/pyblish_lite/control.py @@ -33,7 +33,6 @@ class Controller(QtCore.QObject): was_validated = QtCore.Signal() was_published = QtCore.Signal() was_acted = QtCore.Signal(dict) - action_processing = QtCore.Signal(object) # Emitted when processing has finished finished = QtCore.Signal() @@ -88,7 +87,6 @@ def publish(self): def act(self, plugin, action): context = self.context - self.action_processing.emit(plugin) def on_next(): result = pyblish.plugin.process(plugin, context, None, action.id) diff --git a/pyblish_lite/delegate.py b/pyblish_lite/delegate.py index c647f0f..4ee502b 100644 --- a/pyblish_lite/delegate.py +++ b/pyblish_lite/delegate.py @@ -96,25 +96,23 @@ def paint(self, painter, option, index): # Draw action icon if index.data(model.ActionIconVisible): - icon = icons["action"] - icon_rect = QtCore.QRectF(option.rect.adjusted( - label_rect.width() + 1, label_rect.height() / 3, 0, 0)) + painter.save() - painter.setFont(fonts["smallAwesome"]) - state = index.data(model.ActionState) - color = colors["inactive"] - if state == "idle": + if index.data(model.ActionIdle): color = colors["idle"] - if state == "processing": - color = colors["active"] - if state == "succeeded": - color = colors["ok"] - if state == "failed": + elif index.data(model.ActionFailed): color = colors["warning"] + else: + color = colors["ok"] + painter.setFont(fonts["smallAwesome"]) painter.setPen(QtGui.QPen(color)) - painter.drawText(icon_rect, icon) + icon_rect = QtCore.QRectF(option.rect.adjusted( + label_rect.width() + 1, label_rect.height() / 3, 0, 0)) + painter.drawText(icon_rect, icons["action"]) + + painter.restore() # Draw checkbox pen = QtGui.QPen(check_color, 1) diff --git a/pyblish_lite/window.py b/pyblish_lite/window.py index 92d2167..d090e55 100644 --- a/pyblish_lite/window.py +++ b/pyblish_lite/window.py @@ -490,8 +490,6 @@ def __init__(self, controller, parent=None): controller.was_acted.connect(self.on_was_acted) controller.finished.connect(self.on_finished) - controller.action_processing.connect(self.on_action_processing) - # Discovery happens synchronously during reset, that's # why it's important that this connection is triggered # right away. @@ -721,6 +719,7 @@ def on_plugin_action_menu_requested(self, pos): menu = QtWidgets.QMenu(self) plugin = self.data["models"]["plugins"].items[index.row()] + print("plugin is: %s" % plugin) for action in actions: qaction = QtWidgets.QAction(action.label or action.__name__, self) @@ -813,22 +812,21 @@ def on_was_processed(self, result): models["instances"].update_with_result(result) models["terminal"].update_with_result(result) - def on_action_processing(self, plugin): - plugin_model = self.data["models"]["plugins"] - index = plugin_model.items.index(plugin) - index = plugin_model.createIndex(index, 0) - plugin_model.setData(index, False, model.ActionIdle) - plugin_model.setData(index, True, model.ActionProcessing) - plugin_model.setData(index, False, model.ActionSucceeded) - plugin_model.setData(index, False, model.ActionFailed) - def on_was_acted(self, result): buttons = self.data["buttons"] buttons["reset"].show() buttons["stop"].hide() + # Update action with result + model_ = self.data["models"]["plugins"] + + index = model_.items.index(result["plugin"]) + index = model_.createIndex(index, 0) + + model_.setData(index, not result["success"], model.ActionFailed) + models = self.data["models"] - models["plugins"].update_with_result(result, action=True) + # models["plugins"].update_with_result(result) models["terminal"].update_with_result(result) self.on_finished() @@ -888,7 +886,7 @@ def publish(self): util.defer(5, self.controller.publish) def act(self, plugin, action): - self.info("Preparing action..") + self.info("Preparing %s.." % action) for button in self.data["buttons"].values(): button.hide() @@ -896,7 +894,20 @@ def act(self, plugin, action): self.data["buttons"]["stop"].show() self.controller.is_running = True + # Cause view to update, but it won't visually + # happen until Qt is given time to idle.. + model_ = self.data["models"]["plugins"] + + index = model_.items.index(plugin) + index = model_.createIndex(index, 0) + + for key, value in {model.ActionIdle: False, + model.ActionFailed: False}.items(): + model_.setData(index, value, key) + + # Give Qt time to draw util.defer(100, lambda: self.controller.act(plugin, action)) + self.info("Action prepared.") def closeEvent(self, event): From f5438dc0716e3a5c83fe8a39bfc5dd4ee9f8e0c2 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Mon, 22 Aug 2016 15:59:37 +0100 Subject: [PATCH 5/8] working version of action processing from model.IsProcessing --- pyblish_lite/delegate.py | 2 ++ pyblish_lite/window.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pyblish_lite/delegate.py b/pyblish_lite/delegate.py index 4ee502b..d1d2063 100644 --- a/pyblish_lite/delegate.py +++ b/pyblish_lite/delegate.py @@ -100,6 +100,8 @@ def paint(self, painter, option, index): if index.data(model.ActionIdle): color = colors["idle"] + elif index.data(model.IsProcessing): + color = colors["active"] elif index.data(model.ActionFailed): color = colors["warning"] else: diff --git a/pyblish_lite/window.py b/pyblish_lite/window.py index d090e55..35e8e97 100644 --- a/pyblish_lite/window.py +++ b/pyblish_lite/window.py @@ -824,9 +824,9 @@ def on_was_acted(self, result): index = model_.createIndex(index, 0) model_.setData(index, not result["success"], model.ActionFailed) + model_.setData(index, False, model.IsProcessing) models = self.data["models"] - # models["plugins"].update_with_result(result) models["terminal"].update_with_result(result) self.on_finished() @@ -902,7 +902,8 @@ def act(self, plugin, action): index = model_.createIndex(index, 0) for key, value in {model.ActionIdle: False, - model.ActionFailed: False}.items(): + model.ActionFailed: False, + model.IsProcessing: True}.items(): model_.setData(index, value, key) # Give Qt time to draw From 569b69671f6a2414f1fb08de02156b15bb3e3b46 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Mon, 22 Aug 2016 16:16:01 +0100 Subject: [PATCH 6/8] strip unnecessary roles for actions --- pyblish_lite/model.py | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/pyblish_lite/model.py b/pyblish_lite/model.py index abb0602..215f59d 100644 --- a/pyblish_lite/model.py +++ b/pyblish_lite/model.py @@ -63,11 +63,8 @@ # Available and context-sensitive actions Actions = QtCore.Qt.UserRole + 9 ActionIconVisible = QtCore.Qt.UserRole + 13 -ActionState = QtCore.Qt.UserRole + 14 ActionIdle = QtCore.Qt.UserRole + 15 -ActionProcessing = QtCore.Qt.UserRole + 16 ActionFailed = QtCore.Qt.UserRole + 17 -ActionSucceeded = QtCore.Qt.UserRole + 18 Docstring = QtCore.Qt.UserRole + 12 # LOG RECORDS @@ -176,9 +173,7 @@ def __init__(self): IsChecked: "active", Docstring: "__doc__", ActionIdle: "_action_idle", - ActionProcessing: "_action_processing", ActionFailed: "_action_failed", - ActionSucceeded: "_action_succeeded", }) def append(self, item): @@ -208,21 +203,6 @@ def data(self, index, role): if role == Icon: return awesome.get(getattr(item, "icon", "")) - if role == ActionState: - - state = "inactive" - - if item._action_idle: - state = "idle" - if item._action_processing: - state = "processing" - if item._action_failed: - state = "failed" - if item._action_succeeded: - state = "succeeded" - - return state - if role == ActionIconVisible: # Can only run actions on active plug-ins. @@ -328,12 +308,6 @@ def update_with_result(self, result, action=False): index = self.items.index(item) index = self.createIndex(index, 0) - if action: - self.setData(index, False, ActionProcessing) - self.setData(index, result["success"], ActionSucceeded) - self.setData(index, not result["success"], ActionFailed) - return - self.setData(index, False, IsIdle) self.setData(index, False, IsProcessing) self.setData(index, True, HasProcessed) From 58553ad82734d2427813256099910f06521f105f Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Thu, 22 Sep 2016 18:21:25 +0100 Subject: [PATCH 7/8] Update version.py --- pyblish_lite/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyblish_lite/version.py b/pyblish_lite/version.py index 1d327f8..6d8b351 100644 --- a/pyblish_lite/version.py +++ b/pyblish_lite/version.py @@ -1,6 +1,6 @@ VERSION_MAJOR = 0 -VERSION_MINOR = 3 +VERSION_MINOR = 4 VERSION_PATCH = 3 version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) From afaee09a08c36be81c1283c856cebaeefdf7005d Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Thu, 22 Sep 2016 18:24:57 +0100 Subject: [PATCH 8/8] Update version.py --- pyblish_lite/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyblish_lite/version.py b/pyblish_lite/version.py index 6d8b351..9c2abd1 100644 --- a/pyblish_lite/version.py +++ b/pyblish_lite/version.py @@ -1,7 +1,7 @@ VERSION_MAJOR = 0 VERSION_MINOR = 4 -VERSION_PATCH = 3 +VERSION_PATCH = 0 version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) version = '%i.%i.%i' % version_info