PDA

View Full Version : Pass command in Class Control?


Camaro
06-23-2012, 06:58 AM
I honestly cannot believe I am having so much trouble with this! Here's the problem: I am creating a custom class for what I'm calling a "bladeLayout", which will behave similar to the XBOX 360's original dashboard layout. I have a slider that can be dragged which then changes the size of the panes in a paneLayout. The problem is I can't figure out how to properly pass a command to the "dragCommand" flag of the intSlider. I've tried every combination of quotation marks and with and without the self. prefix, and no matter what I do, I get an error. If I do this simply with functions outside of a class, I simply pass in the command as a string and it works as expected. Surely I'm not going crazy in thinking that this is way easier than I'm making it?

Here be the code so far:

class bladeLayout():
'''
definition for a "blade layout" similar to
the XBOX 360s old dashboard. It's simply a
pane layout with some custom functionality
to act like the blades. The controls should
have a form layout all to themselves.
'''
def __init__(self, name, numBlades=4):
self.UI = {}
self.name = name
self.numBlades = numBlades
self.activeBlade = 1
self.configuration = 'vertical4'
if self.numBlades == 3:
self.configuration = 'vertical3'
elif self.numBlades == 2:
self.configuration = 'vertical2'
elif self.numBlades == 1:
self.configuration = 'vertical2'
self.numBlades = 2
mc.warning('Must have at least two blades')

self.UI['bladeSlider'] = mc.intSlider(dc=self.dragCommand(), max=4)

self.UI['bladeLayout'] = mc.paneLayout(self.name, cn=self.configuration, smc=self.dragCommand())

def dragCommand(self):
slider = 4
try:
if slider == 1:
mc.paneLayout(self.name, e=1, ps=[1, 100, 100])
elif slider == 2:
mc.paneLayout(self.name, e=1, ps=[2, 100, 100])
elif slider == 3:
mc.paneLayout(self.name, e=1, ps=[3, 100, 100])
elif slider == 4:
mc.paneLayout(self.name, e=1, ps=[4, 100, 100])
except:
pass
mc.window()
mc.columnLayout()
blade = bladeLayout('blade1')


I know this is one of those "duh" moments that I simply haven't learned about Python yet. I know about classes in theory, but not in practice :S

tontonsuspect
06-23-2012, 08:59 AM
look for --> dc=self.dragCommand()

it must be written like this:

def dragCommand( self, *args):
your code here

self.UI['bladeSlider'] = mc.intSlider(dc=self.dragCommand, max=4) #notice you dont use parenthesis ?

if your function needs argument you must use partial( your function, yourArgument ).
look in the documentation--> Tips and tricks for scripters new to Python

Camaro
06-23-2012, 06:11 PM
Cool, I never would have guessed to do that. Thanks for the help.

If anyone else wants the code, here's the working version:

class bladeLayout():
'''
definition for a "blade layout" similar to
the XBOX 360s old dashboard. It's simply a
pane layout with some custom functionality
to act like the blades. The controls should
have a form layout all to themselves.
'''
def __init__(self, name, numBlades=4):
self.UI = {}
self.name = name
self.numBlades = numBlades
self.configuration = 'vertical4'
if self.numBlades == 3:
self.configuration = 'vertical3'
elif self.numBlades == 2:
self.configuration = 'vertical2'
elif self.numBlades == 1:
self.configuration = 'vertical2'
self.numBlades = 2
mc.warning('Must have at least two blades')

self.UI['bladeForm'] = mc.formLayout()
self.UI['bladeSlider'] = mc.intSlider(dc=self.dragCommand, min=1, max=4)
self.UI['bladeLayout'] = mc.paneLayout(self.name, cn=self.configuration, smc=self.dragCommand)

mc.formLayout(self.UI['bladeForm'], e=1,
af=[
(self.UI['bladeSlider'], 'left', 5),
(self.UI['bladeSlider'], 'right', 5),
(self.UI['bladeSlider'], 'top', 5),
(self.UI['bladeLayout'], 'left', 5),
(self.UI['bladeLayout'], 'right', 5),
(self.UI['bladeLayout'], 'bottom', 5)],
ac=[
(self.UI['bladeLayout'], 'top', 5, self.UI['bladeSlider'])])

mc.paneLayout(self.name, e=1, ps=[1, 100, 100])

def dragCommand(self, *args):
slider = mc.intSlider(self.UI['bladeSlider'], q=1, v=1)
try:
if slider == 1:
mc.paneLayout(self.name, e=1, ps=[1, 100, 100])
elif slider == 2:
mc.paneLayout(self.name, e=1, ps=[2, 100, 100])
elif slider == 3:
mc.paneLayout(self.name, e=1, ps=[3, 100, 100])
elif slider == 4:
mc.paneLayout(self.name, e=1, ps=[4, 100, 100])
except:
pass

I intend to use it as an alternative to tabLayouts for a character GUI :)

CGTalk Moderation
06-23-2012, 06:11 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.