Exemple #1
0
 def test_SDL_GetVersion(self):
     v = version.SDL_version()
     version.SDL_GetVersion(ctypes.byref(v))
     assert type(v) == version.SDL_version
     assert v.major == 2
     assert v.minor == 0
     assert v.patch >= 5
Exemple #2
0
 def test_SDL_GetVersion(self):
     v = version.SDL_version()
     version.SDL_GetVersion(ctypes.byref(v))
     self.assertEqual(type(v), version.SDL_version)
     self.assertEqual(v.major, 2)
     self.assertEqual(v.minor, 0)
     self.assertEqual(v.patch, 6)
def main():
    # install a signal handler so the script can stop safely
    def signal_handler(signum, frame):
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        signal.signal(signal.SIGTERM, signal.SIG_IGN)
        if tty_fd:
            os.close(tty_fd)
        if SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK:
            SDL_QuitSubSystem(SDL_INIT_JOYSTICK)
        SDL_Quit()
        LOG.debug(f'{sys.argv[0]} exiting cleanly')
        sys.exit(0)

    debug_flag, hex_chars = parse_arguments(sys.argv)
    if debug_flag:
        LOG.setLevel(logging.DEBUG)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)
    # daemonize after signal handlers are registered
    if os.fork():
        os._exit(0)

    try:
        tty_fd = os.open('/dev/tty', os.O_WRONLY)
    except IOError:
        LOG.error('Unable to open /dev/tty', file=sys.stderr)
        sys.exit(1)

    curses.setupterm()
    mapped_chars = [
        get_hex_chars(code) for code in hex_chars
        if get_hex_chars(code) is not None
    ]

    def_buttons = [
        'left', 'right', 'up', 'down', 'a', 'b', 'x', 'y', 'pageup', 'pagedown'
    ]
    joy_map = {}
    # add for each button the mapped keycode, based on the arguments received
    for i, btn in enumerate(def_buttons):
        if i < len(mapped_chars):
            joy_map[btn] = mapped_chars[i]

    menu_swap = ra_btn_swap_config()
    # if button A is <enter> and menu_swap_ok_cancel_buttons is true, swap buttons A and B functions
    if menu_swap \
            and 'a' in joy_map.keys() \
            and 'b' in joy_map.keys() \
            and joy_map['a'] == '\n':
        joy_map['a'] = joy_map['b']
        joy_map['b'] = '\n'

    # tell SDL that we don't want to grab and lock the keyboard
    os.environ['SDL_INPUT_LINUX_KEEP_KBD'] = '1'

    # disable the HIDAPI joystick driver in SDL
    if not (SDL_USE_HIDAPI):
        os.environ['SDL_JOYSTICK_HIDAPI'] = '0'

    # tell SDL to not add any signal handlers for TERM/INT
    os.environ['SDL_NO_SIGNAL_HANDLERS'] = '1'

    configs = get_all_ra_config(def_buttons)

    if SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) < 0:
        LOG.error(f'Error in SDL_Init: {SDL_GetError()}')
        exit(2)

    if LOG.isEnabledFor(logging.DEBUG):
        sdl_ver = version.SDL_version()
        version.SDL_GetVersion(byref(sdl_ver))
        wrapper_version = '.'.join(str(i) for i in version_info)
        LOG.debug(
            f'Using SDL Version {sdl_ver.major}.{sdl_ver.minor}.{sdl_ver.patch}, PySDL2 version {wrapper_version}'
        )

    if joystick.SDL_NumJoysticks() < 1:
        LOG.debug(f'No available joystick devices found on startup')

    event_loop(configs, joy_map, tty_fd)

    SDL_QuitSubSystem(SDL_INIT_JOYSTICK)
    SDL_Quit()
    return 0
Exemple #4
0
 def test_SDL_version(self):
     v = version.SDL_version(0, 0, 0)
     assert v.major == 0
     assert v.minor == 0
     assert v.patch == 0
Exemple #5
0
 def test_SDL_version(self):
     v = version.SDL_version(0, 0, 0)
     self.assertEqual(v.major, 0)
     self.assertEqual(v.minor, 0)
     self.assertEqual(v.patch, 0)
Exemple #6
0
 def get_library_version(self):
     v = version.SDL_version()
     sdl2.SDL_GetVersion(v)
     return v.major, v.minor, v.patch