Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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