def colorControlLayout(self, label=''):
mc.rowLayout( numberOfColumns=4,
columnWidth4=(150, 200, 90, 80),
adjustableColumn=2,
columnAlign=(1, 'right'),
columnAttach=[(1, 'both', 0),
(2, 'both', 0),
(3, 'both', 0),
(4, 'both', 0)] )
mc.text(label=label)
colorSlider = mc.colorSliderGrp( label='', adj=2, columnWidth=((1,1),(3,1)))
mc.button(label='From Selected',
ann='Get the color of the selected object.',
command=partial(self.setFromSelected, colorSlider))
mc.button(label='Randomize',
ann='Set a random color.',
command=partial(self.randomizeColors, colorSlider))
controls = mc.layout(colorSlider, query=True, childArray=True)
mc.setParent('..')
return colorSlider
python类rowLayout()的实例源码
def buildUI(self):
# To start with we create a layout to hold our UI objects
# A layout is a UI object that lays out its children, in this case in a column
column = cmds.columnLayout()
# Now we create a text label to tell a user how to use our UI
cmds.text(label="Use this slider to set the tween amount")
# We want to put our slider and a button side by side. This is not possible in a columnLayout, so we use a row
row = cmds.rowLayout(numberOfColumns=2)
# We create a slider, set its minimum, maximum and default value.
# The changeCommand needs to be given a function to call, so we give it our tween function
# We need to hold on to our slider's name so we can edit it later, so we hold it in a variable
self.slider = cmds.floatSlider(min=0, max=100, value=50, step=1, changeCommand=tween)
# Now we make a button to reset our UI, and it calls our reset method
cmds.button(label="Reset", command=self.reset)
# Finally we don't want to add anymore to our row layout but want to add it to our column again
# So we must change the active parent layout
cmds.setParent(column)
# We add a button to close our UI
cmds.button(label="Close", command=self.close)
# *args will be a new concept for you
# It basically means I do not know how many arguments I will get, so please put them all inside this one list (tuple) called args
def buildUI(self):
column = cmds.columnLayout()
cmds.text(label="Use this slider to set the tween amount")
cmds.rowLayout(numberOfColumns=2)
self.slider = cmds.floatSlider(min=0, max=100, value=50, step=1, changeCommand=tweener.tween)
cmds.button(label="Reset", command=self.reset)
cmds.setParent(column)
cmds.button(label="Close", command=self.close)
# And again, we just need to override the reset method
# We don't need to define the close, or show methods because it gets those from BaseWindow
def buildUI(self):
column = cmds.columnLayout()
cmds.text(label="Use the slider to modify the number of teeth the gear will have")
cmds.rowLayout(numberOfColumns=4)
# This label will show the number of teeth we've set
self.label = cmds.text(label="10")
# Unlike the tweener, we use an integer slider and we set it to run the modifyGear method as it is dragged
self.slider = cmds.intSlider(min=5, max=30, value=10, step=1, dragCommand=self.modifyGear)
cmds.button(label="Make Gear", command=self.makeGear)
cmds.button(label="Reset", command=self.reset)
cmds.setParent(column)
cmds.button(label="Close", command=self.close)
def channelbox_command_freezeUI():
with sysCmd.Undo(0):
if cmds.window("freezeWindowBox", q=1, exists=1):
cmds.deleteUI("freezeWindowBox")
frz_window = cmds.window("freezeWindowBox", title="Freeze", rtf=1, s=0, tbm=1, tlb=1)
layout = cmds.columnLayout(p=frz_window)
layout_top = cmds.rowLayout(nc=4, p=layout)
width = 25
cmds.button(l="T", w=width, ann="Freeze Translate",
c=sysCmd.rpartial(channelbox_command_freezeTranslate, "", "", "Freeze Translate"), p=layout_top)
cmds.button(l="R", w=width, ann="Freeze Rotate",
c=sysCmd.rpartial(channelbox_command_freezeRotate, "", "", "Freeze Rotate"), p=layout_top)
cmds.button(l="S", w=width, ann="Freeze Scale",
c=sysCmd.rpartial(channelbox_command_freezeScale, "", "", "Freeze Scale"), p=layout_top)
cmds.button(l="A", w=width, ann="Freeze All",
c=sysCmd.rpartial(channelbox_command_freezeAll, "", "", "Freeze All"), p=layout_top)
layout_bot = cmds.rowLayout(nc=4, p=layout)
cmds.button(l="TS", w=width, ann="Freeze Translate / Scale",
c=sysCmd.rpartial(channelbox_command_freezeTranslateScale, "", "", "Freeze Translate / Scale"),
p=layout_bot)
cmds.button(l="TR", w=width, ann="Freeze Translate / Rotate",
c=sysCmd.rpartial(channelbox_command_freezeTranslateRotate, "", "", "Freeze Translate / Rotate"),
p=layout_bot)
cmds.button(l="RS", w=width, ann="Freeze Rotate / Scale",
c=sysCmd.rpartial(channelbox_command_freezeRotateScale, "", "", "Freeze Rotate / Scale"),
p=layout_bot)
cmds.button(l="JO", w=width, ann="Freeze Joint Orient",
c=sysCmd.rpartial(channelbox_command_freezeJointOrient, "", "", "Freeze Joint Orient"),
p=layout_bot)
cmds.window(frz_window, e=1, wh=(1, 1), rtf=1)
cmds.showWindow(frz_window)
# --
def buildWindow(self):
'''
Initialize the UI
'''
if mc.window(self.name, exists=True):
mc.deleteUI(self.name)
mc.window(self.name, title='ml :: '+self.title, iconName=self.title, width=self.width, height=self.height, menuBar=self.menu)
if self.menu:
self.createMenu()
self.form = mc.formLayout()
self.column = mc.columnLayout(adj=True)
mc.rowLayout( numberOfColumns=2, columnWidth2=(34, self.width-34), adjustableColumn=2,
columnAlign2=('right','left'),
columnAttach=[(1, 'both', 0), (2, 'both', 8)] )
#if we can find an icon, use that, otherwise do the text version
if self.icon:
mc.iconTextStaticLabel(style='iconOnly', image1=self.icon)
else:
mc.text(label=' _ _ |\n| | | |')
if not self.menu:
mc.popupMenu(button=1)
mc.menuItem(label='Help', command=(_showHelpCommand(wikiURL+'#'+self.name)))
mc.text(label=self.info)
mc.setParent('..')
mc.separator(height=8, style='single', horizontal=True)
def __init__(self):
name = 'cmt_orientjoints'
if cmds.window(name, exists=True):
cmds.deleteUI(name, window=True)
if cmds.windowPref(name, exists=True):
cmds.windowPref(name, remove=True)
self.window = cmds.window(name, title='CMT Orient Joints', widthHeight=(358, 330))
cmds.columnLayout(adjustableColumn=True)
margin_width = 4
cmds.frameLayout(bv=False, label='Quick Actions', collapsable=True, mw=margin_width)
cmds.gridLayout(numberOfColumns=2, cellWidthHeight=(175, 65))
cmds.button(label='Make Planar Orientation', command=self.make_planar)
cmds.button(label='Project to Planar Position', command=partial(make_position_planar))
cmds.button(label='Align Up With Child', command=self.align_with_child)
cmds.button(label='Zero Orient', command=self.zero_orient)
cmds.button(label='Orient to World', command=self.orient_to_world)
cmds.rowColumnLayout(numberOfColumns=4)
height = 20
label_width = 60
icon_left = 'nudgeLeft.png'
icon_right = 'nudgeRight.png'
cmds.text(label='Offset X', align='right', width=label_width)
cmds.iconTextButton(style='iconOnly', image1=icon_left, label='spotlight', h=height, w=height, c=partial(self.offset_orient_x, direction=-1))
self.offset_x = cmds.floatField(value=90.0)
cmds.iconTextButton(style='iconOnly', image1=icon_right, label='spotlight', h=height, w=height, c=partial(self.offset_orient_x, direction=1))
cmds.text(label='Offset Y', align='right', width=label_width)
cmds.iconTextButton(style='iconOnly', image1=icon_left, label='spotlight', h=height, w=height, c=partial(self.offset_orient_y, direction=-1))
self.offset_y = cmds.floatField(value=90.0)
cmds.iconTextButton(style='iconOnly', image1=icon_right, label='spotlight', h=height, w=height, c=partial(self.offset_orient_y, direction=1))
cmds.text(label='Offset Z', align='right', width=label_width)
cmds.iconTextButton(style='iconOnly', image1=icon_left, label='spotlight', h=height, w=height, c=partial(self.offset_orient_z, direction=-1))
self.offset_z = cmds.floatField(value=90.0)
cmds.iconTextButton(style='iconOnly', image1=icon_right, label='spotlight', h=height, w=height, c=partial(self.offset_orient_z, direction=1))
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
cmds.frameLayout(bv=False, label='Manual Orient', collapsable=True, mw=margin_width)
cmds.columnLayout(adj=True)
cmds.rowLayout(numberOfColumns=2, cw2=(150, 150))
self.reorient_children = cmds.checkBox(label='Reorient children', value=True, align='left')
self.reset_orientation = cmds.checkBox(label='Reset orientation', value=True, align='left')
cmds.setParent('..')
cmds.gridLayout(numberOfColumns=2, cellWidthHeight=(175, 65))
cmds.button(label='Template Joints', command=partial(self.template_joints))
cmds.button(label='Rebuild Joints', command=partial(rebuild_joints))
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
cmds.showWindow(self.window)