Пример #1
0
class DIM:
    def __init__(self, host, port):
        # sageGate is the network connection with SAGE
        self.sageGate = SageGate()
        setSageGate(self.sageGate)

        # the event manager takes care of properly dispatching events
        self.evtMgr = EventManager()
        setEvtMgr(self.evtMgr)
        self.evtMgr.addHandlers()

        # sageData keeps the current state of the SAGE windows/apps
        self.sageData = SageData()
        setSageData(self.sageData)
        
        # overlay manager creates, destroys and updates overlays
        self.overlayMgr = OverlayManager()
        setOverlayMgr(self.overlayMgr)

        # contains all the devices and takes care of loading plugins for them
        # also, distributes HW messages to each device 
        self.devMgr = DeviceManager()
        setDevMgr(self.devMgr)

        # connect to SAGE
        for i in range(5):  # try to connect to SAGE for 5 seconds
            if self.sageGate.connectToSage(host, port) != 0:
                self.sageGate.registerSage()
                break
            time.sleep(1)
        else:  # we didn't manage to connect to sage in 5 seconds... so quit
            exitApp()

        # start listening for the device events
        time.sleep(2)   # wait till all the messages come in
        self.listener = Listener(LISTENER_PORT, self.devMgr.onHWMessage)
        self.listener.serve_forever()
Пример #2
0
class DIM:
    
    def __init__(self, host, port, loadState, autosave, doLog):
       
        print "\n\n=========   Starting DIM  ============\n"

        # the log object
        if doLog:
            setLog(Log())
            print "Logging user interaction into: ", getLog().getLogFilename(), "\n\n"

        # sageGate is the network connection with SAGE
        self.sageGate = SageGate()
        setSageGate(self.sageGate)

        # the event manager takes care of properly dispatching events
        self.evtMgr = EventManager()
        setEvtMgr(self.evtMgr)
        self.evtMgr.addHandlers()

        # sageData keeps the current state of the SAGE windows/apps
        self.sageData = SageData(autosave, self.sageGate)
        setSageData(self.sageData)
        
        # overlay manager creates, destroys and updates overlays
        self.overlayMgr = OverlayManager()
        setOverlayMgr(self.overlayMgr)

        # contains all the devices and takes care of loading plugins for them
        # also, distributes HW messages to each device 
        self.devMgr = DeviceManager()
        setDevMgr(self.devMgr)

        # connect to SAGE
        if (DEBUG):
            print "\n\nRUNNING IN DEBUG MODE!!!!\n\n"
        else:
            time.sleep(2)
        
        for i in range(20):  # try to connect to SAGE for X seconds
            retval = self.sageGate.connectToSage(host, port)
            if retval == 1:
                self.sageGate.registerSage("dim")
                print "DIM: successfully connected to SAGE", (host, port)
                break
            elif retval == 0:
                print "DIM: SAGE", (host, port), "is not ready yet. Retrying..."
            elif retval == -1:
                print "DIM: Couldn't connect to appLauncher. appLauncher is not ready yet. Retrying..."
            time.sleep(1)
        else:  # we didn't manage to connect to sage in X seconds... so quit
            exitApp()

        # start listening for the device events
        time.sleep(2)   # wait till all the messages come in
        self.overlayMgr._addGlobalOverlays()   # add all the UI plugins for the display

        # automatically load a saved state if so desired
        if loadState:
            print "\n===> Autoloading state: ", loadState, "\n"
            t = Timer(3, self.sageData.loadState, [loadState])
            t.start()
        
        self.listener = Listener(LISTENER_PORT, self.devMgr.onHWMessage)
        self.listener.serve_forever()