Last active
August 29, 2015 13:56
-
-
Save theodox/9106311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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