コード例 #1
0
def main(skin, joy_index):
    all_maps = configurator.load_mappings(skin)

    pygame.display.init()
    pygame.joystick.init()
    new_map = PadMapper(skin, joy_index).get_all_mappings()
    all_maps.update(new_map)

    configurator.save_mappings(skin, all_maps)
コード例 #2
0
def main(skin, joy_index):
    pygame.display.init()
    pygame.joystick.init()

    joy = pygame.joystick.Joystick(joy_index)
    joy.init()
    mappings = configurator.load_mappings(skin)
    if joy.get_name() not in mappings:
        mapper.main(skin, joy_index)
    visualizer.main(skin, joy_index)
コード例 #3
0
ファイル: __main__.py プロジェクト: Gl4dius/padpyght
def main(skin, joy_index):
    pygame.display.init()
    pygame.joystick.init()

    joy = pygame.joystick.Joystick(joy_index)
    joy.init()
    mappings = configurator.load_mappings(skin)
    if joy.get_name() not in mappings:
        mapper.main(skin, joy_index)
    visualizer.main(skin, joy_index)
コード例 #4
0
def main(skin, joy_index):
    pygame.display.init()
    pygame.joystick.init()

    joy = pygame.joystick.Joystick(joy_index)
    joy.init()
    mappings = configurator.load_mappings(skin)
    if joy.get_name() not in mappings:
        print 'Please run the mapper on', joy.get_name(), 'with', skin, 'skin.'
        return

    mappings = mappings[joy.get_name()]

    button_map = mappings.get('button', dict())
    axis_map = mappings.get('axis', dict())
    hat_map = mappings.get('hat', dict())

    pad_cfg = configurator.PadConfig(skin)

    fb = frame_buffer.FrameBuffer(pad_cfg.size, pad_cfg.size,
                                  scale_smooth=pad_cfg.anti_aliasing,
                                  background_color=pad_cfg.background_color)
    pad_gfx = PadImage(pad_cfg, fb)

    while not pygame.event.peek(pygame.QUIT):
        for event in pygame.event.get():
            if event.type == pygame.JOYBUTTONDOWN:
                if str(event.button) in button_map:
                    elt = button_map[str(event.button)]
                    _get_target(pad_gfx, elt).push(1)
            elif event.type == pygame.JOYBUTTONUP:
                if str(event.button) in button_map:
                    elt = button_map[str(event.button)]
                    _get_target(pad_gfx, elt).push(0)
            elif event.type == pygame.JOYAXISMOTION:
                if str(event.axis) in axis_map:
                    for change, elt in axis_map[str(event.axis)].iteritems():
                        change = int(change)
                        value = event.value
                        if abs(change) == 2:
                            value += change / abs(change)
                        value /= change
                        value = max(0, value)
                        _get_target(pad_gfx, elt).push(value)
            elif event.type == pygame.JOYHATMOTION:
                if str(event.hat) in hat_map:
                    direction_map = hat_map[str(event.hat)]
                    x, y = event.value
                    if 'up' in direction_map:
                        _get_target(pad_gfx, direction_map['up']).push(y)
                    if 'down' in direction_map:
                        _get_target(pad_gfx, direction_map['down']).push(-y)
                    if 'left' in direction_map:
                        _get_target(pad_gfx, direction_map['left']).push(-x)
                    if 'right' in direction_map:
                        _get_target(pad_gfx, direction_map['right']).push(x)
            fb.handle_event(event)

        pad_gfx.draw()
        fb.flip()
        fb.limit_fps(set_caption=True)
コード例 #5
0
ファイル: visualizer.py プロジェクト: hellblauHosen/padpyght
def main(skin, joy_index,  is_main_process):
    pygame.display.init()
    pygame.joystick.init()
    pygame.font.init()

    joy = pygame.joystick.Joystick(joy_index)
    joy.init()
    mappings = configurator.load_mappings(skin)
    if joy.get_name() not in mappings:
        print 'Please run the mapper on', joy.get_name(), 'with', skin, 'skin.'
        return

    mappings = mappings[joy.get_name()]

    button_map = mappings.get('button', dict())
    axis_map = mappings.get('axis', dict())
    hat_map = mappings.get('hat', dict())

    pad_cfg = configurator.PadConfig(skin)

    height = pad_cfg.size[1]
    size = pad_cfg.size if is_main_process else (pad_cfg.size[0], height * 10)
    caption = "padpyght" if is_main_process else "input history"
    fb = frame_buffer.FrameBuffer(size, size, caption,
                                  scale_smooth=pad_cfg.anti_aliasing,
                                  background_color=pad_cfg.background_color)
    pad_gfx = images.PadImage(pad_cfg, fb)

    timer_font = pygame.font.SysFont(None, 16)

    # Start the input history service process
    if is_main_process:
        p = Process(target=main, args=(skin, joy_index, False))
        p.start()

    # TODO: May want to initialize all inputs
    last_state = InputState()
    last_font_rect = None

    # Main input/render loop
    while not pygame.event.peek(pygame.QUIT):

        new_state = copy.deepcopy(last_state)

        for event in pygame.event.get():
            if event.type == pygame.JOYBUTTONDOWN:
                if str(event.button) in button_map:
                    elt = button_map[str(event.button)]
                    new_state.button_map[elt['name']] = 1
                    _get_target(pad_gfx, elt).push(1)
            elif event.type == pygame.JOYBUTTONUP:
                if str(event.button) in button_map:
                    elt = button_map[str(event.button)]
                    new_state.button_map[elt['name']] = 0
                    _get_target(pad_gfx, elt).push(0)
            elif event.type == pygame.JOYAXISMOTION:
                if str(event.axis) in axis_map:
                    for change, elt in axis_map[str(event.axis)].iteritems():
                        change = int(change)
                        value = event.value
                        if abs(change) == 2:
                            value += change / abs(change)
                        value /= change
                        value = max(0, value)
                        _get_target(pad_gfx, elt).push(value)
            elif event.type == pygame.JOYHATMOTION:
                if str(event.hat) in hat_map:
                    direction_map = hat_map[str(event.hat)]
                    x, y = event.value
                    if 'up' in direction_map:
                        new_state.button_map[direction_map['up']['name']] = y
                        _get_target(pad_gfx, direction_map['up']).push(y)
                    if 'down' in direction_map:
                        new_state.button_map[direction_map['down']['name']] = -y
                        _get_target(pad_gfx, direction_map['down']).push(-y)
                    if 'left' in direction_map:
                        new_state.button_map[direction_map['left']['name']] = -x
                        _get_target(pad_gfx, direction_map['left']).push(-x)
                    if 'right' in direction_map:
                        new_state.button_map[direction_map['right']['name']] = x
                        _get_target(pad_gfx, direction_map['right']).push(x)
            fb.handle_event(event)

        if is_main_process:
            pad_gfx.draw()
            fb.flip()
        else:
            if last_state != new_state:
                new_state.elapsed_frames = 0
                # print("L: " + str(last_state) + ", N:" + str(new_state))
                fb.scroll(0, height)
                pad_gfx.draw()
                fb.flip()
            else:
                new_state.elapsed_frames += 1

                if last_font_rect is not None:
                    clear_surf = pygame.Surface((last_font_rect.width, last_font_rect.height))
                    clear_surf.fill(pad_cfg.background_color)
                    fb.blit(clear_surf, (0, 0))

                # render the font
                font_image = timer_font.render(
                    str(new_state.elapsed_frames),
                    True,
                    pygame.Color(255, 255, 255),
                    pad_cfg.background_color)
                last_font_rect = font_image.get_rect()
                fb.blit(font_image, (0, 0))
                fb.flip()
            last_state = new_state

        fb.limit_fps(set_caption=True)
コード例 #6
0
def main(skin, joy_index):
    pygame.display.init()
    pygame.joystick.init()

    joy = pygame.joystick.Joystick(joy_index)
    joy.init()
    mappings = configurator.load_mappings(skin)
    if joy.get_name() not in mappings:
        print 'Please run the mapper on', joy.get_name(), 'with', skin, 'skin.'
        return

    mappings = mappings[joy.get_name()]

    button_map = mappings.get('button', dict())
    axis_map = mappings.get('axis', dict())
    hat_map = mappings.get('hat', dict())

    pad_cfg = configurator.PadConfig(skin)

    fb = frame_buffer.FrameBuffer(pad_cfg.size, pad_cfg.size,
                                  scale_smooth=pad_cfg.anti_aliasing,
                                  background_color=pad_cfg.background_color)
    pad_gfx = PadImage(pad_cfg, fb)

    while not pygame.event.peek(pygame.QUIT):
        for event in pygame.event.get():
            if event.type == pygame.JOYBUTTONDOWN:
                if str(event.button) in button_map:
                    elt = button_map[str(event.button)]
                    _get_target(pad_gfx, elt).push(1)
            elif event.type == pygame.JOYBUTTONUP:
                if str(event.button) in button_map:
                    elt = button_map[str(event.button)]
                    _get_target(pad_gfx, elt).push(0)
            elif event.type == pygame.JOYAXISMOTION:
                if str(event.axis) in axis_map:
                    for change, elt in axis_map[str(event.axis)].iteritems():
                        change = int(change)
                        value = event.value
                        if abs(change) == 2:
                            value += change / abs(change)
                        value /= change
                        value = max(0, value)
                        _get_target(pad_gfx, elt).push(value)
            elif event.type == pygame.JOYHATMOTION:
                if str(event.hat) in hat_map:
                    direction_map = hat_map[str(event.hat)]
                    x, y = event.value
                    if 'up' in direction_map:
                        _get_target(pad_gfx, direction_map['up']).push(y)
                    if 'down' in direction_map:
                        _get_target(pad_gfx, direction_map['down']).push(-y)
                    if 'left' in direction_map:
                        _get_target(pad_gfx, direction_map['left']).push(-x)
                    if 'right' in direction_map:
                        _get_target(pad_gfx, direction_map['right']).push(x)
            fb.handle_event(event)

        pad_gfx.draw()
        fb.flip()
        fb.limit_fps(set_caption=True)