Allow user to select a joystick from a menu
168261
def select_joystick():
    ''''''

    list_joysticks()

    while True:
        print('Select a joystick (L to list, Q to quit)'),
        choice = sys.stdin.readline().strip()

        if choice.lower() == 'l':
            list_joysticks()
        elif choice.lower() == 'q':
            return
        elif choice.isdigit():
            jid = int(choice)
            if jid not in range(pygame.joystick.get_count()):
                print('Invalid joystick.')
                continue
            break
        else:
            print('What?')

    return jid
1363708
def _context_menu_make(self, pos):
        """"""
        menu = super(ShellWidget, self)._context_menu_make(pos)
        return self.ipyclient.add_actions_to_context_menu(menu)
721211
def _right_click(self, event):
        """"""
        iid = self.current_iid
        if iid is None:
            if self._menu is not None:
                self._menu.post(event.x, event.y)
            return
        args = (iid, (event.x_root, event.y_root))
        self.call_callbacks(iid, "right_callback", args)
        tags = list(self.marker_tags(iid))
        if len(tags) == 0:
            return
        menu = self._tags[tags[-1]].get("menu", None)
        if menu is None or not isinstance(menu, tk.Menu):
            return
        menu.post(event.x_root, event.y_root)
29069
def menu_callback(m):
    ''''''
    if m.returnkey.startswith('# '):
        cmd = m.returnkey[2:]
        if m.handler is not None:
            if m.handler_result is None:
                return
            cmd += m.handler_result
        process_stdin(cmd)
    elif m.returnkey == 'menuSettings':
        wxsettings.WXSettings(mestate.settings)
    elif m.returnkey.startswith("mode-"):
        idx = int(m.returnkey[5:])
        mestate.flightmode_selections[idx] = m.IsChecked()
    elif m.returnkey.startswith("loadLog"):
        print("File: " + m.returnkey[8:])
    elif m.returnkey == 'quit':
        mestate.console.close()
        mestate.exit = True
        print("Exited. Press Enter to continue.")
        sys.exit(0)

    else:
        print('Unknown menu selection: %s' % m.returnkey)
400918
def on_button_press(self, event):
        
        if not event.get_button()[1] == 1:  # left mouse button
            return False
        view = self.view

        if isinstance(view.hovered_item, StateView):
            distance = view.hovered_item.border_width / 2.
            item, handle = HandleFinder(view.hovered_item, view).get_handle_at_point((event.x, event.y), distance)
        else:
            item, handle = HandleFinder(view.hovered_item, view).get_handle_at_point((event.x, event.y))

        if not handle:
            return False

        # Only move ports when the MOVE_PORT_MODIFIER key is pressed
        if isinstance(item, (StateView, PortView)) and \
            handle in [port.handle for port in item.get_all_ports()] and \
                not (event.get_state()[1] & constants.MOVE_PORT_MODIFIER):
            return False

        # Do not move from/to handles of connections (only their waypoints)
        if isinstance(item, ConnectionView) and handle in item.end_handles(include_waypoints=True):
            return False

        if handle:
            view.hovered_item = item

            self.motion_handle = None

            self.grab_handle(item, handle)

            return True
360703
def set_menu(self, menu):
        ''''''
        self.menu = menu
        wx_menu = menu.wx_menu()
        self.frame.SetMenuBar(wx_menu)
        self.frame.Bind(wx.EVT_MENU, self.on_menu)
458596
def add_actions_to_context_menu(self, menu):
        """"""
        inspect_action = create_action(self, _("Inspect current object"),
                                    QKeySequence(get_shortcut('console',
                                                    'inspect current object')),
                                    icon=ima.icon('MessageBoxInformation'),
                                    triggered=self.inspect_object)

        clear_line_action = create_action(self, _("Clear line or block"),
                                          QKeySequence(get_shortcut(
                                                  'console',
                                                  'clear line')),
                                          triggered=self.clear_line)

        reset_namespace_action = create_action(self, _("Remove all variables"),
                                               QKeySequence(get_shortcut(
                                                       'ipython_console',
                                                       'reset namespace')),
                                               icon=ima.icon('editdelete'),
                                               triggered=self.reset_namespace)

        clear_console_action = create_action(self, _("Clear console"),
                                             QKeySequence(get_shortcut('console',
                                                               'clear shell')),
                                             triggered=self.clear_console)

        quit_action = create_action(self, _("&Quit"), icon=ima.icon('exit'),
                                    triggered=self.exit_callback)

        add_actions(menu, (None, inspect_action, clear_line_action,
                           clear_console_action, reset_namespace_action,
                           None, quit_action))
        return menu
1175840
def on_menu(self, event):
        ''''''
        state = self.state
        ret = self.menu.find_selected(event)
        if ret is None:
            return
        ret.call_handler()
        state.child_pipe_send.send(ret)
1265501
def OnKey(self, event):
        """"""

        def switch_to_next_table():
            newtable = self.grid.current_table + 1
            post_command_event(self.grid, self.GridActionTableSwitchMsg,
                               newtable=newtable)

        def switch_to_previous_table():
            newtable = self.grid.current_table - 1
            post_command_event(self.grid, self.GridActionTableSwitchMsg,
                               newtable=newtable)

        grid = self.grid
        actions = grid.actions

        shift, alt, ctrl = 1, 1 << 1, 1 << 2

        # Shortcuts key tuple: (modifier, keycode)
        # Modifier may be e. g. shift | ctrl

        shortcuts = {
            # <Esc> pressed
            (0, 27): lambda: setattr(actions, "need_abort", True),
            # <Del> pressed
            (0, 127): actions.delete,
            # <Home> pressed
            (0, 313): lambda: actions.set_cursor((grid.GetGridCursorRow(), 0)),
            # <Ctrl> + R pressed
            (ctrl, 82): actions.copy_selection_access_string,
            # <Ctrl> + + pressed
            (ctrl, 388): actions.zoom_in,
            # <Ctrl> + - pressed
            (ctrl, 390): actions.zoom_out,
            # <Shift> + <Space> pressed
            (shift, 32): lambda: grid.SelectRow(grid.GetGridCursorRow()),
            # <Ctrl> + <Space> pressed
            (ctrl, 32): lambda: grid.SelectCol(grid.GetGridCursorCol()),
            # <Shift> + <Ctrl> + <Space> pressed
            (shift | ctrl, 32): grid.SelectAll,
        }

        if self.main_window.IsFullScreen():
            # <Arrow up> pressed
            shortcuts[(0, 315)] = switch_to_previous_table
            # <Arrow down> pressed
            shortcuts[(0, 317)] = switch_to_next_table
            # <Space> pressed
            shortcuts[(0, 32)] = switch_to_next_table

        keycode = event.GetKeyCode()

        modifier = shift * event.ShiftDown() | \
            alt * event.AltDown() | ctrl * event.ControlDown()

        if (modifier, keycode) in shortcuts:
            shortcuts[(modifier, keycode)]()

        else:
            event.Skip()
1092843
def click(self, x=-1, y=-1, selector=None):
        

        self.touch(x=x, y=y, selector=selector)
813874
def _onMenuItemSelected(self, evt):
        """"""
        current = self._menu.IsChecked(evt.GetId())
        if current:
            new = False
        else:
            new = True
        self._menu.Check(evt.GetId(), new)
        # Lines above would be deleted based on svn tracker ID 2841525;
        # not clear whether this matters or not.
        self._toolbar.set_active(self.getActiveAxes())
        evt.Skip()
184393
function getController(hand, config) {
	const findGamepad = (resolve, reject) => {
		const gamepad = altspace.getGamepads().find((g) => g.mapping === 'steamvr' && g.hand === hand);
		if (gamepad) {
			if(config.logging) console.log("SteamVR input device found", gamepad);
			resolve(gamepad);
		} else {
			if(config.logging) console.log("SteamVR input device not found trying again in 500ms...");
			setTimeout(findGamepad, 500, resolve, reject);
		}
	};

	return new Promise(findGamepad);
}
515961
def selected(self, interrupt=False):
        """"""
        self.ao2.output(self.get_title(), interrupt=interrupt)
524650
def on_mouse_click(self, widget, event):
        
        import rafcon.gui.helpers.state_machine as gui_helper_state_machine
        if self.view.get_path_at_pos(int(event.x), int(event.y)) is not None \
                and len(self.view.get_selected_items()) > 0:
            return gui_helper_state_machine.insert_state_into_selected_state(self._get_state(), False)
1203702
function (gamepadId) {
    var gamepad = gamepadSupport.gamepads[gamepadId];

    // Update all the buttons (and their corresponding labels) on screen.
    window.tester.updateButton(gamepad.buttons[0], gamepadId, 'button-1');
    window.tester.updateButton(gamepad.buttons[1], gamepadId, 'button-2');
    window.tester.updateButton(gamepad.buttons[2], gamepadId, 'button-3');
    window.tester.updateButton(gamepad.buttons[3], gamepadId, 'button-4');

    window.tester.updateButton(gamepad.buttons[4], gamepadId,
        'button-left-shoulder-top');
    window.tester.updateButton(gamepad.buttons[6], gamepadId,
        'button-left-shoulder-bottom');
    window.tester.updateButton(gamepad.buttons[5], gamepadId,
        'button-right-shoulder-top');
    window.tester.updateButton(gamepad.buttons[7], gamepadId,
        'button-right-shoulder-bottom');

    window.tester.updateButton(gamepad.buttons[8], gamepadId, 'button-select');
    window.tester.updateButton(gamepad.buttons[9], gamepadId, 'button-start');

    window.tester.updateButton(gamepad.buttons[10], gamepadId, 'stick-1');
    window.tester.updateButton(gamepad.buttons[11], gamepadId, 'stick-2');

    window.tester.updateButton(gamepad.buttons[12], gamepadId, 'button-dpad-top');
    window.tester.updateButton(gamepad.buttons[13], gamepadId, 'button-dpad-bottom');
    window.tester.updateButton(gamepad.buttons[14], gamepadId, 'button-dpad-left');
    window.tester.updateButton(gamepad.buttons[15], gamepadId, 'button-dpad-right');

    // Update all the analogue sticks.
    window.tester.updateAxis(gamepad.axes[0], gamepadId,
        'stick-1-axis-x', 'stick-1', true);
    window.tester.updateAxis(gamepad.axes[1], gamepadId,
        'stick-1-axis-y', 'stick-1', false);
    window.tester.updateAxis(gamepad.axes[2], gamepadId,
        'stick-2-axis-x', 'stick-2', true);
    window.tester.updateAxis(gamepad.axes[3], gamepadId,
        'stick-2-axis-y', 'stick-2', false);

    // Update extraneous buttons.
    var extraButtonId = gamepadSupport.TYPICAL_BUTTON_COUNT;
    while (typeof gamepad.buttons[extraButtonId] !== 'undefined') {
      window.tester.updateButton(gamepad.buttons[extraButtonId], gamepadId,
          'extra-button-' + extraButtonId);

      extraButtonId++;
    }

    // Update extraneous axes.
    var extraAxisId = gamepadSupport.TYPICAL_AXIS_COUNT;
    while (typeof gamepad.axes[extraAxisId] !== 'undefined') {
      window.tester.updateAxis(gamepad.axes[extraAxisId], gamepadId,
          'extra-axis-' + extraAxisId);

      extraAxisId++;
    }

  }
828638
def get_menu(self, name):
        """"""
        if name not in self._menus:
            self._menus[name] = self.menuBar().addMenu(name)
        return self._menus[name]
523359
def select_rect(action, action_space, select_add, screen, screen2):
  """"""
  select = spatial(action, action_space).unit_selection_rect
  out_rect = select.selection_screen_coord.add()
  screen_rect = point.Rect(screen, screen2)
  screen_rect.tl.assign_to(out_rect.p0)
  screen_rect.br.assign_to(out_rect.p1)
  select.selection_add = bool(select_add)