Skip to content

Commit fbbe35f

Browse files
committed
Shifter: Custom Step Error update UI and improved feedback #601
1 parent 3114114 commit fbbe35f

1 file changed

Lines changed: 190 additions & 40 deletions

File tree

‎release/scripts/mgear/shifter/custom_step_widget.py‎

Lines changed: 190 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,6 +3541,159 @@ def get_selected_template(self):
35413541
return self._template_combo.currentData()
35423542

35433543

3544+
# ============================================================================
3545+
# Custom Step Error Dialog
3546+
# ============================================================================
3547+
3548+
3549+
class CustomStepErrorDialog(QtWidgets.QDialog):
3550+
"""Dialog for displaying custom step execution errors.
3551+
3552+
Shows the step name, error type, and traceback in a well-formatted layout.
3553+
"""
3554+
3555+
CONTINUE = "Continue"
3556+
STOP_BUILD = "Stop Build"
3557+
EDIT = "Edit"
3558+
3559+
def __init__(
3560+
self, step_path, error_type, error_args, traceback_text, parent=None
3561+
):
3562+
"""Initialize the error dialog.
3563+
3564+
Args:
3565+
step_path: Path to the failing custom step
3566+
error_type: The exception type name
3567+
error_args: The exception arguments
3568+
traceback_text: Full traceback text
3569+
parent: Parent widget
3570+
"""
3571+
super(CustomStepErrorDialog, self).__init__(parent)
3572+
self.setWindowTitle("Custom Step Error")
3573+
self.setMinimumWidth(600)
3574+
self.setMinimumHeight(400)
3575+
3576+
self._result = self.CONTINUE
3577+
self._setup_ui(step_path, error_type, error_args, traceback_text)
3578+
3579+
def _setup_ui(self, step_path, error_type, error_args, traceback_text):
3580+
"""Setup the dialog UI."""
3581+
layout = QtWidgets.QVBoxLayout(self)
3582+
layout.setSpacing(12)
3583+
layout.setContentsMargins(16, 16, 16, 16)
3584+
3585+
# Header with error icon and title
3586+
header_layout = QtWidgets.QHBoxLayout()
3587+
icon_label = QtWidgets.QLabel()
3588+
icon = self.style().standardIcon(QtWidgets.QStyle.SP_MessageBoxCritical)
3589+
icon_label.setPixmap(icon.pixmap(32, 32))
3590+
header_layout.addWidget(icon_label)
3591+
3592+
title_label = QtWidgets.QLabel("Custom Step Failed")
3593+
title_font = title_label.font()
3594+
title_font.setPointSize(14)
3595+
title_font.setBold(True)
3596+
title_label.setFont(title_font)
3597+
header_layout.addWidget(title_label)
3598+
header_layout.addStretch()
3599+
layout.addLayout(header_layout)
3600+
3601+
# Step path section
3602+
step_group = QtWidgets.QGroupBox("Failed Step")
3603+
step_layout = QtWidgets.QVBoxLayout(step_group)
3604+
step_label = QtWidgets.QLabel(step_path)
3605+
step_label.setWordWrap(True)
3606+
step_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
3607+
step_font = step_label.font()
3608+
step_font.setFamily("Consolas, Monaco, monospace")
3609+
step_label.setFont(step_font)
3610+
step_label.setStyleSheet(
3611+
"QLabel { background-color: #2d2d30; padding: 8px; "
3612+
"border-radius: 4px; color: #ff6b6b; }"
3613+
)
3614+
step_layout.addWidget(step_label)
3615+
layout.addWidget(step_group)
3616+
3617+
# Error type section
3618+
error_group = QtWidgets.QGroupBox("Error")
3619+
error_layout = QtWidgets.QVBoxLayout(error_group)
3620+
error_text = "{}: {}".format(error_type, error_args)
3621+
error_label = QtWidgets.QLabel(error_text)
3622+
error_label.setWordWrap(True)
3623+
error_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
3624+
error_label.setStyleSheet(
3625+
"QLabel { background-color: #2d2d30; padding: 8px; "
3626+
"border-radius: 4px; }"
3627+
)
3628+
error_layout.addWidget(error_label)
3629+
layout.addWidget(error_group)
3630+
3631+
# Traceback section
3632+
tb_group = QtWidgets.QGroupBox("Traceback")
3633+
tb_layout = QtWidgets.QVBoxLayout(tb_group)
3634+
tb_text = QtWidgets.QPlainTextEdit()
3635+
tb_text.setPlainText(traceback_text)
3636+
tb_text.setReadOnly(True)
3637+
tb_text.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
3638+
tb_font = tb_text.font()
3639+
tb_font.setFamily("Consolas, Monaco, monospace")
3640+
tb_font.setPointSize(9)
3641+
tb_text.setFont(tb_font)
3642+
tb_text.setMinimumHeight(150)
3643+
tb_layout.addWidget(tb_text)
3644+
layout.addWidget(tb_group)
3645+
3646+
# Question label
3647+
question_label = QtWidgets.QLabel("Continue with next step?")
3648+
question_label.setAlignment(QtCore.Qt.AlignCenter)
3649+
layout.addWidget(question_label)
3650+
3651+
# Buttons
3652+
button_layout = QtWidgets.QHBoxLayout()
3653+
button_layout.addStretch()
3654+
3655+
continue_btn = QtWidgets.QPushButton("Continue")
3656+
continue_btn.setMinimumWidth(100)
3657+
continue_btn.clicked.connect(self._on_continue)
3658+
button_layout.addWidget(continue_btn)
3659+
3660+
stop_btn = QtWidgets.QPushButton("Stop Build")
3661+
stop_btn.setMinimumWidth(100)
3662+
stop_btn.clicked.connect(self._on_stop_build)
3663+
button_layout.addWidget(stop_btn)
3664+
3665+
edit_btn = QtWidgets.QPushButton("Edit")
3666+
edit_btn.setMinimumWidth(100)
3667+
edit_btn.clicked.connect(self._on_edit)
3668+
button_layout.addWidget(edit_btn)
3669+
3670+
button_layout.addStretch()
3671+
layout.addLayout(button_layout)
3672+
3673+
def _on_continue(self):
3674+
"""Handle Continue button click."""
3675+
self._result = self.CONTINUE
3676+
self.accept()
3677+
3678+
def _on_stop_build(self):
3679+
"""Handle Stop Build button click."""
3680+
self._result = self.STOP_BUILD
3681+
self.accept()
3682+
3683+
def _on_edit(self):
3684+
"""Handle Edit button click."""
3685+
self._result = self.EDIT
3686+
self.accept()
3687+
3688+
def get_result(self):
3689+
"""Get the dialog result.
3690+
3691+
Returns:
3692+
str: One of CONTINUE, STOP_BUILD, or EDIT
3693+
"""
3694+
return self._result
3695+
3696+
35443697
# ============================================================================
35453698
# Group Selection Dialog
35463699
# ============================================================================
@@ -4281,21 +4434,23 @@ def runStep(cls, stepPath, customStepDic):
42814434
Returns:
42824435
True if build should stop, False otherwise
42834436
"""
4437+
# Resolve the full path before try block so it's available for Edit
4438+
if sys.platform.startswith("darwin"):
4439+
stepPath = stepPath.replace("\\", "/")
4440+
4441+
fileName = os.path.split(stepPath)[1].split(".")[0]
4442+
4443+
if os.environ.get(MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""):
4444+
runPath = os.path.join(
4445+
os.environ.get(MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""),
4446+
stepPath,
4447+
)
4448+
else:
4449+
runPath = stepPath
4450+
42844451
try:
42854452
with pm.UndoChunk():
42864453
pm.displayInfo("EXEC: Executing custom step: %s" % stepPath)
4287-
if sys.platform.startswith("darwin"):
4288-
stepPath = stepPath.replace("\\", "/")
4289-
4290-
fileName = os.path.split(stepPath)[1].split(".")[0]
4291-
4292-
if os.environ.get(MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""):
4293-
runPath = os.path.join(
4294-
os.environ.get(MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""),
4295-
stepPath,
4296-
)
4297-
else:
4298-
runPath = stepPath
42994454

43004455
customStep = imp.load_source(fileName, runPath)
43014456
if hasattr(customStep, "CustomShifterStep"):
@@ -4321,36 +4476,31 @@ def runStep(cls, stepPath, customStepDic):
43214476
)
43224477

43234478
except Exception as ex:
4324-
template = "An exception of type {0} occurred. "
4325-
"Arguments:\n{1!r}"
4326-
message = template.format(type(ex).__name__, ex.args)
4327-
pm.displayError(message)
4328-
pm.displayError(traceback.format_exc())
4329-
cont = pm.confirmBox(
4330-
"FAIL: Custom Step Fail",
4331-
"The step:%s has failed. Continue with next step?" % stepPath
4332-
+ "\n\n"
4333-
+ message
4334-
+ "\n\n"
4335-
+ traceback.format_exc(),
4336-
"Continue",
4337-
"Stop Build",
4338-
"Edit",
4339-
"Try Again!",
4479+
error_type = type(ex).__name__
4480+
error_args = str(ex.args)
4481+
traceback_text = traceback.format_exc()
4482+
pm.displayError(
4483+
"An exception of type {} occurred. Arguments: {}".format(
4484+
error_type, error_args
4485+
)
4486+
)
4487+
pm.displayError(traceback_text)
4488+
4489+
dialog = CustomStepErrorDialog(
4490+
step_path=stepPath,
4491+
error_type=error_type,
4492+
error_args=error_args,
4493+
traceback_text=traceback_text,
4494+
parent=pyqt.maya_main_window(),
43404495
)
4341-
if cont == "Stop Build":
4496+
dialog.exec_()
4497+
result = dialog.get_result()
4498+
4499+
if result == CustomStepErrorDialog.STOP_BUILD:
43424500
return True
4343-
elif cont == "Edit":
4344-
cls._editFile(stepPath)
4345-
elif cont == "Try Again!":
4346-
try:
4347-
pm.undo()
4348-
except Exception:
4349-
pass
4350-
pm.displayInfo("Trying again! : {}".format(stepPath))
4351-
inception = cls.runStep(stepPath, customStepDic)
4352-
if inception:
4353-
return True
4501+
elif result == CustomStepErrorDialog.EDIT:
4502+
cls._editFile(runPath)
4503+
return False
43544504
else:
43554505
return False
43564506

0 commit comments

Comments
 (0)