Skip to content

Instantly share code, notes, and snippets.

@theodox
Last active August 29, 2015 13:56
Show Gist options
  • Save theodox/9106616 to your computer and use it in GitHub Desktop.
Save theodox/9106616 to your computer and use it in GitHub Desktop.
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']
def __new__(cls, name, parents, kwargs):
CMD = kwargs.get('CMD', None)
_ATTRIBS = kwargs.get('_ATTRIBS',[]) # unique props from outer class
if not kwargs.get('CMD'):
CMD = parents[0].CMD
for item in ControlMeta.CONTROL_ATTRIBS:
kwargs[item] = CtlProperty(item, CMD)
for item in _ATTRIBS: # now add in the outer class's unique props too
kwargs[item] = CtlProperty(item, CMD)
return super(ControlMeta, cls).__new__(cls, name, parents, kwargs)
class MetaButton(object):
CMD = cmds.button
_ATTRIBS = ['label', 'command'] # button specific props
__metaclass__ = ControlMeta
def __init__(self, *args, **kwargs):
self.Widget = self.CMD (*args, **kwargs)
class MetaFloatField(object):
CMD = cmds.floatField
_ATTRIBS = ['editable','precision','value','maxValue','step',
'minValue', 'changeCommand','dragCommand','enterCommand',
'receiveFocusCommand'] # this one has a lot of properties
__metaclass__ = ControlMeta
def __init__(self, *args, **kwargs):
self.Widget = self.CMD (*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment