added base of validation actions

This commit is contained in:
iLLiCiTiT 2021-08-20 16:45:29 +02:00
parent ab683ed1b6
commit d7303262b4
3 changed files with 119 additions and 20 deletions

View file

@ -575,6 +575,12 @@ class PublisherController:
if self._publish_is_running:
self._stop_publish()
def run_action(self, plugin, action):
# TODO handle result
result = pyblish.plugin.process(
plugin, self._publish_context, None, action.id
)
def _publish_next_process(self):
# Validations of progress before using iterator
# - same conditions may be inside iterator but they may be used

View file

@ -19,7 +19,7 @@ class PublishOverlayFrame(QtWidgets.QFrame):
info_frame = QtWidgets.QFrame(self)
info_frame.setObjectName("PublishOverlay")
validation_errors_widget = ValidationsWidget(self)
validation_errors_widget = ValidationsWidget(controller, self)
content_widget = QtWidgets.QWidget(info_frame)
content_widget.setAttribute(QtCore.Qt.WA_TranslucentBackground)

View file

@ -1,7 +1,30 @@
from Qt import QtWidgets, QtCore
class ValidationErrorTitleWidget(QtWidgets.QFrame):
class _ClickableFrame(QtWidgets.QFrame):
def __init__(self, parent):
super(_ClickableFrame, self).__init__(parent)
self._mouse_pressed = False
def _mouse_release_callback(self):
pass
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self._mouse_pressed = True
super(_ClickableFrame, self).mousePressEvent(event)
def mouseReleaseEvent(self, event):
if self._mouse_pressed:
self._mouse_pressed = False
if self.rect().contains(event.pos()):
self._mouse_release_callback()
super(_ClickableFrame, self).mouseReleaseEvent(event)
class ValidationErrorTitleWidget(_ClickableFrame):
checked = QtCore.Signal(int)
def __init__(self, index, error_info, parent):
@ -49,28 +72,100 @@ class ValidationErrorTitleWidget(QtWidgets.QFrame):
if checked:
self.checked.emit(self._index)
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self._mouse_pressed = True
super(ValidationErrorTitleWidget, self).mousePressEvent(event)
def _mouse_release_callback(self):
self.set_checked(True)
def mouseReleaseEvent(self, event):
if self._mouse_pressed:
self._mouse_pressed = False
if self.rect().contains(event.pos()):
self.set_checked(True)
super(ValidationErrorTitleWidget, self).mouseReleaseEvent(event)
class ActionWidget(_ClickableFrame):
action_clicked = QtCore.Signal(str)
def __init__(self, action, parent):
super(ActionWidget, self).__init__(parent)
self.setObjectName("PublishPluginActionWidget")
self._action_id = action.id
action_label = action.label or action.__name__
# TODO handle icons
# action.icon
lable_widget = QtWidgets.QLabel(action_label, self)
layout = QtWidgets.QHBoxLayout(self)
layout.addWidget(lable_widget)
def _mouse_release_callback(self):
self.action_clicked.emit(self._action_id)
class ValidateActionsWidget(QtWidgets.QFrame):
def __init__(self, controller, parent):
super(ValidateActionsWidget, self).__init__(parent)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
content_widget = QtWidgets.QWidget(self)
content_layout = QtWidgets.QVBoxLayout(content_widget)
layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(content_widget)
self.controller = controller
self._content_widget = content_widget
self._content_layout = content_layout
self._plugin = None
self._actions_mapping = {}
def clear(self):
while self._content_layout.count():
item = self._content_layout.takeAt(0)
widget = item.widget()
if widget:
widget.deleteLater()
self._actions_mapping = {}
def set_plugin(self, plugin):
self.clear()
self._plugin = plugin
if not plugin:
self.setVisible(False)
return
actions = getattr(plugin, "actions", [])
for action in actions:
if not action.active:
continue
if action.on not in ("failed", "all"):
continue
self._actions_mapping[action.id] = action
action_widget = ActionWidget(action, self._content_widget)
action_widget.action_clicked.connect(self._on_action_click)
self._content_layout.addWidget(action_widget)
if self._content_layout.count() > 0:
self.setVisible(True)
self._content_layout.addStretch(1)
else:
self.setVisible(False)
def _on_action_click(self, action_id):
action = self._actions_mapping[action_id]
self.controller.run_action(self._plugin, action)
class ValidationsWidget(QtWidgets.QWidget):
def __init__(self, parent):
def __init__(self, controller, parent):
super(ValidationsWidget, self).__init__(parent)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
errors_widget = QtWidgets.QWidget(self)
errors_widget.setAttribute(QtCore.Qt.WA_TranslucentBackground)
errors_widget.setFixedWidth(200)
errors_layout = QtWidgets.QVBoxLayout(errors_widget)
errors_layout.setContentsMargins(0, 0, 0, 0)
@ -84,9 +179,8 @@ class ValidationsWidget(QtWidgets.QWidget):
error_details_layout = QtWidgets.QVBoxLayout(error_details_widget)
error_details_layout.addWidget(error_details_input)
actions_widget = QtWidgets.QWidget(self)
actions_widget.setAttribute(QtCore.Qt.WA_TranslucentBackground)
actions_layout = QtWidgets.QVBoxLayout(actions_widget)
actions_widget = ValidateActionsWidget(controller, self)
actions_widget.setFixedWidth(140)
layout = QtWidgets.QHBoxLayout(self)
layout.setSpacing(0)
@ -101,7 +195,6 @@ class ValidationsWidget(QtWidgets.QWidget):
self._error_details_widget = error_details_widget
self._error_details_input = error_details_input
self._actions_widget = actions_widget
self._actions_layout = actions_layout
self._title_widgets = {}
self._error_info = {}
@ -118,9 +211,6 @@ class ValidationsWidget(QtWidgets.QWidget):
if widget:
widget.deleteLater()
while self._actions_layout.count():
self._actions_layout.takeAt(0)
self._error_details_widget.setVisible(False)
self._errors_widget.setVisible(False)
self._actions_widget.setVisible(False)
@ -174,7 +264,10 @@ class ValidationsWidget(QtWidgets.QWidget):
self._previous_checked.set_checked(False)
self._previous_checked = self._title_widgets[index]
error_item = self._error_info[index]
self._error_details_input.setMarkdown(
error_item["exception"].description
)
self._actions_widget.set_plugin(error_item["plugin"])