Skip to content

Instantly share code, notes, and snippets.

@AndresMWeber
Last active August 14, 2017 20:50
Show Gist options
  • Save AndresMWeber/e793e84b683e68b14fcf6e45e8d93479 to your computer and use it in GitHub Desktop.
Save AndresMWeber/e793e84b683e68b14fcf6e45e8d93479 to your computer and use it in GitHub Desktop.
Trying to figure out implementing services pattern
import maya.cmds as cmds
platform = cmds
class EventService(object):
def __init__(self):
self.events = []
self.event_log = []
def add_event(self, event):
self.events.append(event)
def process_stack(self):
for event in self.events:
print('Processing event %s' % event)
if self.process_event(event.copy()):
self.event_log.append(event.copy())
self.events = []
def process_event(self, event):
event_type = event.pop('event_type')
if hasattr(platform, event_type):
event_function = getattr(platform, event_type)
event_function(**event)
return True
return False
def create():
service = EventService()
service.add_event({'event_type': 'group', 'name': 'test_group', 'em': True})
service.process_stack()
return service.event_log
if __name__ == '__main__':
log = create()
print(log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment