def compute_position(self, current_x, current_y, frame, area): self.direction = 'None' try: self.config = json.load(open('config.json', 'r')) self.prev_x = self.config['prevX'] self.prev_y = self.config['prevY'] self.config['noCnt'] = 0 except: self.config['prevX'] = 0 self.config['prevY'] = 0 if (frame % 5 == 0): self.config['prevX'] = current_x self.config['prevY'] = current_y self.current_x = current_x self.current_y = current_y # self.direction =[] length = self.get_length( self.prev_x, self.prev_y, self.current_x, self.current_y) active_window = win32gui.GetWindowText( win32gui.GetForegroundWindow()) self.direction = 'None' for window in self.config.get('allowed_windows'): if window.get('name') in active_window and window.get('works_on') == 'Face': # print window.get('name') + ' found. WORKING' self.direction = self.get_direction( self.prev_x, self.prev_y, self.current_x, self.current_y, length, area) # self.perform_action() json.dump( self.config, open('config.json', 'w'), sort_keys=True, indent=4) if active_window == "Travel": return self.direction else: # self.direction = str(self.direction) # print self.direction action.perform_action(self.config, self.direction, 'Face') return self.direction else: return self.direction
def perform_action(self,direction): action.perform_action(self.config, direction, 'Face')