>
> 2. Refresh text (values) in frame "Current values in degrees" after
> clicking on "Apply" button.
> When window is created, in frame "Current values in degrees" values of X,
> Y and Z are retrieved from three fields in "Custom axis orientation".  Then
> they are converted to degrees and displayed (lines 63-83 in the code linked
> above). But what I also want is to refresh them each time I click "Apply"
> button. Is there a way to achieve this?
>

What might help you accomplish this is to refactor the code into a class,
so that you can start saving a bunch of the state. You create all the
widgets, and the data structures to set things up, but your callbacks would
either need to be wrapped up with closures to the references, or, would
access them simply off the state of the instance:

So you can track your current degree values as they are updated, via:

self.curMoveDegVal = []


And I would suggest refactoring the block of code that updates your current
text values, into a method that will do them using those instance
attribute. Then its just a matter of tacking on a little more to your
Accept button callback:

...
    applyButton = cmds.button(
        l='Apply',
        height=26,
        c=self.degToRad)
...
def updateText():
    # update the current degree text with
    # self.curMoveDegVal
    # self.curScaleVal

def clickCmd(self, *args):
    self.degToRad()
    self.updateText()

def degToRad(self):
    xDeg = self.xDeg
    yDeg = self.yDeg
    zDeg = self.zDeg
    relativeOpt = self.relativeOpt
    applyFor = self.applyFor

    ...


> 3. Combine formatting of "width", "align" and "precision" in Python.
> Lines 75-83 are showing Python .format method. Each value has 3 float
> digit precision (.3f) and in addition to that they are right-aligned with
> 10 value (>10). Ok, that’s good but I what also want is to have three "0"
> before dot. So I want apply [width] to it (
> http://docs.python.org/2.6/library/string.html#format-specification-mini-language).
> But I don’t know how to mix [align], [width] and [.precision] together in
> one formatting {}.
>
>
I'm not saying this is *the* way to do it, but this works, by breaking it
up into a two step formatting:

vals = [.1, .23456, 12.23]
print 'Move: {0:>10} {1:>10} {2:>10}'.format(*map('{0:0>7.3f}'.format,
vals))

First it converts the float to 3-precision, and left padded with zeros
Then it just does the right alignment to the strings.


> 4. Code improvements
> Because it’s my first script/tool and because I have learning Python for
> only 3 month now – I don’t have too much experience in it – any advice
> about the code structure will be highly appreciated :*
>

That's some really clean looking python in my opinion!
I wouldn't say "always write a class", but in your case you would probably
want to explore writing one since you already have the need to store state,
like references to your widgets, and your data structures, for use in
callbacks.

>
> PS. And as always sorry for my English.
>

Didn't even notice :-)


>  --
> 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/f002cc5e-5a10-4c24-b06b-a71c53860f90%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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/CAPGFgA2w6u8-4UF7V3sST1CSVC05wgXohx2cBh8A3OSE9VhmuA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to