diff options
Diffstat (limited to 'LightInstallation.py')
-rw-r--r-- | LightInstallation.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/LightInstallation.py b/LightInstallation.py index e4adab7..e6e5a26 100644 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -3,11 +3,14 @@ from pixelcore.Screen import * from pixelcore.PixelStrip import * import pdb, sys, time, Util, thread from pygame.locals import * +import util.TimeOps as clock +import util.Config as configGetter +import util.ComponentRegistry as compReg #Python class to instantiate and drive a Screen through different patterns, #and effects. class LightInstallation: def __init__(self, configFileName): - self.timer = Util.Stopwatch() + self.timer = clock.Stopwatch() self.timer.start() self.inputs = {} #dict of inputs and their bound behaviors, keyed by InputId self.behaviors = {} @@ -19,10 +22,11 @@ class LightInstallation: #input #give Util a pointer to our componentRegistry and screen so that everyone can use #it - Util.setComponentDict(self.componentDict) + #Util.setComponentDict(self.componentDict) self.screen = Screen() - Util.setScreen(self.screen) - config = Util.loadConfigFile(configFileName) + #Util.setScreen(self.screen) + compReg.registerComponent(self.screen, 'Screen') #TODO: move to constants file + config = configGetter.loadConfigFile(configFileName) #read configs from xml rendererConfig = config.find('RendererConfiguration') pixelConfig = config.find('PixelConfiguration') @@ -68,14 +72,15 @@ class LightInstallation: cid = component['Id'] if cid == None: raise Exception('Components must have Ids!') - self.componentDict[cid] = component + #self.componentDict[cid] = component + compReg.registerComponent(component) def initializeComponent(self, config): components = [] if config != None: for configItem in config.getchildren(): [module,className] = configItem.find('Class').text.split('.') exec('from ' + module+'.'+className + ' import *') - args = Util.generateArgDict(configItem.find('Args')) + args = configGetter.generateArgDict(configItem.find('Args')) args['parentScope'] = self #TODO: we shouldn't give away scope #like this, find another way. components.append(eval(className+'(args)')) #TODO: doesn't error @@ -85,12 +90,12 @@ class LightInstallation: return True def mainLoop(self): #self.screen.allOn() - lastLoopTime = Util.time() + lastLoopTime = clock.time() refreshInterval = 30 runCount = 10000 while runCount > 0: runCount -= 1 - loopStart = Util.time() + loopStart = clock.time() responses = self.evaluateBehaviors() #inputs are all queued when they #happen, so we only need to run the behaviors self.timer.start() @@ -98,7 +103,7 @@ class LightInstallation: response != []] self.screen.timeStep() [r.render(self.screen) for r in self.renderers] - loopElapsed = Util.time()-loopStart + loopElapsed = clock.time()-loopStart sleepTime = max(0,refreshInterval-loopElapsed) self.timer.stop() #print self.timer.elapsed() @@ -132,8 +137,11 @@ class LightInstallation: def processResponse(self,inputDict, responseDict): inputId = inputDict['Id'] boundBehaviorIds = self.inputBehaviorRegistry[inputId] - [self.componentDict[b].addInput(responseDict) for b in boundBehaviorIds] - + #TODO: fix this, it crashes because inputs get run before beahviors exist + try: + [compReg.getComponent(b).addInput(responseDict) for b in boundBehaviorIds] + except: + print 'Behaviors not initialized yet. WAIT!' def main(argv): print argv if len(argv) == 1: |