# Load maya commands module
import maya.cmds as mc
# This prevents multiple windows to pop up
if mc.window("myWindow", ex=True):
mc.deleteUI("myWindow", window=True)
# Window set-up
mc.window("myWindow",title="Test Window", s=False, wh=(300,100))
mc.columnLayout(adj=True)
toggle_test = mc.checkBox(label = 'Toggle me!', value = False)
mc.button(l="Press to print the value of the checkbox below", w=300, h=100,
command = 'printIt()'
)
mc.showWindow("myWindow")
# Print the value
def printIt():
# Query toggle status
var = mc.checkBox(toggle_test, query = True, value = True )
# Print the status
print "Checkbox's status is:", varimport testScript
reload (testScript)
# Error: NameError: file <maya console> line 1: name 'printIt' is not defined #from testScript_01 import *
import testScript
reload (testScript)
command = 'printIt()'
command = 'testScript.printIt()'
import testScript
reload (testScript)
# Add a line of code that feeds the string 'testScript' to the imported module
# Declare var for fed string
input_string = #fed string
...
command = input_string + '.printIt()'
Hi Gabriele,
All you need to do is import your script in the shelf button, it will take care of the “loading” for you.
testScript.py
def test_function():
print "Test complete"
Your shelf button can then consist of something like this:
import testScript
testScript.test_function()
As a side note, you shouldn’t have anything outside of functions or classes that executes anything; so imports and attribute definitions are okay, but showing and deleting windows are not. Reload is useful if you change your script on disk; so really only for dev, not during production, you can do something like what you did:
import testScript
reload(testScript)
testScript.test_function()
Also, have a look at PEP08 for naming conventions; mainly how to stick with snake_case:
test_script.py
def test_function():
print "Test complete"
Best,
Marcus
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/be3c13c1-48f0-41d3-8184-e36fda61073e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
import maya.cmds as mc
def load_UI():
# UI mumbo jumbo
def printIt():
# same as before
# call the function
load_UI()
mc.button(l="Press to print the value of the checkbox below", w=300, h=100, command = 'printIt()' )
mc.button(l="Press to print the value of the checkbox below", w=300, h=100, command=printIt )
--
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+unsub...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/bd96c3b7-9fe1-4f38-b7fb-8e4506792af2%40googlegroups.com.
# Load maya commands module
import maya.cmds as mc
# Build the UI
def launch_UI():
# This prevents multiple windows to pop up
if mc.window("myWindow", ex=True):
mc.deleteUI("myWindow", window=True)
# Window set-up
mc.window("myWindow",title="Test Window", s=False, wh=(300,100))
mc.columnLayout(adj=True)
toggle_test = mc.checkBox(label = 'Toggle me!', value = False)
mc.button(l="Press to print the value of the checkbox below", w=300, h=100,
command = printIt)
mc.showWindow("myWindow")
# Print the value
def printIt():
# Query toggle status
var = mc.checkBox(toggle_test, query = True, value = True )
# Print the status
print "Checkbox's status is:", var
launch_UI()import testScript
reload (testScript)# Error: printIt() takes no arguments (1 given)
# TypeError: printIt() takes no arguments (1 given) # # Print the value
def printIt(test):
print test
# Query toggle status
var = mc.checkBox(toggle_test, query = True, value = True )
# Print the status
print "Checkbox's status is:", var# Error: NameError: file D:/GoogleDrive/Maya/shared_folder/scripts\testScript_01.py line 25: global name 'toggle_test' is not defined #mc.button(l="Press to print the value of the checkbox below", w=300, h=100, command=printIt(toggle_test) )# Error: TypeError: file D:/GoogleDrive/Maya/shared_folder/scripts\testScript_01.py line 16: Invalid arguments for flag 'command'. Expected string or function, got NoneType #--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3075c5c8-5215-461f-86d3-39adde494131%40googlegroups.com.
import maya.cmds as mc
from functools import partial
def launch_UI():
if mc.window("myWindow", ex=True):
mc.deleteUI("myWindow", window=True)
mc.window("myWindow",title="Test Window", s=False, wh=(300,100))
mc.columnLayout(adj=True)
toggle_test = mc.checkBox(label = 'Toggle me!', value = False)
mc.button(l="Press to print the value of the checkbox below",
w=300, h=100, command=partial(printIt, toggle_test))
mc.showWindow("myWindow")
def printIt(checkBox, *args):
var = mc.checkBox(checkBox, query = True, value = True )
print "Checkbox's status is:", var
launch_UI()
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/53C6A36F.5050309%40gmail.com.
# Build the UI
def launch_UI():
global toggle_test
# This prevents multiple windows to pop up
if mc.window("myWindow", ex=True):
mc.deleteUI("myWindow", window=True)
# Window set-up
mc.window("myWindow",title="Test Window", s=False, wh=(300,100))
mc.columnLayout(adj=True)
toggle_test = mc.checkBox(label = 'Toggle me!', value = False)
mc.button(l="Press to print the value of the checkbox below", w=300, h=100,
command = printIt)
mc.showWindow("myWindow")
# Print the value
def printIt(*args):
# Query toggle status
var = mc.checkBox(toggle_test, query = True, value = True )
# Print the status
print "Checkbox's status is:", var
launch_UI()# Build the UI
def launch_UI():
# This prevents multiple windows to pop up
if mc.window("myWindow", ex=True):
mc.deleteUI("myWindow", window=True)
# Window set-up
mc.window("myWindow",title="Test Window", s=False, wh=(300,100))
mc.columnLayout(adj=True)
toggle_test = mc.checkBox(label = 'Toggle me!', value = False)
mc.button(l="Press to print the value of the checkbox below", w=300, h=100,
command = partial(printIt, toggle_test))
mc.showWindow("myWindow")
# Print the value
def printIt(check_box, *args):
# Query toggle status
var = mc.checkBox(check_box, query = True, value = True )
# Print the status
print "Checkbox's status is:", var
launch_UI()class Custom_tool:
def __init__(self):
# This prevents multiple windows to pop up
if mc.window("myWindow", ex=True):
mc.deleteUI("myWindow", window=True)
# Window set-up
mc.window("myWindow",title="Test Window", s=False, wh=(300,100))
mc.columnLayout(adj=True)
self.toggle_test = mc.checkBox(label = 'Toggle me!', value = False)
mc.button(l="Press to print the value of the checkbox below", w=300, h=100,
command = self.printIt)
mc.showWindow("myWindow")
# Print the value
def printIt(self, *args):
# Query toggle status
var = mc.checkBox(self.toggle_test, query = True, value = True )
# Print the status
print "Checkbox's status is:", var
new_tool = Custom_tool()--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/733dcb16-55b0-43c4-8f5c-9de1765993e4%40googlegroups.com.
Definitely not the first one. Avoid relying on globals when possible.
The second and third are equally fine right now. But if you start needing more state such as storing more widgets or values, then the class will end up becoming the better choice.
--
For sure. Please share what you have when you are ready. We can all give you some help if you get stuck again.
Thanks man, I appreciate the feedback.
Needless to say that I'm not working only on a test script, but I have something else up my sleeve. Would you like to give it a try when I am done with it?Cheers
On Thursday, 17 July 2014 21:57:17 UTC+2, Justin Israel wrote:Definitely not the first one. Avoid relying on globals when possible.
The second and third are equally fine right now. But if you start needing more state such as storing more widgets or values, then the class will end up becoming the better choice.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0a7cbabb-cc7b-49e1-9c88-13566304f94d%40googlegroups.com.
command = my_functioncommand = my_function()
def f():
print "hello"
f()
# hello
f.__call__()
# hello
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/630eee2f-b4db-4c0c-a164-2bf33bfa7ad7%40googlegroups.com.
a = f()command = fcommand = partial(f, val)To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9fcb19aa-8bc9-44b4-bec3-bfedb4694469%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/630eee2f-b4db-4c0c-a164-2bf33bfa7ad7%40googlegroups.com.
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9fcb19aa-8bc9-44b4-bec3-bfedb4694469%40googlegroups.com.
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAhbVTnKaZ_QOEVV%3Dgj6bG0akV401TUj1amWHCBc46vYg%40mail.gmail.com.
Marcus,partial() is a formal version of a closure (lambda) so if you recommend a lambda, then a partial() is a safer version of this. It does a proper closure (lambda has the potential to have scoping issues if not careful).I am not here to judge whether Gabriele is more capable of comprehending classes vs closures. I only presented options, and am answering questions to the best of my abilities when asked.
Gabriele, please disregard Marcus's interjections. functools.partial() is not a 'workaround'. It is a tool for performing a closure. It is like you said, a 'wrapper' that says "I will give you back a new callable that will automatically use these default arguments and keywords that you have given me. You can have a function called foo(x). foo() requires a single argument 'x'. If I write: wrapped = functools.partial(foo, x) , then 'wrapped' is a new callable that is a 'closure' of foo() over x. When I call wrapped(), it is really calling foo(x) for me with the baked in x value. Honestly though, I can't see classes being any more or less complex than closures so they might as well be met on the same level. A class has methods, and methods are functions that are 'baked' with an implicit first argument that is the current instance at that moment.
Yes, you seem to have explained your understanding of the callable just fine. The only correction I would make is where you are describing what "command" is in this context. "command" is a parameter to a function. Namely, the button function that accepts a callable as a parameter. Within this function it will receive the callable, passed through the parameter "command". Within the scope of that function (which is completely transparent to you), it would be working with a local variable "command" to save your callback, and use it later when the button is clicked.
On Fri, Jul 18, 2014 at 11:31 PM, Marcus Ottosson <konstr...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAhbVTnKaZ_QOEVV%3Dgj6bG0akV401TUj1amWHCBc46vYg%40mail.gmail.com.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1c_m0z1va4Wa5qFMQiCtzu3mqNHQ2SJeDf2Zbhp-ROQg%40mail.gmail.com.
Let the battle begin! Haha, just kidding. Not sure why you took it personally, Justin, but I'll leave you to it then. No harm intended. :)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBzCHwt7zZViS%2B_0MPztgYAemBKfjnf4FHnUmGES%2B%3DBXQ%40mail.gmail.com.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d857e3a5-c027-4a79-b67d-b15ad2ac1a9b%40googlegroups.com.
I can offer a couple points of feedback so far, but I didn't get too deep into the too since it has some compatibility issues with python2.6 (Maya 2013).If you use the str.format() approach for formatting text, python2.6 doesn't support the anonymous fields. That was introduced in python2.7So in python2.7, this is valid: "My string says {} {}!".format("Hello", "World")But in python2.6 you have to name the fields: "My string says {0} {1}!".format("Hello", "World")
Also, there are a couple button callbacks where you use "mm.eval()", but if someone doesn't have maya.mel imported as mm in their global scope (either having done it manually in the script editor, or in their userSetup.py) then it will produce an error. That could be another candidate for partial, doing something like partial(mm.eval, "my mel command"). Otherwise you have to do the more verbose string approach that has to first import maya.mel: "import maya.mel as mm; mm.eval('my mel command')". I kind of prefer the former, if you have to call mel as a python callback. Or it can call a python method you have set up already that will cleanly call the mel command, like: self.__prefixHierarchy()
def launch_prefixHierarchy(self, *args):
"""Launches Maya's built-in command"""
from maya.mel import eval as eval
eval('prefixHierarchy') * "New-style" python classes always at least subclass object: class MyClass(object):
* When testing if a list is empty, instead of allocating a new empty list object each time, just to test if it is equal to the other list, you can simply check if your list is empty using: if not myList
if my_list != []:if not my_list* It is usually best not to have your class constructor have side effects, such as showing the window. It should have a separate method like show(). That way someone can import and create an instance of the window and show it when they want to. Constructors are for setting up the state of the class.
* The approach where you are using the tool_launcher() method with a string tool name might be cleaner if you made those tools formal functions or methods. There are a couple of places where you test for the literal string names in order to do different logic, which could be bug prone because changing the name in one spot means you have to find and replace all of the literal string references. Maybe you might want to define those once in your class as class constants:class MyClass(object):ACTION_NAME_1 = "action1"ACTION_NAME_2 = "action2"Or if you want to make the association between an action and a displayable name, you can register a dictionary in your constructor that maps them:
self._actions = {
"Action 1": self.__action1,
"Action 2": self.__action2,
}Then you won't have to do the 'if actionName == "literal name"' test in multiple places to figure out the action to perform. You can just look up the associated action in the dict: self._actions[actionName]
* rsplit() is a method of a stringso this: str.rsplit(str(temp_name), split_char, 1)can be written as: temp_name.rsplit(split_char, 1)
str.rsplit(temp_name, split_char, 1)TypeError: descriptor 'rsplit' requires a 'str' object but received a 'unicode'temp_name.rsplit(split_char, 1)
str(temp_name).rsplit(split_char, 1)Hi, sorry for the late reply. Busy weekend!
On Friday, 18 July 2014 23:36:52 UTC+2, Justin Israel wrote:I can offer a couple points of feedback so far, but I didn't get too deep into the too since it has some compatibility issues with python2.6 (Maya 2013).If you use the str.format() approach for formatting text, python2.6 doesn't support the anonymous fields. That was introduced in python2.7So in python2.7, this is valid: "My string says {} {}!".format("Hello", "World")But in python2.6 you have to name the fields: "My string says {0} {1}!".format("Hello", "World")Good to know! I'll fix it so that it works with older versions too. :)Also, there are a couple button callbacks where you use "mm.eval()", but if someone doesn't have maya.mel imported as mm in their global scope (either having done it manually in the script editor, or in their userSetup.py) then it will produce an error. That could be another candidate for partial, doing something like partial(mm.eval, "my mel command"). Otherwise you have to do the more verbose string approach that has to first import maya.mel: "import maya.mel as mm; mm.eval('my mel command')". I kind of prefer the former, if you have to call mel as a python callback. Or it can call a python method you have set up already that will cleanly call the mel command, like: self.__prefixHierarchy()Thanks, I never noticed that issue, probably because I have always launched the script at least once from the script editor, importing maya.mel in the global scope, before trying the shelf button. I fixed it creating three methods looking like this:def launch_prefixHierarchy(self, *args):
"""Launches Maya's built-in command"""
from maya.mel import eval as eval
eval('prefixHierarchy')Out of curiosity, why did you add the double underscore in the method example? I know it is supposed to tell python that the method is private, but I don't see why would someone do that (it is more of a general inquiry, not a specific one).
from maya.mel import eval
* "New-style" python classes always at least subclass object: class MyClass(object):Ok, not really sure what is going on here, but I'll do some research! To be on the safe side, I'll do as you say and take it from there.* When testing if a list is empty, instead of allocating a new empty list object each time, just to test if it is equal to the other list, you can simply check if your list is empty using: if not myListDo you mean that instead of doingif my_list != []:I should doif not my_list
? I guess I stick with the first method as it reminds me of the few things I remember about C :P
* It is usually best not to have your class constructor have side effects, such as showing the window. It should have a separate method like show(). That way someone can import and create an instance of the window and show it when they want to. Constructors are for setting up the state of the class.
Ok, to put in other words, I can leave the __init__ empty, given that there isn't much to initialize, and create a new method that does what the __init__ was doing. It seems to work, so I'll do it :)
* The approach where you are using the tool_launcher() method with a string tool name might be cleaner if you made those tools formal functions or methods. There are a couple of places where you test for the literal string names in order to do different logic, which could be bug prone because changing the name in one spot means you have to find and replace all of the literal string references. Maybe you might want to define those once in your class as class constants:class MyClass(object):ACTION_NAME_1 = "action1"ACTION_NAME_2 = "action2"Or if you want to make the association between an action and a displayable name, you can register a dictionary in your constructor that maps them:
self._actions = {
"Action 1": self.__action1,
"Action 2": self.__action2,
}Then you won't have to do the 'if actionName == "literal name"' test in multiple places to figure out the action to perform. You can just look up the associated action in the dict: self._actions[actionName]You're very much right. I think I'll live it as it is for now. If happen to change that part of the code I'll fix it properly.* rsplit() is a method of a stringso this: str.rsplit(str(temp_name), split_char, 1)can be written as: temp_name.rsplit(split_char, 1)Ok, now this is interesting. It was definitely stupid of me to use that syntax. I do have a question though. I started with:str.rsplit(temp_name, split_char, 1)
which gave me this:TypeError: descriptor 'rsplit' requires a 'str' object but received a 'unicode'This is why I managed to make the ugly code even uglier with the str(temp_name) type conversion.Now with the question. Following the error stated above, I assumed that if I wanted to avoid the same TypeError, your suggestiontemp_name.rsplit(split_char, 1)
needed to be converted tostr(temp_name).rsplit(split_char, 1)
Needles to say, you were right and it works perfectly without conversion. Any idea why it needed the conversion in the first case and not in the second?
s = u"foo bar"
unicode.rsplit(s, ' ', 1)
Well, thanks a lot. You've been really helpful. Do you have anything to say about the actual functionality of the whole thing? UI design and stuff like that?
Thank you very much!
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ed3474e4-08f8-4b02-9f7d-2b4cd958d6c0%40googlegroups.com.
The use of double underscore is for methods where the implementation is private and outside people shouldn't be calling it. For things like callbacks that may take private arguments or have functionality where you want control over them being called, it is good to hide them. Ideally you are only exposing functions you want the outside world to have access to. I just chose to make this a private method since it's sole purpose was to wrap a mel call to prefixHierarchy, and really serves no purpose as being a part of your public API. But it is possible you might have some reason to make it a public method.
>>> class MyClass:
... def myPublicMethod(self):
... print 'public method'
... def __myPrivateMethod(self):
... print 'this is private!!'
...
>>> obj = MyClass()Out of curiosity for me as well, why do you choose to use that specific form of an import statement? It seems redundant to import something as an alias of the original name (not to mention that technically in this case, "eval" would shadow the python eval, although it would have no effect if you weren't going to use the python eval() anywhere). But it could be written as:from maya.mel import eval
Well my comment wasn't just about syntax. You are actually allocating a temporary list object in memory each time that just gets garbage collected. Seems like something you might want to avoid doing. Do you allocate temporary arrays in C to check if an existing array is empty? Or are you confusing this syntax with comparing an array to NULL in C (asking if it is a NULL pointer)?
You could leave all of your widget construction and layout in the constructor if you want (thats up to you). I only meant the last line where it shows the window as part of the constructor.
I didn't get to try the whole thing out, since I didn't have Maya2014+ handy at the time. But it looks nice! Also very kind of you to add so much help at the bottom. Leaves nothing to ambiguity! Sorry that I focused more on the code aspects, rather than the interface. It was easier for me to do that at the given moment.
On 22/07/2014 3:13 AM, "Gabriele Bartoli" <prodegu...@gmail.com> wrote:
>>
>> The use of double underscore is for methods where the implementation is private and outside people shouldn't be calling it. For things like callbacks that may take private arguments or have functionality where you want control over them being called, it is good to hide them. Ideally you are only exposing functions you want the outside world to have access to. I just chose to make this a private method since it's sole purpose was to wrap a mel call to prefixHierarchy, and really serves no purpose as being a part of your public API. But it is possible you might have some reason to make it a public method.
>
>
> Ok, I understand why it makes sense to hide some of the methods to the end user if they are not going to call them. But for what I understand they are not really hidden, they are simply slightly harder to call. Example from stackOverflow:
>
> >>> class MyClass:
> ... def myPublicMethod(self):
> ... print 'public method'
> ... def __myPrivateMethod(self):
> ... print 'this is private!!'
> ...
> >>> obj = MyClass()
>
>
> I can call the private method using obj._MyClass__myPrivateMethod(), or self._MyClass__myPrivateMethod() from the inside, right?
> It seems to link to the "new classes" deal. I'll look into it!
>
Yea in Python there is no true sense of private members. Python just uses name mangling as a deterrent. One would still need to construct a name based on the class name and the member to access it (your example is doing it interactively where you know the object to call) . But like I said it is more of a deterrent. It implies to others which parts they should access and which could cause undocumented problems and side effects. In a private method you can do whatever you want and don't have to be clear about it in terms of public documentation. Although you should still write clear code and comment it if needed. It also helps dictate which parts of your code will get picked up for documentation generators such as Sphinx which by default will look for public methods.
It is more of a practice and Python idiom. It tells me as a consumer how to use the object without breaking it.
>> Out of curiosity for me as well, why do you choose to use that specific form of an import statement? It seems redundant to import something as an alias of the original name (not to mention that technically in this case, "eval" would shadow the python eval, although it would have no effect if you weren't going to use the python eval() anywhere). But it could be written as:
>>
>> from maya.mel import eval
>
> I don't really have an answer. I first thought of importing the whole maya.mel as mm in every method, but it seemed overkill, so I decided to try importing the single eval() method. I should call it differently, maybe mm_eval, to avoid it shadowing the python eval, shouldn't I? I tried to call it mm.eval, which was obviously wrong, and then I forgot to try another name.
>
Ideally you would just import it once at the root of your module and then base your callbacks off that.
>> Well my comment wasn't just about syntax. You are actually allocating a temporary list object in memory each time that just gets garbage collected. Seems like something you might want to avoid doing. Do you allocate temporary arrays in C to check if an existing array is empty? Or are you confusing this syntax with comparing an array to NULL in C (asking if it is a NULL pointer)?
>
>
> You have a point, rampage of confusion going on here. What I started doing was declaring a variable with None (my_list = None), but then it wold give me issues when I tried to append stuff to it, because it is not considered a list yet. The fastest thing I thought of was to make it a list to begin with. At that point I didn't think using booleans or identity tests would work.
>
>>
>> You could leave all of your widget construction and layout in the constructor if you want (thats up to you). I only meant the last line where it shows the window as part of the constructor.
>
>
> I tried to do that real quick, but it gave me an error of window not found. It was easier to rename the method and create an empty __init__
>
>> I didn't get to try the whole thing out, since I didn't have Maya2014+ handy at the time. But it looks nice! Also very kind of you to add so much help at the bottom. Leaves nothing to ambiguity! Sorry that I focused more on the code aspects, rather than the interface. It was easier for me to do that at the given moment.
>
>
> No reason to apologize, you are being very helpful! Do you know where I could find more pointers regarding creating custom UIs? It seems very hard to find good reference guides.
>
Do you mean more like design guides as opposed to technical code-based guides? Hmm I'm terrible with remembering references to suggest. Not quite sure in this area. Maybe others can chime in?
> I uploaded the edited version here, if you want to give it a go. I changed the text formatting, therefore it shouldn't give you any issues now.
>
Will give it a go when I have a moment. Thanks!
> Cheers!
>
> --
> 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_m...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8b96abf3-8863-4738-9000-397f7eabf922%40googlegroups.com.
Yea in Python there is no true sense of private members. Python just uses name mangling as a deterrent. One would still need to construct a name based on the class name and the member to access it (your example is doing it interactively where you know the object to call) . But like I said it is more of a deterrent. It implies to others which parts they should access and which could cause undocumented problems and side effects. In a private method you can do whatever you want and don't have to be clear about it in terms of public documentation. Although you should still write clear code and comment it if needed. It also helps dictate which parts of your code will get picked up for documentation generators such as Sphinx which by default will look for public methods.
It is more of a practice and Python idiom. It tells me as a consumer how to use the object without breaking it.
Ideally you would just import it once at the root of your module and then base your callbacks off that.
Do you mean more like design guides as opposed to technical code-based guides? Hmm I'm terrible with remembering references to suggest. Not quite sure in this area. Maybe others can chime in?