Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Ui Syntax

Help
Carlos
2006-11-24
2013-03-24
  • Carlos
    Carlos
    2006-11-24

    Hi,

    I'm trying to do this UI in Maya/Python:

    window -rtf true -title "Create a bunch of balls"   myWindow;

    columnLayout;

    intSliderGrp -label "Number of Balls" -field true numBalls;
    floatSliderGrp -minValue .1 -maxValue 1 -label "Thickness" -field true ballThickness;

    button -c "findValues" -label "Make'm";

    showWindow myWindow;

    proc findValues () {

    int $myNumBalls = `intSliderGrp -q -value "numBalls"`;

    float $myThickness = `floatSliderGrp -q -value "ballThickness"`;

    ballStack $myNumBalls $myThickness;

    }

    Can this be done with Maya/Python? I mean just by changing the syntax or a different approach is needed?

    If it can be done just by changing the syntax and this is what I have been trying to do, I would like to know:

    In "window -rtf true -title "Create a bunch of balls"   myWindow;" and "intSliderGrp -label "Number of Balls" -field true numBalls;" the name of the window and the slider are created just by a string with no flag. How can I do this in Maya/Python?

    And as you can see a procedure "proc findValues ()" needs to be defined. Is this too possible just by changing the syntax? or I need to use another way? can you tell me the correct way to procede with this procedure? : )

    Thanks
    Carlos

     
    • Matthias Baas
      Matthias Baas
      2006-11-25

      You have two options: you can either use the mel module and use the same commands as above or you can use the GUI classes from the gui module.

      The first option would look like this:

      ################################################################
      # Option 1: Using the mel module
      from maya.mel import *

      window("myWindow", rtf=True, title="Create a bunch of balls")

      columnLayout()

      intSliderGrp("numBalls", label="Number of Balls", field=True)
      floatSliderGrp("ballThickness", minValue=.1, maxValue=1, label="Thickness", field=True)

      button(c="findValues", label="Make'm")

      showWindow("myWindow")
      ################################################################

      Any regular (non-flag) argument such as the name of the objects can be passed as normal positional argument (which, of course, means that they have to appear *before* the keyword arguments).
      The drawback of this approach is that the button command still must be MEL code, i.e. "findValues" still refers to a MEL function which must be defined elsewhere. If you want to invoke Python code you would have to use the "py" MEL command.

      The recommended second option does not have this drawback. Using this option the code might look like this:

      ################################################################
      # Option 2: Using the gui module
      from maya.gui import *
      from maya.mel import *

      def findValues():
          "Callback function."
          global numBalls, ballThickness
          print "numBalls:",numBalls.value
          print "ballThickness (via object):",ballThickness.value
          print "ballThickness (via MEL):",floatSliderGrp("ballThickness", query=None, value=None)

      myWindow = Window(name="myWindow", rtf=True, title="Create a bunch of balls")

      ColumnLayout()

      numBalls = IntSliderGrp(name="numBalls", label="Number of Balls", field=True)
      ballThickness = FloatSliderGrp(name="ballThickness", minValue=.1, maxValue=1, label="Thickness", field=True)

      Button(c=findValues, label="Make'm")

      myWindow.Show()
      ################################################################

      The classes are simply called after their corresponding MEL command and start with an upper case character. Usage is almost the same as before. There's only an additional keyword argument "name" that can be used to specify the name of the GUI object.
      Now the command argument of the button is actually a Python callable. In the callback you can either retrieve the values of the GUI elements via the objects or still by using the appropriate MEL command.

      - Matthias -

       
      • Carlos
        Carlos
        2006-11-26

        Hi Matthias,

        Thanks a lot for your help, I got it working now.

        Carlos