Skip to content

Instantly share code, notes, and snippets.

@theodox
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theodox/9106311 to your computer and use it in GitHub Desktop.
Save theodox/9106311 to your computer and use it in GitHub Desktop.
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']
def __new__(cls, name, parents, kwargs):
'''
__new__ is called then classes using this meta are defined. It will add
all of the items in CONTROL_ATTRIBS to the new class definition as
CtlProperty descriptor objects using the CMD field (a maya.cmds command)
provied in the outer class.
'''
CMD = kwargs.get('CMD', None)
if not kwargs.get('CMD'):
CMD = parents[0].CMD
for item in ControlMeta.CONTROL_ATTRIBS:
kwargs[item] = CtlProperty(item, CMD)
return super(ControlMeta, cls).__new__(cls, name, parents, kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment