def __init__(self, bottom_w, stretchy): self.bottom_w = bottom_w self.stretchy = stretchy self.listbox = ListBox([stretchy.stretchy_w]) def entry(i, w): if i == stretchy.stretchy_index: return ('weight', 1, self.listbox) else: return ('pack', w) inner_pile = Pile( [entry(i, w) for (i, w) in enumerate(stretchy.widgets)]) inner_pile.focus_position = stretchy.focus_index # this Filler/Padding/LineBox/Filler/Padding construction # seems ridiculous but it works. self.top_w = urwid.Filler(urwid.Padding(urwid.LineBox( urwid.Filler(urwid.Padding(inner_pile, left=2, right=2), top=1, bottom=1, height=('relative', 100)), title=stretchy.title), left=3, right=3), top=1, bottom=1, height=('relative', 100))
def screen(rows, buttons=None, focus_buttons=True, excerpt=None, narrow_rows=False): """Helper to create a common screen layout. The commonest screen layout in subiquity is: [ 1 line padding (optional) ] excerpt (optional) [ 1 line padding ] Box widget (usually a ListBox) [ 1 line padding ] a button_pile [ 1 line padding ] This helper makes creating this a 1-liner. """ if isinstance(rows, list): rows = ListBox(rows) if narrow_rows: rows = Padding.center_63(rows) if buttons is None: focus_buttons = False elif isinstance(buttons, list): buttons = button_pile(buttons) excerpt_rows = [] if excerpt is not None: excerpt_rows = [ ('pack', Text(excerpt)), ('pack', Text("")), ] body = [ rows, ('pack', Text("")), ] if buttons is not None: body.extend([ ('pack', buttons), ('pack', Text("")), ]) pile = Pile(excerpt_rows + body) if focus_buttons: pile.focus_position = len(excerpt_rows) + 2 return Padding.center_79(pile, min_width=76)
def __init__(self, model, controller, opts): self.model = model self.controller = controller self.opts = opts self.form = KeyboardForm() opts = [] for layout, desc in model.layouts.items(): opts.append(Option((desc, True, layout))) opts.sort(key=lambda o:o.label) connect_signal(self.form, 'submit', self.done) connect_signal(self.form, 'cancel', self.cancel) connect_signal(self.form.layout.widget, "select", self.select_layout) self.form.layout.widget._options = opts try: self.form.layout.widget.value = model.layout self.form.variant.widget.value = model.variant except AttributeError: # Don't crash on pre-existing invalid config. pass self._rows = self.form.as_rows(self) lb_contents = [self._rows] if not self.opts.run_on_serial: lb_contents.extend([ Text(""), button_pile([ other_btn(label=_("Identify keyboard"), on_press=self.detect)]), ]) lb = ListBox(lb_contents) pile = Pile([ ('pack', Text("")), Padding.center_90(lb), ('pack', Pile([ Text(""), self.form.buttons, Text(""), ])), ]) lb._select_last_selectable() pile.focus_position = 2 super().__init__(pile)
def screen(rows, buttons, focus_buttons=True): """Helper to create a common screen layout. The commonest screen layout in subiquity is: [ 1 line padding ] Listbox() [ 1 line padding ] a button_pile [ 1 line padding ] This helper makes creating this a 1-liner. """ screen = Pile([ ('pack', Text("")), Padding.center_79(ListBox(rows)), ('pack', Text("")), ('pack', buttons), ('pack', Text("")), ]) if focus_buttons: screen.focus_position = 3 return screen
def screen(rows, buttons, focus_buttons=True, excerpt=None): """Helper to create a common screen layout. The commonest screen layout in subiquity is: [ 1 line padding (optional) ] excerpt (optional) [ 1 line padding ] Listbox() [ 1 line padding ] a button_pile [ 1 line padding ] This helper makes creating this a 1-liner. """ if isinstance(rows, list): rows = ListBox(rows) if isinstance(buttons, list): buttons = button_pile(buttons) excerpt_rows = [] if excerpt is not None: excerpt_rows = [ ('pack', Text("")), ('pack', Text(excerpt)), ] body = [ ('pack', Text("")), rows, ('pack', Text("")), ('pack', buttons), ('pack', Text("")), ] pile = Pile(excerpt_rows + body) if focus_buttons: pile.focus_position = len(excerpt_rows) + 3 return Padding.center_79(pile)