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 CtlProperty (object): | |
''' | |
Property descriptor. When applied to a Control-derived class, invokes the correct Maya command under the hood to get or set values | |
''' | |
def __init__(self, flag, cmd): | |
assert callable(cmd), "cmd flag must be a maya command for editing gui objects" | |
self.Flag = flag | |
self.Command = cmd |
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
def constructor(self, name): | |
self.Name = name | |
example = type('Example', (), {'__init__':constructor } ) | |
Test = example("Hello world") | |
# <__main__.Example object at 0x00000000022D6198> | |
Test.Name | |
# Hello world |
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'] |
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 FloatSlider(Control): | |
'''sample output from mGui.helpers.tools.generate_commands()''' | |
CMD = cmds.floatSlider | |
_ATTRIBS = ['horizontal','step','maxValue','value','minValue'] | |
_CALLBACKS = ['changeCommand','dragCommand'] |
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
from mGui.core.controls import FloatSlider | |
slider = FloatSlider('testslider') | |
# pythonic properties, thanks to the metaclass... | |
slider.width = 100 | |
slider.minValue = 50 | |
slider.maxValue = 250 |
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 and CallbackProperty objects for Control classes | |
''' | |
def __new__(cls, name, parents, kwargs): | |
CMD = kwargs.get('CMD', None) | |
_READ_ONLY = kwargs.get('_READ_ONLY',[]) |
OlderNewer