def create(self) -> urwid.Widget: btxt = urwid.BigText("Openvario", urwid.font.Thin6x6Font()) logo = urwid.Padding(btxt, "center", "clip") m_pinned_apps = self._get_pinned_apps() if m_pinned_apps: m_pinned_apps.append(urwid.Divider()) m_apps = widget.SelectableListItem("Applications") urwid.connect_signal(m_apps, "click", self._on_apps) m_settings = widget.SelectableListItem("Settings") urwid.connect_signal(m_settings, "click", self._on_settings) m_shutdown = widget.SelectableListItem("Shut down") urwid.connect_signal(m_shutdown, "click", self._on_quit) menu = urwid.Pile( m_pinned_apps + [m_apps, m_settings, urwid.Divider(), m_shutdown] ) # Reserve space for counter self.autostart_counter = urwid.WidgetPlaceholder( urwid.BoxAdapter(urwid.SolidFill(" "), 2) ) view = urwid.Filler( urwid.Pile( [ logo, urwid.Text(self._get_version(), align=urwid.CENTER), urwid.Divider(), urwid.Padding( urwid.LineBox(menu, "Main Menu", title_align="left"), width=("relative", 40), align=urwid.CENTER, ), urwid.Divider(), urwid.Divider(), self.autostart_counter, ] ), "middle", ) self.autostart_canceller = AutostartCanceller(view) urwid.connect_signal( self.autostart_canceller, "anykey", self._on_cancel_autostart ) view = widget.KeySignals(self.autostart_canceller) urwid.connect_signal(view, "cancel", self._on_quit) return view
def _popup_simple_choice(self, activator: api.SettingActivator) -> None: # Generate choice widget menuitems = [] focus = None choices = self.get_choices() height = len(choices) width = 0 for key, label in choices: mi = widget.SelectableListItem(label) urwid.connect_signal(mi, "click", self._choice_clicked, user_args=[activator, key]) if self.value == key: focus = mi menuitems.append(mi) if len(label) > width: width = len(label) menu = urwid.Pile(menuitems, focus) filler = urwid.Filler(menu, "top") box = urwid.LineBox(filler) box = urwid.AttrMap(box, widget.LIGHT_ATTR_MAP) signals = widget.KeySignals(box) urwid.connect_signal(signals, "cancel", self._choice_cancelled, user_args=[activator]) activator.open_value_popup(signals, width + 2, height + 2)
def _get_pinned_apps(self) -> urwid.Widget: m_items = [] for appinfo in self.shell.apps.list(): if not appinfo.pinned: continue button = widget.SelectableListItem(appinfo.app.title) urwid.connect_signal( button, "click", self._on_pinned_app, user_args=[appinfo] ) m_items.append(button) return m_items
def _refresh_pinned_apps(self) -> None: m_items = [] for appinfo in self.shell.apps.list(): if not appinfo.pinned: continue button = widget.SelectableListItem(appinfo.app.title) urwid.connect_signal( button, "click", self._on_pinned_app, user_args=[appinfo] ) m_items.append((button, ("pack", None))) self.pinned_apps.contents = m_items if m_items: self.pinned_apps.contents.append((urwid.Divider(), ("pack", None))) self.pinned_apps.set_focus(0) self.pinned_apps._selectable = True
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)