Exemplo n.º 1
0
 def manage_projectors(self, control, minutes):
     inactivity_time = self.get_minutes( self.cast_time_to_timedelta( control.inactivity_time ) ) 
     logger.debug("Projector inactivity time = %s\ndiff time = %s\nis_projectors_on = %s" % (inactivity_time, minutes, self.projectors_on))
     
     if minutes > inactivity_time and self.projectors_on:
         logger.info("Turning Projectors Off")   
         self.turn_projectors_power(0)     
Exemplo n.º 2
0
    def set_foreground(self, handler):
        """put the window in the foreground"""

        if handler != None:
            win32gui.ShowWindow(handler, SET_FULLSCREEN)
            win32gui.SetForegroundWindow(handler)
            logger.info("changed to window with handler %d" % int(handler))
Exemplo n.º 3
0
 def execute (self, is_screensaver=False):
     """Executes within a thread"""
     app_mutex = get_app_mutex()
     if app_mutex.testandset():
         t = Thread( target=self._execute, args=( is_screensaver, ) )
         t.start()
     else:
         logger.info("NOT RUNNING %s: some application is already running" % self.name)
Exemplo n.º 4
0
 def execute(self):
     self.start_sockets()
     logger.info("PROXY SOCKETS STARTED")
     while self.flag:
         data = self.receive_sock.recv( 30 * 1024 ) # buffer size is 30 * 1024 bytes
         self.send_sock.sendto( data, (PROXY_UDP_IP, PROXY_SENDING_PORT_ONE) )
         if is_app_running():
             self.send_sock.sendto( data, (PROXY_UDP_IP, PROXY_SENDING_PORT_TWO) )
Exemplo n.º 5
0
 def execute(self, is_screensaver=False):
     """Executes within a thread"""
     app_mutex = get_app_mutex()
     if app_mutex.testandset():
         t = Thread(target=self._execute, args=(is_screensaver, ))
         t.start()
     else:
         logger.info("NOT RUNNING %s: some application is already running" %
                     self.name)
Exemplo n.º 6
0
 def turn_projectors_power(self, status):
     if not self.in_schedule():
         logger.info("NOT IN SCHEDULE. Projectors will remain with the previous state")
         return
     
     try:
         projectors.projectors_power(status)
         logger.info("Projectors status changed to %d" % status)
     except Exception, e:
         logger.error('Error changing projectors status:\n%s' % e)
Exemplo n.º 7
0
 def run(self):
     logger.info("PROXY RUNNING")
     try:
         self.execute()
         logger.info("PROXY STOPPED")
     except Exception, e: #Pokemon
         if logger:
             logger.error("EXCEPTION ON PROXY:\n%s" % e)
         else:
             print "Exception on Proxy:", e
Exemplo n.º 8
0
 def execute(self):
     self.start_sockets()
     logger.info("PROXY SOCKETS STARTED")
     while self.flag:
         data = self.receive_sock.recv(
             30 * 1024)  # buffer size is 30 * 1024 bytes
         self.send_sock.sendto(data, (PROXY_UDP_IP, PROXY_SENDING_PORT_ONE))
         if is_app_running():
             self.send_sock.sendto(data,
                                   (PROXY_UDP_IP, PROXY_SENDING_PORT_TWO))
Exemplo n.º 9
0
 def run(self):
     logger.info("PROXY RUNNING")
     try:
         self.execute()
         logger.info("PROXY STOPPED")
     except Exception, e:  #Pokemon
         if logger:
             logger.error("EXCEPTION ON PROXY:\n%s" % e)
         else:
             print "Exception on Proxy:", e
Exemplo n.º 10
0
    def on_gesture(self, gesture, touch):

        logger.debug("PROJECTORS STATE: %d" % self.activity_checker.projectors_on)

        if not self.activity_checker.projectors_on:
            logger.info('Turning Projectors On')
            self.activity_checker.turn_projectors_power(1)
        self.activity_checker.set_last_activity()
            
        logger.debug('gesture: %d' % self.counter)
        self.counter += 1
        #print self.gestures.gesture_to_str(gesture)
        
        # gesture recognition
        if self.gestures.find(gesture, GESTURE_ACCEPTANCE_MARGIN) and is_app_running():
            logger.debug("gesture recognized")
            kill_app_running()
Exemplo n.º 11
0
    def open_app(self):
        logger.info('\nLoading %s...\n' % unicode(self.app))
        logger.info('ID: %i' % self.app.id)
        logger.info('Path: %s\n' % self.app.get_extraction_fullpath())
        logger.info('Boot file: %s\n' % self.app.get_boot_file())
        self.app.execute()

        #refresh cstegory in main thread
        from mtmenu import categories_list
        categories_list.refresh()
        self.parent.refresh(categories_list.current)
Exemplo n.º 12
0
    def open_app(self):
        logger.info('\nLoading %s...\n' % unicode(self.app))
        logger.info('ID: %i' % self.app.id)
        logger.info('Path: %s\n' % self.app.get_extraction_fullpath())
        logger.info('Boot file: %s\n' % self.app.get_boot_file())
        self.app.execute()

        #refresh cstegory in main thread
        from mtmenu import categories_list
        categories_list.refresh()
        self.parent.refresh(categories_list.current)
Exemplo n.º 13
0
    def on_gesture(self, gesture, touch):

        logger.debug("PROJECTORS STATE: %d" %
                     self.activity_checker.projectors_on)

        if not self.activity_checker.projectors_on:
            logger.info('Turning Projectors On')
            self.activity_checker.turn_projectors_power(1)
        self.activity_checker.set_last_activity()

        logger.debug('gesture: %d' % self.counter)
        self.counter += 1
        #print self.gestures.gesture_to_str(gesture)

        # gesture recognition
        if self.gestures.find(gesture,
                              GESTURE_ACCEPTANCE_MARGIN) and is_app_running():
            logger.debug("gesture recognized")
            kill_app_running()
Exemplo n.º 14
0
def bring_window_to_front(toApp=False):
    ''' Bring the WallManager window to the front'''
    from mtmenu import self_hwnd

    hwnd = None

    w = WindowMgr()
    if toApp:

        for i in range(MAX_ATTEMPTS):
            # loop for the open windows on the desktop
            for handler, name in w.getWindows():
                logger.debug("Window opened with name %s" % name)
                if handler != self_hwnd and name not in NATIVE_APP_NAMES:
                    hwnd = handler
                    logger.info('Changing context to handler %d with name %s' %
                                (handler, name))
                    break
            if hwnd != None:
                break
            sleep(SLEEP_SECONDS_BETWEEN_ATTEMPTS)

        logger.debug("Got handler %d" % hwnd)
        if hwnd == None:
            hwnd = self_hwnd

    else:
        hwnd = self_hwnd
        logger.info("Going back to the main application")

        for handler, name in w.getWindows():
            logger.debug("Window opened with name %s" % name)
            if handler != self_hwnd and name not in NATIVE_APP_NAMES:

                tid, pid = win32process.GetWindowThreadProcessId(handler)
                if PRODUCTION:
                    Popen("taskkill /F /T /PID %i" % pid, shell=True)

                logger.debug('killing %s with PID %d' % (name, pid))

    w.set_foreground(hwnd)
Exemplo n.º 15
0
def bring_window_to_front(toApp = False):
    ''' Bring the WallManager window to the front'''
    from mtmenu import self_hwnd
    
    hwnd = None
    
    w = WindowMgr()
    if toApp:
        
        for i in range(MAX_ATTEMPTS):
            # loop for the open windows on the desktop
            for handler, name in w.getWindows():
                logger.debug("Window opened with name %s" % name)
                if handler != self_hwnd and name not in NATIVE_APP_NAMES:
                    hwnd = handler
                    logger.info('Changing context to handler %d with name %s' % (handler, name))
                    break
            if hwnd != None:
                break
            sleep(SLEEP_SECONDS_BETWEEN_ATTEMPTS)
        
        logger.debug("Got handler %d" % hwnd)    
        if hwnd == None:
            hwnd = self_hwnd
            
    else:
        hwnd = self_hwnd
        logger.info("Going back to the main application")
        
        for handler, name in w.getWindows():
            logger.debug("Window opened with name %s" % name)
            if handler != self_hwnd and name not in NATIVE_APP_NAMES:
                
                tid, pid = win32process.GetWindowThreadProcessId(handler)
                if PRODUCTION:
                    Popen("taskkill /F /T /PID %i" % pid, shell=True)
                
                logger.debug('killing %s with PID %d' % (name, pid))
        
    w.set_foreground(hwnd)
Exemplo n.º 16
0
    def _execute(self, is_screensaver):
        """Tries to execute application's batch file.
        
        While is executing all process output (stdout/stderr) is catched 
        and handled later on when the application is terminated. 
        
        This method blocks until the application exits. Use run() instead.

        Returns:
            True if application is successfuly executed. 
            False is returned whether there is no boot file or another application is already running.
            
        Raises:
            An Exception is raised in case something goes wrong during
            process execution"""
            
            
        #hide scatter
        
        logger.info('running application: %s' % self.name)
        
        if (is_app_running()):
            get_app_mutex().unlock()
            return False
          
        
        app_boot_file = self.get_boot_file()
        success = False
        
        if app_boot_file:
            
            try:
                from mtmenu import cover_window
                cover_window.show()
                
                self.start_run()
                
                command = self.build_command(app_boot_file)
                
                # Starts application process and waits for it to terminate
                process = Popen(command, stdout = PIPE, stderr = PIPE, cwd = self.get_extraction_fullpath(), shell = False)
                
                # defines the application that is running
                set_app_running(process)
                
                
                from utils import bring_window_to_front
                bring_window_to_front(True)
                
                # Concatenate output
                output = StringIO()
                for line in process.communicate():
                    output.write(line)


                remove_app_running()
                
                cover_window.resume(self, is_screensaver)
                        
                self.end_run()                
                
                # Save output to database
                self.add_log_entry(output.getvalue())    
                    
                success = True
                logger.info("Application %s terminated" % self.name)
            except Exception, e: #Pokemon
                logger.error("EXCEPTION RUNNING APPLICATION:\n%s" % e)
Exemplo n.º 17
0
 def __init__(self, checker):
     super(GestureWidget, self).__init__()
     self.gestures = Gestures()
     self.counter = 0
     self.activity_checker = checker
     logger.info('Gesture loaded')
Exemplo n.º 18
0
 def __init__(self, checker):
     super(GestureWidget, self).__init__()
     self.gestures = Gestures()
     self.counter = 0
     self.activity_checker = checker
     logger.info('Gesture loaded')
Exemplo n.º 19
0
    def _execute(self, is_screensaver):
        """Tries to execute application's batch file.
        
        While is executing all process output (stdout/stderr) is catched 
        and handled later on when the application is terminated. 
        
        This method blocks until the application exits. Use run() instead.

        Returns:
            True if application is successfuly executed. 
            False is returned whether there is no boot file or another application is already running.
            
        Raises:
            An Exception is raised in case something goes wrong during
            process execution"""

        #hide scatter

        logger.info('running application: %s' % self.name)

        if (is_app_running()):
            get_app_mutex().unlock()
            return False

        app_boot_file = self.get_boot_file()
        success = False

        if app_boot_file:

            try:
                from mtmenu import cover_window
                cover_window.show()

                self.start_run()

                command = self.build_command(app_boot_file)

                # Starts application process and waits for it to terminate
                process = Popen(command,
                                stdout=PIPE,
                                stderr=PIPE,
                                cwd=self.get_extraction_fullpath(),
                                shell=False)

                # defines the application that is running
                set_app_running(process)

                from utils import bring_window_to_front
                bring_window_to_front(True)

                # Concatenate output
                output = StringIO()
                for line in process.communicate():
                    output.write(line)

                remove_app_running()

                cover_window.resume(self, is_screensaver)

                self.end_run()

                # Save output to database
                self.add_log_entry(output.getvalue())

                success = True
                logger.info("Application %s terminated" % self.name)
            except Exception, e:  #Pokemon
                logger.error("EXCEPTION RUNNING APPLICATION:\n%s" % e)
Exemplo n.º 20
0
 def manage_screensaver(self, control, minutes):
     inactivity_time = self.get_minutes( self.cast_time_to_timedelta( control.inactivity_time ) )
     application = ApplicationProxy.objects.filter(id = control.application.id)[0]    
     if minutes > inactivity_time and not is_app_running() and application:
         logger.info('Launching Screensaver')
         application.execute(True)