Skip to content

Instantly share code, notes, and snippets.

@theodox
Created March 19, 2014 00:00
Show Gist options
  • Save theodox/9632729 to your computer and use it in GitHub Desktop.
Save theodox/9632729 to your computer and use it in GitHub Desktop.
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',[])
_ATTRIBS = kwargs.get('_ATTRIBS',[])
_CALLBACKS = kwargs.get('_CALLBACKS',[])
if not kwargs.get('CMD'):
CMD = parents[0].CMD
for item in _READ_ONLY:
kwargs[item] = CtlProperty(item, CMD, writeable = False)
for item in _ATTRIBS:
kwargs[item] = CtlProperty(item, CMD)
for item in _CALLBACKS:
kwargs[item] = CallbackProperty(item)
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