On Wed, Oct 24, 2018 at 9:18 AM likage <[email protected]> wrote:
> 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 :)
>
The overall design of formatting detailed output for a QMessageBox seems
normal to me. Although based just on this code example I am not really sure
why you even need discrete msg{A,B,C} variables when you could just be
appending string literals to the dictionary directly, or reusing the same
msg variable. Still, not much to say about this since you are just building
up error messages in a dictionary and formatting them. All good to me.
If you are asking about the QMessageBox approach in general, I suppose
there are other ways to represent invalid forms, such as coloring the bad
input fields and enabling error text around them. You could even write a
validating QLineEdit that can be set into an 'error' state with a message
and knows how to display itself, and to clear itself once the value changes
again.
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/d4a69a96-087e-489c-b294-0a07d609c67f%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/d4a69a96-087e-489c-b294-0a07d609c67f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0khRpbzE_Qt1tV2LtRJ6ci48p3AV%2B9uXe7ynreN-S%2BSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.