Skip to content

Instantly share code, notes, and snippets.

@theodox
Created March 19, 2014 00:18
Show Gist options
  • Save theodox/9632994 to your computer and use it in GitHub Desktop.
Save theodox/9632994 to your computer and use it in GitHub Desktop.
class Control(Styled, BindableObject):
'''
Base class for all mGui controls. Provides the necessary frameworks for
CtlProperty and CallbackProperty access to the underlying widget.
NOTE this is not exactly identical to the code on github - more advanced stuff is removed to make the progression clearer
'''
CMD = cmds.control
_ATTRIBS = ['annotation', 'backgroundColor', 'defineTemplate', 'docTag', 'enable', 'enableBackground', 'exists', 'fullPathName', 'height', 'manage', 'noBackground', 'numberOfPopupMenus', 'parent', 'popupMenuArray', 'preventOverride', 'useTemplate', 'visible', 'visibleChangeCommand', 'width']
_CALLBACKS = ['dragCallback', 'dropCallback', 'visibleChangeCommand']
_READ_ONLY = ['isObscured', 'popupMenuArray', 'numberOfPopupMenus']
__metaclass__ = ControlMeta
def __init__(self, key, *args, **kwargs):
self.Key = key
self.Widget = self.CMD(*args, **_style)
'''
Widget is the gui element in the scene
'''
self.Callbacks = {}
'''
A dictionary of Event objects
'''
Layout.add_current(self)
def register_callback(self, callbackName, event):
'''
when a callback property is first accessed this creates an Event for the specified callback and hooks it to the gui widget's callback function
'''
kwargs = {'e':True, callbackName:event}
self.CMD(self.Widget, **kwargs)
def __nonzero__(self):
return self.exists
def __repr__(self):
if self:
return self.Widget
else:
return "<deleted UI element %s>" % self.__class__
def __str__(self):
return self.Widget
def __iter__(self):
yield self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment