def _on_focus_changed(self) -> None: focus = self._w.get_focus_widgets() if self.orient_lb not in focus: # Do not change orientation until listbox is in focus return _, idx = self.orient_lb.get_focus() rots = rotation.get_rotations() rot, _ = rots[idx] rotation.apply_rotation(self.shell.os, rot)
def __init__(self, shell: api.OpenVarioShell) -> None: self.shell = shell msg = [ "Orient your Openvario device the way it will be mounted on ", "your instrument panel. Press ", ("highlight", "↓"), " and ", ("highlight", "↑"), " until orientation looks right. Press ", ("highlight", "Enter"), " to confirm.", ] orient_walker = urwid.SimpleFocusListWalker([]) for oval, otxt in rotation.get_rotations(): mitem = widget.SelectableListItem(otxt) urwid.connect_signal(mitem, "click", self._save_orientation, user_args=[oval]) orient_walker.append(mitem) self.orient_lb = urwid.ListBox(orient_walker) self._set_current_rotation(self.orient_lb) urwid.connect_signal(orient_walker, "modified", self._on_focus_changed) content = urwid.Pile([ ("pack", urwid.Text(msg)), ("pack", urwid.Divider()), ( "pack", _button_row([self.make_next_button("Skip")]), ), ("pack", urwid.Divider()), (len(orient_walker), self.orient_lb), ]) super().__init__(content)
def _set_current_rotation(self, lb: urwid.ListBox) -> None: rots = [n for n, title in rotation.get_rotations()] cur_rot = self.shell.settings.get("core.screen_orientation", str) or "0" focus_pos = rots.index(cur_rot) lb.set_focus(focus_pos, "above")
def get_choices(self) -> Sequence[Tuple[str, str]]: return rotation.get_rotations()