示例#1
0
 def cmd_line(self, config_file_name):
     self._CONFIG_O = Config(config_file_name)
     self._rf2path = Path(self._CONFIG_O.get_rfactor_folder()).expandvars()
     #self._rf2path = r'c:\Temp\dummy Rf2'
     self._mm_o = Mod_manager(self._rf2path)
     if not self._mm_o:
         SystemExit(99)
     return Path(self._rf2path)  # for unit test
示例#2
0
class Mod_manager_app:
    def cmd_line(self, config_file_name):
        self._CONFIG_O = Config(config_file_name)
        self._rf2path = Path(self._CONFIG_O.get_rfactor_folder()).expandvars()
        #self._rf2path = r'c:\Temp\dummy Rf2'
        self._mm_o = Mod_manager(self._rf2path)
        if not self._mm_o:
            SystemExit(99)
        return Path(self._rf2path)  # for unit test

    def wait_for_rf2_to_start(self):
        self.rf2_o = rF2_check()

        #call('"c:/Program Files(x86)/Steam/steam" -applaunch 365960')
        print('\nWaiting for rFactor 2 to start...')

        while not self.rf2_o.isRF2running():
            sleep(.2)

        print('\nrFactor 2 started')

    def set_up(self):
        self._mm_o.setup()
        for location in self._CONFIG_O.get_locations():
            if not self._mm_o.select_mod(('Locations', location)):
                print(f'Locations {location} not found')

        for vehicle in self._CONFIG_O.get_vehicles():
            if not self._mm_o.select_mod(('Vehicles', vehicle)):
                print(f'Vehicles {vehicle} not found')
        # for unit test:
        return (self._CONFIG_O.get_locations(), self._CONFIG_O.get_vehicles())

    def start_rf2_single_player(self):
        self.rf2_o = rF2_check()
        _pop = os.getcwd()  # save current directory
        os.chdir(self._rf2path)
        cmd = '"' + str(self._rf2path) + \
            r'\Bin64\rFactor2.exe"  +singleplayer +path="."'
        print(cmd)
        call(cmd)  # actually, it doesn't return until rf2 exits
        os.chdir(_pop)

    def wait_for_rf2_to_exit(self):
        print('\nWaiting for rFactor 2 to exit...')
        while self.rf2_o.isRF2running():
            sleep(1)

        print('\nrFactor 2 exited')

    def tear_down(self):
        #self._mm_o.repair()
        self._mm_o.unselect_mods()
示例#3
0
 def __init__(self) -> None:
     """ docstring """
     config_o = Config()
     if config_o.get('rFactor Toggle', 'controller') == KEYBOARD:
         self.headlightToggleDIK = config_o.get('rFactor Toggle', 'control')
         # (it must be)
         if self.headlightToggleDIK not in DirectInputKeyCodeTable:
             print('\nheadlight toggle button "%s" not recognised.\n'
                   'It must be one of:' % self.headlightToggleDIK)
             for _keyCode in DirectInputKeyCodeTable:
                 print(_keyCode, end=', ')
             quit_program(99)
     else:
         status_poker_fn('\nHeadlight toggle control must be a key.\n')
         quit_program(99)
示例#4
0
def main():
    """ docstring """
    headlightFlash_o = HeadlightControl()
    config_o = Config()

    def pit_limiter():
        return config_o.get('miscellaneous', 'pit_limiter') == '1'

    def pit_lane():
        return config_o.get('miscellaneous', 'pit_lane') == '1'

    def flash_duration():
        return int(config_o.get('miscellaneous', 'flash_duration'))

    def pit_flash_duration():
        return int(config_o.get('miscellaneous', 'pit_flash_duration'))

    def default_to_on():
        return config_o.get('miscellaneous', 'default_to_on') == '1'

    def on_automatically():
        return int(config_o.get('miscellaneous', 'on_automatically'))

    _root, tabConfigureFlash = gui_main()
    _player_is_driving = False
    _o_run = run(_root, tabConfigureFlash)
    _o_run.controller_o.start_pit_check_timer()  # Start the 1 second timer
    while True:
        _cmd = _o_run.running()
        if headlightFlash_o.player_is_driving():
            if not _player_is_driving:
                # First time player takes control
                _player_is_driving = True
                if default_to_on():
                    status_poker_fn('default_to_on')
                    headlightFlash_o.on()

            if _cmd == 'Headlights off':
                headlightFlash_o.on()
            if _cmd == 'Headlights on':
                headlightFlash_o.off()
            if _cmd == 'Flash headlights':
                headlightFlash_o.four_flashes(flash_duration())
            if _cmd == 'Toggle headlights':
                headlightFlash_o.toggle()
            if _cmd == TIMER_EVENT:
                if pit_limiter():
                    headlightFlash_o.check_pit_limiter(pit_flash_duration())
                if pit_lane():
                    headlightFlash_o.check_pit_lane(pit_flash_duration())
                headlightFlash_o.automatic_headlights(on_automatically())
        else:
            _player_is_driving = False
        if _cmd == 'QUIT':
            break
示例#5
0
class Run:
    """ The external interface """
    controller_o = Controller()
    config_o = Config()
    root = None
    xyPadding = 10
    pygame_event = None

    def tk_event_callback(self, _event):  # pylint: disable=no-self-use
        """ docstring """
        global tk_event  # pylint: disable=global-statement
        tk_event = _event

    def __init__(self, parentFrame, _root):
        """ Put this into the parent frame """
        self.root = _root
        self.parentFrame = parentFrame
        icon(self.root)
        _keyboard_control = False
        for name in headlight_controls:
            if self.config_o.get(name, 'Controller') == KEYBOARD:
                _keyboard_control = True
                break
        """
        tk.Label(self.parentFrame,
                 text="This window is only needed to capture keyboard input").\
            grid(row=0, column=0)
        """
        if _keyboard_control:
            root.bind('<KeyPress>', self.tk_event_callback)
        """
        else:  # minimise the windown
            self.root.wm_state('iconic')
        """

    def pygame_callback(self, event):
        """ docstring """
        self.pygame_event = event

    def running(self):
        """ docstring """
        global tk_event  # pylint: disable=global-statement
        tk_event = None
        self.pygame_event = None
        while True:  # pylint: disable=too-many-nested-blocks
            while not tk_event and not self.pygame_event:
                # Run pygame and tk to get latest input
                self.controller_o.pygame_tk_check(self.pygame_callback,
                                                  self.parentFrame)
            if tk_event:
                if tk_event == 'QUIT':
                    return 'QUIT'
                dik = KeycodeToDIK(tk_event.keycode)
                for cmd in headlight_controls:
                    if self.config_o.get(cmd, 'Controller') == KEYBOARD:
                        if dik == self.config_o.get(cmd, 'Control'):
                            return cmd
                tk_event = None
            if self.pygame_event:
                if self.pygame_event == 'QUIT':
                    return 'QUIT'
                if self.pygame_event == TIMER_EVENT:
                    return TIMER_EVENT
                try:
                    _button = str(self.pygame_event.button)
                    _joy = self.controller_o.controller_names[
                        self.pygame_event.joy]
                    #print(_joy, _button)
                    for cmd in headlight_controls:
                        if self.config_o.get(cmd, 'Controller') == _joy:
                            if _button == self.config_o.get(cmd, 'Control'):
                                return cmd
                except:  # pylint: disable=bare-except
                    # not a joystick button
                    pass
                self.pygame_event = None
示例#6
0
class Tab:
    """ Configure the headlight control app """
    parentFrame = None
    controller_o = Controller()
    config_o = Config()
    root = None
    xyPadding = 10

    def __tk_event_callback(self, _event):  # pylint: disable=no-self-use
        """ docstring """
        global tk_event  # pylint: disable=global-statement
        tk_event = _event
        if tk_event == 'QUIT':
            sys.exit(0)

    def __init__(self, parentFrame, _root):
        """ Put this into the parent frame """
        self.root = _root
        self.parentFrame = parentFrame
        icon(self.root)

        self.root.bind('<KeyPress>', self.__tk_event_callback)

        #############################
        # Three sub-frames

        self.headlight_controls_frame_o = headlightControlsFrame(
            self.parentFrame)
        self.headlight_controls_frame_o.tkFrame_headlight_control.grid(
            column=0, row=0, sticky='new', padx=self.xyPadding, rowspan=1)

        self.headlightOptionsFrame_o = headlightOptionsFrame(self.parentFrame)
        self.headlightOptionsFrame_o.tkFrame_headlight_control.grid(
            column=1, row=0, sticky='new', padx=self.xyPadding, rowspan=2)

        self.rFactorStatusFrame_o = rFactorStatusFrame(self.parentFrame)
        self.rFactorStatusFrame_o.tkFrame_headlight_control.grid(
            column=2, row=0, sticky='new', padx=self.xyPadding, rowspan=3)

        self.rf_headlight_control_frame_o = rFactorHeadlightControlFrame(
            self.parentFrame)
        self.rf_headlight_control_frame_o.tkFrame_headlight_control.grid(
            column=0, row=1, sticky='new', padx=self.xyPadding, rowspan=1)

        #############################
        # And a "Save configuration" button
        buttonFont = font.Font(weight='bold', size=10)

        self.tkButtonSave = tk.Button(parentFrame,
                                      text="Save configuration",
                                      width=20,
                                      height=2,
                                      background='green',
                                      font=buttonFont,
                                      command=self.save)
        self.tkButtonSave.grid(column=1, row=1, pady=25, sticky='s')
        #############################

    def save(self):
        """ Save all the settings written to the config data struct """
        self.headlight_controls_frame_o.save()
        self.rf_headlight_control_frame_o.save()
        self.headlightOptionsFrame_o.save()
        self.config_o.write()

    def getSettings(self):  # pylint: disable=no-self-use
        """ Return the settings for this tab """
        return ['Options']

    def setSettings(self, settings):
        """ Set the settings for this tab """
        pass  # pylint: disable=unnecessary-pass
示例#7
0
 def test_nested_config_files(self):
     config_o = Config('1960s_F1.modlist.txt ')
     locations = config_o.get_locations()
     vehicles = config_o.get_vehicles()
     assert locations
     assert vehicles
示例#8
0
            except json.JSONDecodeError:
                pass

    def get_item(self, item_name):
        for section, items in self.dict.items():
            if item_name in items:
                value = items[item_name]
                return value
        return None


if __name__ == "__main__":
    # Test
    from configIni import Config
    from pyDirectInputKeySend.directInputKeySend import rfKeycodeToDIK
    _CONFIG_O = Config()
    _controller_file = _CONFIG_O.get_controller_file()
    _JSON_O = Json(_controller_file)
    headlight_control = _JSON_O.get_item("Control - Headlights")
    if headlight_control:
        print(F'headlight_control: {headlight_control}')
        keycode = rfKeycodeToDIK(headlight_control[1])
        rf2headlights_keycode = _CONFIG_O.get('rFactor Toggle', 'Control')
        if keycode == rf2headlights_keycode:
            print(F'Match: {keycode}')
        else:
            print(
                F"Doesn't match: rF2 keycode {keycode} : rf2headlights keycode {rf2headlights_keycode}"
            )
    else:
        print(F'"Control - Headlights" not in {_controller_file}')