Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread likage
Got it, thank you.

I did not read the post correctly and thought it was a case of just dict 
type instead of defaultdict.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/445125c7-2e29-4fb8-af66-b601d7d208f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread Justin Israel
On Wed, Oct 24, 2018 at 11:46 AM likage  wrote:

> I have 2 questions, should have done more testing on my end..
>
> 1. I am trying to understand the use of `.append'. I know that it adds
> things to list, but when I was looking thru the documentation page -
> https://docs.python.org/2/library/collections.html, even in the example,
> it is mostly `dict_name['key name'].append(value)` but nowhere near the
> method you have used.. Am I looking at the wrong doc?
>

It isn't actually part of the collections.defaultdict class. You have
constructed:

dict_name = defaultdict(list)

 That means when you do

dict_name['key name']

you get a list returned to you. Because python treats everything as first
class objects, you can assign the list.append function to a variable

aList = dict_name['key name']
append = aList.append

And its actually a documented performance note:
https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Avoiding_dots...


>
> 2. For Method #2 you have proposed, instead of using a defaultdict(list),
> I used a normal dictionary {} and I got the KeyError message.
> Is this because when using normal dictionary, generally it should be
> `dict_name['key name'] = value`, and since we are not doing this way and
> hence the error?
>

I don't recall proposing that you stop using defaultdict. My example
expected that it would be a defaultdict.


>
> Pardon the noob questions as I am trying to make sense of things
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/3a7ad9d5-118b-4617-9806-e5189992b15d%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0O_uCsJ01c3yd8N%3DtQG8SBv2T5tjNUXj0Vf-O_DkAYjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread likage
I have 2 questions, should have done more testing on my end..

1. I am trying to understand the use of `.append'. I know that it adds 
things to list, but when I was looking thru the documentation page 
- https://docs.python.org/2/library/collections.html, even in the example, 
it is mostly `dict_name['key name'].append(value)` but nowhere near the 
method you have used.. Am I looking at the wrong doc?

2. For Method #2 you have proposed, instead of using a defaultdict(list), I 
used a normal dictionary {} and I got the KeyError message.
Is this because when using normal dictionary, generally it should be 
`dict_name['key name'] = value`, and since we are not doing this way and 
hence the error?

Pardon the noob questions as I am trying to make sense of things

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/3a7ad9d5-118b-4617-9806-e5189992b15d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread Justin Israel
On Wed, Oct 24, 2018 at 11:25 AM likage  wrote:

> I was not aware that you could use `append = test_dict["Input
> Issue"].append` as you have demonstrated in Example #2.
> Learnt something new today :D
>

Hey, its Python. You can do anything you want :-)


> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/0d3950d2-41a1-4618-91b3-643d9836b00a%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2A1nC%3DeswCBSW%2B3dNXE%3DNKBSxb4FtqPPkA4h71hTMAEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread likage
I was not aware that you could use `append = test_dict["Input 
Issue"].append` as you have demonstrated in Example #2.
Learnt something new today :D

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/0d3950d2-41a1-4618-91b3-643d9836b00a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread Justin Israel
That last reply didn't format nicely:

# Example 1
if all((input_01, input_02)) == False:
msg = "One or both of the Input fields is/ are empty!"
elif input_01 == input_02:
msg = "Inputs used in both fields are the same!"
else:
msg = validate_inputs((input_01, input_02))
if msg:
test_dict["Input Issue"].append(msg)

if next_test():
msg = 'error'
if msg:
test_dict["Frame Range Issue"].append(msg)

# Example 2
append = test_dict["Input Issue"].append
if all((input_01, input_02)) == False:
append("One or both of the Input fields is/ are empty!")
elif input_01 == input_02:
append("Inputs used in both fields are the same!")
else:
append(validate_inputs((input_01, input_02)))

append = test_dict["Frame Range Issue"].append
if next_test():
append('error')





On Wed, Oct 24, 2018 at 10:29 AM Justin Israel 
wrote:

> On Wed, Oct 24, 2018 at 10:09 AM likage  wrote:
>
>> Hi Justin, thanks for the reply.
>> I use msg{A,B,C} because if any one of the condition passed, the msg will
>> get appended with the next in-line error.
>>
>> Eg. If only frame range fails, my `test_dict` will return as follows:
>> {'Frame Range Issue': [None,
>>'Value of Start/Min Frame is larger than the value
>> of End/Max Frame.'],
>>  'Namespace Issue': [None, None],
>>  'Selections Issue': [None,
>>   'Value of Start/Min Frame is larger than the value
>> of End/Max Frame.']}
>>
>> And hence my usage of A,B,C to differentiate them as I can't reuse the
>> same variable in which I am using defaultdict to differentiate them in this
>> case.
>>
>
> I can only base my reply on your code example, which shows msg{A,B,C}
> being defaulted to  None, conditionally set to a message, and then always
> being appended immediately. So this translates in my brain to a single temp
> var or a string literally, conditionally being appended to each category
> key if there is a message to report. The code example doesn't prove the
> need for multiple variables.
>
>
>> appending string literals to the dictionary directly
>>>
>> Could you kindly elaborate more on this?
>>
>
> # Example 1
>
> if all((input_01, input_02)) == False
>
> :
> msg = "One or both of the Input fields is/ are empty!"elif input_01 == 
> input_02:
> msg = "Inputs used in both fields are the same!"else:
> msg = validate_inputs((input_01, input_02))if msg:
> test_dict["Input Issue"].append(msg)
> if next_test():
> msg = 'error'if msg:
> test_dict["Frame Range Issue"].append(msg)
> # Example 2
> append = test_dict["Input Issue"].append
>
> if all((input_01, input_02)) == False
>
> :
> append("One or both of the Input fields is/ are empty!")elif input_01 == 
> input_02:
> append("Inputs used in both fields are the same!")else:
> append(validate_inputs((input_01, input_02)))
>
>
> append = test_dict["Frame Range Issue"].appendif next_test():
> append('error')
>
> ​
>
>
>> In general, I am trying to find out what is the best practice to go about
>> doing them :)
>>
>>
>>
>>
>>
>>
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/c40099fc-dce8-4987-a367-77c3616bae50%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0CkXm9vW9TjmB68n%2BjJnQVUR7efYXJGvp3kio3S9QZNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread Justin Israel
On Wed, Oct 24, 2018 at 10:09 AM likage  wrote:

> Hi Justin, thanks for the reply.
> I use msg{A,B,C} because if any one of the condition passed, the msg will
> get appended with the next in-line error.
>
> Eg. If only frame range fails, my `test_dict` will return as follows:
> {'Frame Range Issue': [None,
>'Value of Start/Min Frame is larger than the value
> of End/Max Frame.'],
>  'Namespace Issue': [None, None],
>  'Selections Issue': [None,
>   'Value of Start/Min Frame is larger than the value
> of End/Max Frame.']}
>
> And hence my usage of A,B,C to differentiate them as I can't reuse the
> same variable in which I am using defaultdict to differentiate them in this
> case.
>

I can only base my reply on your code example, which shows msg{A,B,C} being
defaulted to  None, conditionally set to a message, and then always being
appended immediately. So this translates in my brain to a single temp var
or a string literally, conditionally being appended to each category key if
there is a message to report. The code example doesn't prove the need for
multiple variables.


> appending string literals to the dictionary directly
>>
> Could you kindly elaborate more on this?
>

# Example 1if all((input_01, input_02)) == False:
msg = "One or both of the Input fields is/ are empty!"elif
input_01 == input_02:
msg = "Inputs used in both fields are the same!"else:
msg = validate_inputs((input_01, input_02))if msg:
test_dict["Input Issue"].append(msg)
if next_test():
msg = 'error'if msg:
test_dict["Frame Range Issue"].append(msg)
# Example 2
append = test_dict["Input Issue"].appendif all((input_01, input_02)) == False:
append("One or both of the Input fields is/ are empty!")elif
input_01 == input_02:
append("Inputs used in both fields are the same!")else:
append(validate_inputs((input_01, input_02)))


append = test_dict["Frame Range Issue"].appendif next_test():
append('error')

​


> In general, I am trying to find out what is the best practice to go about
> doing them :)
>
>
>
>
>
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/c40099fc-dce8-4987-a367-77c3616bae50%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0d0XFRdm_bMMS-9%3DZXiWv-441w9gSAwWD%3D3xCQyOGXKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread likage
Hi Justin, thanks for the reply.
I use msg{A,B,C} because if any one of the condition passed, the msg will 
get appended with the next in-line error.

Eg. If only frame range fails, my `test_dict` will return as follows:
{'Frame Range Issue': [None,
   'Value of Start/Min Frame is larger than the value 
of End/Max Frame.'],
 'Namespace Issue': [None, None],
 'Selections Issue': [None,
  'Value of Start/Min Frame is larger than the value of 
End/Max Frame.']}

And hence my usage of A,B,C to differentiate them as I can't reuse the same 
variable in which I am using defaultdict to differentiate them in this case.

appending string literals to the dictionary directly
>
Could you kindly elaborate more on this?

In general, I am trying to find out what is the best practice to go about 
doing them :)
 






-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/c40099fc-dce8-4987-a367-77c3616bae50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Method to collates all errors for Conditions Checking

2018-10-23 Thread Justin Israel
On Wed, Oct 24, 2018 at 9:18 AM likage  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 python_inside_maya+unsubscr...@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+unsubscr...@googlegroups.com.
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