Skip to content

Instantly share code, notes, and snippets.

View theodox's full-sized avatar

Steve Theodore theodox

View GitHub Profile
class ControlMeta(type):
'''
Metaclass which creates CtlProperty objects for maya gui proxies
'''
CONTROL_ATTRIBS = ['annotation', 'backgroundColor', 'defineTemplate',
'docTag', 'dragCallback', 'dropCallback', 'enable',
'enableBackground', 'exists', 'fullPathName', 'height',
'manage', 'noBackground', 'numberOfPopupMenus', 'parent',
'popupMenuArray', 'preventOverride', 'useTemplate', 'visible',
'visibleChangeCommand', 'width']
class MetaButton(object):
CMD = cmds.button
__metaclass__ = ControlMeta
def __init__(self, *args, **kwargs):
self.Widget = self.CMD (*args, **kwargs)
w = cmds.window()
c = cmds.columnLayout()
class ControlMeta(type):
'''
Metaclass which creates CtlProperty objects for Control classes
'''
CONTROL_ATTRIBS = ['annotation', 'backgroundColor', 'defineTemplate', 'docTag',
'dragCallback', 'dropCallback', 'enable', 'enableBackground',
'exists', 'fullPathName', 'height', 'manage', 'noBackground',
'numberOfPopupMenus', 'parent', 'popupMenuArray', 'preventOverride',
'useTemplate', 'visible', 'visibleChangeCommand', 'width']
@theodox
theodox / xform.py
Created March 11, 2014 21:52
Exposes the xform class: a simple way to set maya position, rotation and similar properties with point notation.
'''
xform.py
Exposes the xform class: a simple way to set maya position, rotation and similar properties with point notation.
from xform import Xform
example = Xform('pCube1')
print example.translation
# [0,0,0]
class FloatSlider(Control):
'''sample output from mGui.helpers.tools.generate_commands()'''
CMD = cmds.floatSlider
_ATTRIBS = ['horizontal','step','maxValue','value','minValue']
_CALLBACKS = ['changeCommand','dragCommand']
from mGui.core.controls import FloatSlider
slider = FloatSlider('testslider')
# pythonic properties, thanks to the metaclass...
slider.width = 100
slider.minValue = 50
slider.maxValue = 250
class ControlMeta(type):
'''
Metaclass which creates CtlProperty and CallbackProperty objects for Control classes
'''
def __new__(cls, name, parents, kwargs):
CMD = kwargs.get('CMD', None)
_READ_ONLY = kwargs.get('_READ_ONLY',[])
class Control(Styled, BindableObject):
'''
Base class for all mGui controls. Provides the necessary frameworks for
CtlProperty and CallbackProperty access to the underlying widget.
NOTE this is not exactly identical to the code on github - more advanced stuff is removed to make the progression clearer
'''
CMD = cmds.control
_ATTRIBS = ['annotation', 'backgroundColor', 'defineTemplate', 'docTag', 'enable', 'enableBackground', 'exists', 'fullPathName', 'height', 'manage', 'noBackground', 'numberOfPopupMenus', 'parent', 'popupMenuArray', 'preventOverride', 'useTemplate', 'visible', 'visibleChangeCommand', 'width']
_CALLBACKS = ['dragCallback', 'dropCallback', 'visibleChangeCommand']
class Nested(Control):
'''
Base class for all the nested context-manager classes which automatically parent themselves
'''
ACTIVE_LAYOUT = None
def __init__(self, key, *args, **kwargs):
self.Controls = []
super(Nested, self).__init__(key, *args, **kwargs)
from mGui.gui import *
# note the caps: all of these are wrapper objects, not maya.cmds!
window = Window('main window', title="How's this")
with ColumnLayout('gui', width = 256) as gui:
with FrameLayout("t_buttons", label = "buttons column"):
with ColumnLayout("col"):
Button('mkSphere', label = "Make Sphere")
Button('mkCone', label ="Make Cone")
Button('mkCube', label ="Make Cube")