likage
2018-10-23 20:18:52 UTC
Hi all, I am trying to see what is the best way that I can collate results
into a QMessageBox.
This is my code:
test_dict = defaultdict(list)
# Old : msg = ""
msgA = msgB = msgC = None
# Inputs
if all((input_01, input_02)) == False:
msgA = "One or both of the Input fields is/ are empty!"
elif input_01 == input_02:
msgA = "Inputs used in both fields are the same!"
else:
msgA = validate_inputs(
(input_01, input_02)
)
test_dict["Input Issue"].append(msgA)
# Frame Ranges
start = int(start_frame)
end = int(end_frame)
if (start > end) or (end < start):
msgB = (
"Value of Start/Min Frame is larger than the value of "
"End/Max Frame."
)
elif start == end:
msgB = (
"Frame Values are the same"
)
test_dict["Frame Range Issue"].append(msgB)
# Selections
if user_selections:
msgC = validate_user_selections(
input_01,
user_selections
)
test_dict["Selections Issue"].append(msgC)
# Iterates and prints out all error at a go
if test_dict:
err_popup = QtGui.QMessageBox()
err_popup.setIcon(QtGui.QMessageBox.Critical)
err_popup.setWindowTitle("Errors found!")
err_popup.setText("Please rectify the following errors found.")
err_popup.setDetailedText(
"\n".join("{}\n * {}".format(k, '\n\t'.join(v)) for k, v in
test_dict.items())
)
"""
# This will prints out in the following format if there are values
found in each key
Input Issue
xxx
xxx
Frame Range Issue
xxx
Selections Issues
xxx
# If there are no values (no errors) in Frame Range, it will be
ouputted as
Input Issue
xxx
xxx
Selections Issues
xxx
"""
err_popup.setStandardButtons(QtGui.QMessageBox.Ok)
err_popup.exec_()
"""
# Old - Only prints one error that it found in a top-down manner
if msg:
err_popup = QtGui.QMessageBox()
err_popup.setIcon(QtGui.QMessageBox.Critical)
err_popup.setWindowTitle("Errors found!")
err_popup.setText(msg)
err_popup.setStandardButtons(QtGui.QMessageBox.Ok)
err_popup.exec_()
"""
In my Gui, there are a bunch of inputs, mainly QLineEdits and I have
factored in some conditions checking so that if something is incorrectly
inputted, it will prompts up a window.
In my old code, as you have seen, it will only prints and prompts the
QMessageBox, one condition at a time. And so, say if there are 2 errors -
"Inputs" and "Selections", it will only shows "Inputs"
Whereas, I am now trying to implement and have it iterated all the
conditions and shows all errors at one go.
As such, is there a better way that I can go about doing this? While I am
no Python expert but the use of `msgA`. `msgB`, `msgC` does not looks very
nice in this context...
Many thanks in advance for any replies :)
into a QMessageBox.
This is my code:
test_dict = defaultdict(list)
# Old : msg = ""
msgA = msgB = msgC = None
# Inputs
if all((input_01, input_02)) == False:
msgA = "One or both of the Input fields is/ are empty!"
elif input_01 == input_02:
msgA = "Inputs used in both fields are the same!"
else:
msgA = validate_inputs(
(input_01, input_02)
)
test_dict["Input Issue"].append(msgA)
# Frame Ranges
start = int(start_frame)
end = int(end_frame)
if (start > end) or (end < start):
msgB = (
"Value of Start/Min Frame is larger than the value of "
"End/Max Frame."
)
elif start == end:
msgB = (
"Frame Values are the same"
)
test_dict["Frame Range Issue"].append(msgB)
# Selections
if user_selections:
msgC = validate_user_selections(
input_01,
user_selections
)
test_dict["Selections Issue"].append(msgC)
# Iterates and prints out all error at a go
if test_dict:
err_popup = QtGui.QMessageBox()
err_popup.setIcon(QtGui.QMessageBox.Critical)
err_popup.setWindowTitle("Errors found!")
err_popup.setText("Please rectify the following errors found.")
err_popup.setDetailedText(
"\n".join("{}\n * {}".format(k, '\n\t'.join(v)) for k, v in
test_dict.items())
)
"""
# This will prints out in the following format if there are values
found in each key
Input Issue
xxx
xxx
Frame Range Issue
xxx
Selections Issues
xxx
# If there are no values (no errors) in Frame Range, it will be
ouputted as
Input Issue
xxx
xxx
Selections Issues
xxx
"""
err_popup.setStandardButtons(QtGui.QMessageBox.Ok)
err_popup.exec_()
"""
# Old - Only prints one error that it found in a top-down manner
if msg:
err_popup = QtGui.QMessageBox()
err_popup.setIcon(QtGui.QMessageBox.Critical)
err_popup.setWindowTitle("Errors found!")
err_popup.setText(msg)
err_popup.setStandardButtons(QtGui.QMessageBox.Ok)
err_popup.exec_()
"""
In my Gui, there are a bunch of inputs, mainly QLineEdits and I have
factored in some conditions checking so that if something is incorrectly
inputted, it will prompts up a window.
In my old code, as you have seen, it will only prints and prompts the
QMessageBox, one condition at a time. And so, say if there are 2 errors -
"Inputs" and "Selections", it will only shows "Inputs"
Whereas, I am now trying to implement and have it iterated all the
conditions and shows all errors at one go.
As such, is there a better way that I can go about doing this? While I am
no Python expert but the use of `msgA`. `msgB`, `msgC` does not looks very
nice in this context...
Many thanks in advance for any replies :)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d4a69a96-087e-489c-b294-0a07d609c67f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d4a69a96-087e-489c-b294-0a07d609c67f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.