aboutsummaryrefslogtreecommitdiff
path: root/behaviors/AddPixelEvent.py
blob: da3f7c2fe1b243e3a5d79872c46f0ad8970db510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from operationscore.Behavior import *
import util.Strings as Strings
from logger import main_log
class AddPixelEvent(Behavior):
    """AddPixelEvent is a behavior to append an arbitrary PixelEvent to a behavior response.  The
    classname of the PixelEvent should be specified in the Class field of Args.  All arguments normally
    passed to the PixelEvent should also be specified in Args."""
    def behaviorInit(self):
        [module, className] = self['Class'].split('.')
        try:
            exec('from ' + module+'.'+className + ' import *', globals())
        except Exception as inst:
            main_log.error('Error importing ' + module+'.'+className+ '.  Component not\
            initialized.')
            main_log.error(str(inst)) 
        self.eventGenerator = eval('lambda args:'+className+'(args)') 
        
        #^lambda function to do generate new event (takes args)
    
    def processResponse(self, sensors, recurses):
        ret = []
        for sensory in sensors:
            outDict = {}
            outDict[Strings.LOCATION] = sensory[Strings.LOCATION]
            settingsDict = dict(self.argDict)
            settingsDict['Color'] = sensory['Color']
            outDict['PixelEvent'] = self.eventGenerator(settingsDict)
            ret.append(outDict)
        return (ret, recurses)