Last active
August 14, 2017 20:50
-
-
Save AndresMWeber/e793e84b683e68b14fcf6e45e8d93479 to your computer and use it in GitHub Desktop.
Trying to figure out implementing services pattern
This file contains hidden or 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
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