示例#1
0
    def __init__(self, args=None):
        super().__init__(target=self.key_listener)
        # queue for getting info from 1st process
        self.q1, self.q2, self.joy_n = args

        # Set up the GUI part
        self.joy = BotController.VXBOX_Device(self.joy_n)

        self.running = True
        self.playing = False
        self.hks_on = False
        self.rest = True
        # ignore action interval (set to False at end of loops)
        self.iai = False
        #holds all hotkeys
        self.hotkeys = []
        self.hk_names = []
        #holds all action strings
        self.strings = []
        self.pending = []
        # variable for making sure client process has been informed
        self.client_informed = False
示例#2
0
    def processIncoming(self):
        # unpack data from queue

        # may need to find a more robust way of doing this. Test for speed
        #begin = time.time()
        while self.q1.qsize():
            try:
                info = self.q1.get(0)
                if info is not None:
                    # True or False
                    try:
                        self.cfg = info['cfg']
                    except Exception as e:
                        pass
                        #print(e)

                    try:
                        self.joycfg = info['joycfg']
                    except Exception as e:
                        pass

                    try:
                        self.playing = info['playing']

                        if self.playing == True:
                            self.rest = False
                            #print"self.playing = True")
                            #if self.strings == []:
                            self.strings = info['actlist']
                        else:
                            self.rest = True
                            #print"self.playing = False")
                            self.strings = []

                        self.client_informed = True
                        self.pending = []

                    except Exception as e:
                        pass
                        #print("PLAYING EXCEPTION: ", e)

                    try:
                        n = int(info['joy'])
                        #print("joy number: ", n)
                        if n != self.joy_n:
                            self.joy = BotController.VXBOX_Device(n)

                    except Exception as e:
                        pass

                    try:
                        self.settings = info['settings']
                        self.fps = int(self.settings['fps'])
                        self.start_delay_t = float(
                            self.settings['start delay'])
                        self.act_int_t = float(self.settings['ADI'])
                        self.defaultdir = self.settings['default direction']
                    except Exception as e:
                        #print("SETTINGS: ", e)
                        pass
                    try:
                        self.custom_delays = info['delay tuners']
                        #print"new custom delays: ", self.custom_delays)
                        self.fps = int(self.custom_delays['fps'])
                        self.act_int_t = float(self.custom_delays['ADI'])
                        print("action interval: {}; custom delays: {}".format(
                            self.act_int_t, self.custom_delays))
                    except Exception as e:
                        #print("custom delay error: ", e)
                        pass

                    try:
                        self.hks_on = info['hks on']
                    except Exception as e:
                        pass
                        # print("HKS ON: ", e)
                    try:
                        self.facing = info['facing']
                    except Exception as e:
                        #print("FACING: ", e)
                        pass
                    try:
                        if info['hks on'] == True:
                            # throw error if bus driver doesn't exist
                            self.check_for_vbus()
                            # turn on controller
                            self.joy.TurnOn()

                            for k, v in self.cfg.items():
                                hk = v['Hotkey']
                                try:
                                    string = eval(v['String'])
                                except:
                                    string = v['String']
                                notation = v['Notation']

                                if hk not in [
                                        "None", "'None'"
                                ] and string not in [
                                        "None", "'None'"
                                ] and hk != None and string != None and hk not in self.hk_names:
                                    try:
                                        key = keyboard.add_hotkey(
                                            str(hk),
                                            self.perform_hk,
                                            args=(notation, string))
                                        #print"appending {} to list".format(hk))
                                        self.hk_names.append(hk)
                                        self.hotkeys.append(key)
                                    except:
                                        pass

                            if 'play hotkey' not in self.hk_names:
                                print("play hotkey added")
                                v = self.settings['play hotkey']
                                key = keyboard.add_hotkey(
                                    str(v), self.toggle_play)
                                self.hk_names.append('play hotkey')
                                self.hotkeys.append(key)

                            if 'switch sides hotkey' not in self.hk_names:
                                v = self.settings['switch sides hotkey']
                                key = keyboard.add_hotkey(
                                    str(v), self.switch_sides)
                                self.hk_names.append('switch sides hotkey')
                                self.hotkeys.append(key)

                            # if 'increase tuner hotkey' not in self.hk_names:
                            #     v = self.settings['increase tuner hotkey']
                            #     #print'increase tuner appended')
                            #     key = keyboard.add_hotkey(str(v), self.increase_tuner)
                            #     self.hk_names.append('increase tuner hotkey')
                            #     self.hotkeys.append(key)
                            #
                            # if 'decrease tuner hotkey' not in self.hk_names:
                            #     v = self.settings['decrease tuner hotkey']
                            #     #print'decrease tuner appended')
                            #     key = keyboard.add_hotkey(str(v), self.decrease_tuner)
                            #     self.hk_names.append('decrease tuner hotkey')
                            #     self.hotkeys.append(key)
                            #
                            # if 'next tuner hotkey' not in self.hk_names:
                            #     v = self.settings['next tuner hotkey']
                            #     #print'increase adi hk appended')
                            #     key = keyboard.add_hotkey(str(v), self.next_tuner)
                            #     self.hk_names.append('next tuner hotkey')
                            #     self.hotkeys.append(key)
                            #
                            # if 'previous tuner hotkey' not in self.hk_names:
                            #     v = self.settings['previous tuner hotkey']
                            #     #print'previous tuner hk appended')
                            #     key = keyboard.add_hotkey(str(v), self.prev_tuner)
                            #     self.hk_names.append('previous tuner hotkey')
                            #     self.hotkeys.append(key)

                            for k, v in self.joycfg.items():
                                hk = v['Hotkey']
                                try:
                                    string = eval(v['String'])
                                except:
                                    string = v['String']

                                notation = v['Notation']

                                if hk not in [
                                        "None", "'None'"
                                ] and string not in [
                                        "None", "'None'"
                                ] and hk != None and string != None and hk not in self.hk_names:
                                    try:
                                        key = keyboard.add_hotkey(
                                            str(hk),
                                            self.perform_hk,
                                            args=(notation, string))
                                        self.hk_names.append(hk)
                                        self.hotkeys.append(key)
                                    except:
                                        pass

                        else:
                            #print"hks off")
                            # turn off controller
                            self.joy.TurnOff()

                            # unbind hotkeys
                            for k in self.hotkeys:
                                try:
                                    keyboard.remove_hotkey(k)
                                except:
                                    pass
                            # empty containers
                            self.strings = []
                            self.hotkeys = []
                            self.hk_names = []
                            self.pending = []
                    except Exception as e:
                        print("HKS: ", e)
                        #pass

            except Exception as e:
                msg = "{}: {}".format(type(e).__name__, e.args)