On Mon, Apr 17, 2017 at 11:19 AM gnn <[email protected]> wrote:

> Thank you Justin,
> I'm sorry, but i'm a real newbie in Python, i'm not understand why i can't
> assign a variable inside the function like this:
>
> def buttonLGTPressed(*args):
>     buttonPressed = 'LGT'
>     print "button pressed"
>
> cmds.button('Open', l="Open Last scene", w=180, h=30,
> command=buttonLGTPressed)
>
> if buttonPressed == 'LGT':
>     print "button LGT pressed"
>
> it's not the good way to do this?
>

The use of a callback function, in this case your 'buttonLGTPressed()', is
meant to be the point at which you know the button has been pressed and can
react. I am not sure what you are trying to achieve by having that extra
"if buttonPressed" at the end. I will assume you want the button press to
change some form of persistent state, which you can then check at another
point in time? If that is the case, you are going to have to set up some
way to properly store state. Two possible approaches to this are to either
use a class for your UI. Or to use optionVars which is more of a global
variable storage provided by Maya. In the MEL world, because of a lack of
classes, optionVar is used more frequently.

A class might take the form of:

class MyDialog(object):

    def __init__(self):
        self._buttonPressValue = ""
        # Now set up the rest of your UI.

        # Create a button and set the command
        # to use  self.buttonPressed

    def show(self):
        # Show the UI

    def buttonPressed(self, *args):
        self._buttonPressValue = 'LGT'

    def getButtonPressValue(self):
        return self._buttonPressValue

​

Does this help clarify the issue a bit more?

Justin


-- 
> 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/fea16d97-5ea0-43da-8a14-a951eb65cf18%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/fea16d97-5ea0-43da-8a14-a951eb65cf18%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/CAPGFgA03Y1%3DHQNWLK0bN91zBOstK_E_X3t6Ld13hYpK0yAK1XQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to