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)
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))
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)
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) )
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)
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)
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
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))
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()
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)
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)
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)
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)
def __init__(self, checker): super(GestureWidget, self).__init__() self.gestures = Gestures() self.counter = 0 self.activity_checker = checker logger.info('Gesture loaded')
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)
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)