def __init__(self, controller): self.controller = controller self.ongoing = {} # context -> line containing a spinner self.reboot_btn = Toggleable(ok_btn( _("Reboot Now"), on_press=self.reboot)) self.view_error_btn = cancel_btn( _("View error report"), on_press=self.view_error) self.view_log_btn = other_btn( _("View full log"), on_press=self.view_log) self.continue_btn = other_btn( _("Continue"), on_press=self.continue_) self.event_listbox = ListBox() self.event_linebox = MyLineBox(self.event_listbox) self.event_buttons = button_pile([self.view_log_btn]) event_body = [ ('weight', 1, Padding.center_79(self.event_linebox, min_width=76)), ('pack', Text("")), ('pack', self.event_buttons), ('pack', Text("")), ] self.event_pile = Pile(event_body) self.log_listbox = ListBox() log_linebox = MyLineBox(self.log_listbox, _("Full installer output")) log_body = [ ('weight', 1, log_linebox), ('pack', button_pile([other_btn(_("Close"), on_press=self.close_log)])), ] self.log_pile = Pile(log_body) super().__init__(self.event_pile)
def __init__(self, controller): self.controller = controller self.spinner = Spinner(controller.loop) self.reboot_btn = Toggleable( ok_btn(_("Reboot Now"), on_press=self.reboot)) self.exit_btn = cancel_btn(_("Exit To Shell"), on_press=self.quit) self.view_log_btn = other_btn(_("View full log"), on_press=self.view_log) self.event_listbox = ListBox() self.event_linebox = MyLineBox(self.event_listbox) self.event_buttons = button_pile([self.view_log_btn]) event_body = [ ('pack', Text("")), ('weight', 1, Padding.center_79(self.event_linebox, min_width=76)), ('pack', Text("")), ('pack', self.event_buttons), ('pack', Text("")), ] self.event_pile = Pile(event_body) self.log_listbox = ListBox() log_linebox = MyLineBox(self.log_listbox, _("Full installer output")) log_body = [ ('weight', 1, log_linebox), ('pack', button_pile([other_btn(_("Close"), on_press=self.close_log)])), ] self.log_pile = Pile(log_body) super().__init__(self.event_pile)
def __init__(self, controller): self.controller = controller self.spinner = Spinner(controller.loop) self.event_listwalker = SimpleFocusListWalker([]) self.event_listbox = ListBox(self.event_listwalker) self.event_linebox = MyLineBox(self.event_listbox) self.event_buttons = button_pile([other_btn("View full log", on_press=self.view_log)]) event_body = [ ('pack', Text("")), ('weight', 1, Padding.center_79(self.event_linebox)), ('pack', Text("")), ('pack', self.event_buttons), ('pack', Text("")), ] self.event_pile = Pile(event_body) self.log_listwalker = SimpleFocusListWalker([]) self.log_listbox = ListBox(self.log_listwalker) log_linebox = MyLineBox(self.log_listbox, _("Full installer output")) log_body = [ ('weight', 1, log_linebox), ('pack', button_pile([other_btn(_("Close"), on_press=self.close_log)])), ] self.log_pile = Pile(log_body) super().__init__(self.event_pile)
def __init__(self, controller): self.controller = controller self.listwalker = SimpleFocusListWalker([]) self.listbox = ListBox(self.listwalker) self.linebox = MyLineBox(self.listbox) body = [ ('pack', Text("")), ('weight', 1, Padding.center_79(self.linebox)), ('pack', Text("")), ] self.pile = Pile(body) super().__init__(self.pile)
class ProgressView(BaseView): def __init__(self, controller): self.controller = controller self.listwalker = SimpleFocusListWalker([]) self.listbox = ListBox(self.listwalker) self.linebox = MyLineBox(self.listbox) body = [ ('pack', Text("")), ('weight', 1, Padding.center_79(self.linebox)), ('pack', Text("")), ] self.pile = Pile(body) super().__init__(self.pile) def add_log_tail(self, text): at_end = len( self.listwalker) == 0 or self.listbox.focus_position == len( self.listwalker) - 1 for line in text.splitlines(): self.listwalker.append(Text(line)) if at_end: self.listbox.set_focus(len(self.listwalker) - 1) self.listbox.set_focus_valign('bottom') def clear_log_tail(self): self.listwalker[:] = [] def set_status(self, text): self.linebox.set_title(text) def show_complete(self, include_exit=False): buttons = [ ok_btn(_("Reboot Now"), on_press=self.reboot), ] if include_exit: buttons.append(cancel_btn(_("Exit To Shell"), on_press=self.quit)) buttons = button_pile(buttons) new_pile = Pile([ ('pack', Text("")), buttons, ('pack', Text("")), ]) self.pile.contents[-1] = (new_pile, self.pile.options('pack')) self.pile.focus_position = len(self.pile.contents) - 1 def reboot(self, btn): self.controller.reboot() def quit(self, btn): self.controller.quit()
def __init__(self, parent, cur_index): self.parent = parent group = [] for i, option in enumerate(self.parent._options): if option.enabled: btn = _PopUpButton(option.label, state=i == cur_index) connect_signal(btn, 'click', self.click, i) group.append(AttrWrap(btn, 'menu_button', 'menu_button focus')) else: btn = Text(" " + option.label) group.append(AttrWrap(btn, 'info_minor')) list_box = ListBox(group) list_box.focus_position = cur_index super().__init__(LineBox(list_box))
def __init__(self, size, existing, initial, back): mountpoint_to_devpath_mapping = self.model.get_mountpoint_to_devpath_mapping( ) if existing is not None: fs = existing.fs() if fs is not None: if existing.flag != "boot": initial['fstype'] = self.model.fs_by_name[fs.fstype] mount = fs.mount() if mount is not None: initial['mount'] = mount.path if mount.path in mountpoint_to_devpath_mapping: del mountpoint_to_devpath_mapping[mount.path] else: initial['fstype'] = self.model.fs_by_name[None] self.form = self.form_cls(mountpoint_to_devpath_mapping, size, initial) self.back = back connect_signal(self.form, 'submit', self.done) connect_signal(self.form, 'cancel', self.cancel) partition_box = Padding.center_50(ListBox(self.make_body())) super().__init__( Pile([ ('pack', Text("")), partition_box, ('pack', Pile([ ('pack', Text("")), self.form.buttons, ('pack', Text("")), ])), ]))
def __init__(self, model, controller, name): self.model = model self.controller = controller self.dev = self.model.get_netdev_by_name(name) self.title = _("Network interface {} WIFI configuration").format(name) self.form = WLANForm() connect_signal(self.form, 'submit', self.done) connect_signal(self.form, 'cancel', self.cancel) if self.dev.configured_ssid is not None: self.form.ssid.value = self.dev.configured_ssid if self.dev.configured_wifi_psk is not None: self.form.psk.value = self.dev.configured_wifi_psk self.ssid_row = self.form.ssid.as_row(self.form.longest_caption) self.psk_row = self.form.psk.as_row(self.form.longest_caption) self.inputs = Pile(self._build_iface_inputs()) self.error = Text("") self.body = Pile([ ('pack', Text("")), ListBox([Padding.center_79(self.inputs)]), ('pack', Pile([ ('pack', Text("")), Padding.center_79(Color.info_error(self.error)), self.form.buttons, ('pack', Text("")), ])), ]) self.orig_w = None super().__init__(self.body)
def __init__(self, parent, cur_index): self.parent = parent group = [] for i, option in enumerate(self.parent._options): if option.enabled: btn = ClickableThing(option.label) connect_signal(btn, 'click', self.click, i) if i == cur_index: rhs = '\N{BLACK LEFT-POINTING SMALL TRIANGLE} ' else: rhs = '' else: btn = option.label rhs = '' row = Columns([ (1, Text("")), btn, (2, Text(rhs)), ]) if option.enabled: row = AttrWrap(row, 'menu_button', 'menu_button focus') else: row = AttrWrap(row, 'info_minor') btn = UrwidPadding(row, width=self.parent._padding.width) group.append(btn) list_box = ListBox(group) list_box.base_widget.focus_position = cur_index super().__init__(Color.body(LineBox(list_box)))
def __init__(self, model, controller, opts): self.model = model self.controller = controller self.signal = controller.signal self.opts = opts self.items = [] reserved_usernames_path = (os.path.join(os.environ.get("SNAP", "."), "reserved-usernames")) reserved_usernames = set() if os.path.exists(reserved_usernames_path): with open(reserved_usernames_path) as fp: for line in fp: line = line.strip() if line.startswith('#') or not line: continue reserved_usernames.add(line) else: reserved_usernames.add('root') self.form = IdentityForm(reserved_usernames) connect_signal(self.form, 'submit', self.done) connect_signal(self.form.confirm_password.widget, 'change', self._check_password) connect_signal(self.form.ssh_import_id.widget, 'select', self._select_ssh_import_id) self.form.import_username.enabled = False self.form_rows = ListBox(self.form.as_rows()) super().__init__( screen(self.form_rows, [self.form.done_btn], excerpt=_(self.excerpt), focus_buttons=False))
def make_serial_choices(self): ssh_password = get_installer_password(self.controller.opts.dry_run) ips = get_global_addresses(self.controller.app) btns = [ other_btn(label="Switch to rich mode", on_press=self.enable_rich), forward_btn(label="Continue in basic mode", on_press=self.choose_language, user_arg='C'), ] widgets = [ Text(""), Text(rewrap(SERIAL_TEXT)), Text(""), ] if ssh_password and ips: widgets.append(Text(rewrap(SSH_TEXT))) widgets.append(Text("")) btns.insert( 1, other_btn(label="View SSH instructions", on_press=self.ssh_help, user_arg=ssh_password)) widgets.extend([ button_pile(btns), ]) lb = ListBox(widgets) return screen(lb, buttons=None)
def make_language_choices(self): btns = [] current_index = None langs = self.model.get_languages(self.is_linux_tty) cur = self.model.selected_language log.debug("_build_model_inputs selected_language=%s", cur) if cur in ["C", None]: cur = "en_US" for i, (code, native) in enumerate(langs): log.debug("%s", (code, self.model.selected_language)) if code == cur: current_index = i btns.append( forward_btn(label=native, on_press=self.choose_language, user_arg=code)) lb = ListBox(btns) if current_index is not None: lb.base_widget.focus_position = current_index return screen( lb, buttons=None, narrow_rows=True, excerpt=_("Use UP, DOWN and ENTER keys to select your language."))
def __init__(self, model, controller, name): self.model = model self.controller = controller self.dev = self.model.get_netdev_by_name(name) self.is_gateway = False self.form = NetworkConfigForm(self.ip_version) connect_signal(self.form, 'submit', self.done) connect_signal(self.form, 'cancel', self.cancel) self.form.subnet.help = "CIDR e.g. %s"%(self.example_address,) configured_addresses = self.dev.configured_ip_addresses_for_version(self.ip_version) if configured_addresses: addr = ipaddress.ip_interface(configured_addresses[0]) self.form.subnet.value = str(addr.network) self.form.address.value = str(addr.ip) configured_gateway = self.dev.configured_gateway_for_version(self.ip_version) if configured_gateway: self.form.gateway.value = configured_gateway self.form.nameservers.value = ', '.join(self.dev.configured_nameservers) self.form.searchdomains.value = ', '.join(self.dev.configured_searchdomains) self.error = Text("", align='center') #self.set_as_default_gw_button = Pile(self._build_set_as_default_gw_button()) body = [ Padding.center_79(self.form.as_rows(self)), #Padding.line_break(""), #Padding.center_79(self.set_as_default_gw_button), Padding.line_break(""), Padding.fixed_10(self.form.buttons) ] super().__init__(ListBox(body))
def __init__(self, model, controller, opts): self.model = model self.controller = controller self.signal = controller.signal self.opts = opts self.items = [] self.form = IdentityForm() connect_signal(self.form, 'submit', self.done) connect_signal(self.form.confirm_password.widget, 'change', self._check_password) self.ssh_import_confirmed = True body = Pile([ ('pack', Text("")), Padding.center_90(ListBox([self.form.as_rows(self)])), ('pack', Pile([ ('pack', Text("")), button_pile([self.form.done_btn]), ('pack', Text("")), ], focus_item=1)), ]) super().__init__(body)
def __init__(self, model, controller, opts, loop): self.model = model self.controller = controller self.opts = opts self.loop = loop self.items = [] self.email = EmailEditor() self.error = Text("", align="center") self.progress = Text("", align="center") body = [ ('pack', Text("")), ListBox([ self._build_model_inputs(), Padding.line_break(""), Padding.center_79( Color.info_minor( Text("If you do not have an account, visit " "https://login.ubuntu.com to create one."))), Padding.line_break(""), Padding.center_90(Color.info_error(self.error)), Padding.center_90(self.progress), ]), ('pack', Pile([ ('pack', Text("")), button_pile(self._build_buttons()), ('pack', Text("")), ])), ] super().__init__(Pile(body))
def __init__(self, controller): self.controller = controller super().__init__(Pile([ ListBox([Text('')]), # need to have a listbox or something else "stretchy" here or urwid complains. ('pack', button_pile([ok_btn("OK", on_press=self.confirm)])), ('pack', Text("")), ], focus_item=1))
def __init__(self, model, controller): self.model = model self.controller = controller cancel = cancel_btn(_("Cancel"), on_press=self.cancel) disks = [] for disk in self.model.all_disks(): label = "%-42s %s" % (disk.label, humanize_size( disk.size).rjust(9)) if disk.size >= model.lower_size_limit: disk_btn = forward_btn(label, on_press=self.choose_disk, user_arg=disk) else: disk_btn = Color.info_minor(Text(" " + label)) disks.append(disk_btn) body = Pile([ ('pack', Text("")), ('pack', Padding.center_70(Text(_("Choose the disk to install to:")))), ('pack', Text("")), Padding.center_70(ListBox(disks)), ('pack', Text("")), ('pack', button_pile([cancel])), ('pack', Text("")), ]) super().__init__(body)
def __init__(self, model, controller, name): self.model = model self.controller = controller self.dev = self.model.get_netdev_by_name(name) self.form = WLANForm() connect_signal(self.form, 'submit', self.done) connect_signal(self.form, 'cancel', self.cancel) if self.dev.configured_ssid is not None: self.form.ssid.value = self.dev.configured_ssid if self.dev.configured_wifi_psk is not None: self.form.psk.value = self.dev.configured_wifi_psk self.ssid_row = self.form.ssid.as_row(self, self.form.longest_caption) self.psk_row = self.form.psk.as_row(self, self.form.longest_caption) self.inputs = Pile(self._build_iface_inputs()) self.error = Text("") self.body = [ Padding.center_79(self.inputs), Padding.line_break(""), Padding.center_79(Color.info_error(self.error)), Padding.line_break(""), Padding.fixed_10(Pile([self.form.done_btn, self.form.cancel_btn])), ] self.orig_w = None super().__init__(ListBox(self.body))
def __init__(self, parent): self.parent = parent close = ActionBackButton("(close)") connect_signal(close, "click", self.close) group = [Color.menu_button(close)] width = 0 for i, option in enumerate(self.parent._options): if option.enabled: if isinstance(option.label, Widget): btn = option.label else: btn = Color.menu_button(ActionMenuButton(option.label)) width = max(width, len(btn.base_widget.label)) connect_signal(btn.base_widget, 'click', self.click, option.value) else: label = option.label if isinstance(label, Widget): label = label.base_widget.label width = max(width, len(label)) btn = Columns([ ('fixed', 1, Text("")), Text(label), ('fixed', 1, Text(">")), ], dividechars=1) btn = AttrWrap(btn, 'info_minor') group.append(btn) self.width = width super().__init__(LineBox(ListBox(group)))
def __init__(self, model, controller): self.model = model self.controller = controller initial = { "install_server": self.model.install_server, "pwauth": self.model.pwauth, } if self.model.ssh_import_id: prefix, username = self.model.ssh_import_id.split(':', 1) initial['ssh_import_id'] = prefix initial['import_username'] = username self.form = SSHForm(initial=initial) connect_signal(self.form.ssh_import_id.widget, 'select', self._select_ssh_import_id) connect_signal(self.form, 'submit', self.done) connect_signal(self.form, 'cancel', self.cancel) self.form_rows = ListBox(self.form.as_rows()) super().__init__( screen(self.form_rows, self.form.buttons, excerpt=_(self.excerpt), focus_buttons=False))
def make_language_choices(self): btns = [] current_index = None langs = get_languages() cur = self.cur_lang if cur in ["C.UTF-8", None]: cur = "en_US.UTF-8" for i, (code, native) in enumerate(langs): log.debug("%s", (code, cur)) if code == cur: current_index = i btns.append( forward_btn( label=native, on_press=self.choose_language, user_arg=code)) lb = ListBox(btns) back = None if self.serial: back = other_btn(_("Back"), on_press=self.controller.cancel) if current_index is not None: lb.base_widget.focus_position = current_index return screen( lb, focus_buttons=False, narrow_rows=True, buttons=[back] if back else None, excerpt=_("Use UP, DOWN and ENTER keys to select your language."))
def __init__(self, model, controller): log.debug('FileSystemView init start()') self.model = model self.controller = controller self.items = [] self.body = [ Text(_("FILE SYSTEM SUMMARY")), Text(""), Padding.push_4(self._build_filesystem_list()), Text(""), Text(_("AVAILABLE DEVICES")), Text(""), Padding.push_4(self._build_available_inputs()), #self._build_menu(), #Text(""), #Text("USED DISKS"), #Text(""), #self._build_used_disks(), #Text(""), ] self.lb = Padding.center_95(ListBox(self.body)) self.footer = Pile([ Text(""), self._build_buttons(), Text(""), ]) self.frame = Pile([ ('pack', Text("")), self.lb, ('pack', self.footer)]) if self.model.can_install(): self.lb.original_widget._select_last_selectable() self.frame.focus_position = 2 super().__init__(self.frame) log.debug('FileSystemView init complete()')
def __init__(self, model, controller): self.model = model self.controller = controller self.items = [] self.error = Text("", align='center') self.model_inputs = Pile(self._build_model_inputs()) self.additional_options = Pile(self._build_additional_options()) self.body = [ self.model_inputs, Padding.center_79(self.additional_options), Padding.line_break(""), ] self.lb = Padding.center_90(ListBox(self.body)) self.footer = Pile([ Text(""), self._build_buttons(), Text(""), ]) self.error_showing = False self.frame = Pile([ ('pack', Text("")), self.lb, ('pack', self.footer)]) self.lb.original_widget._select_last_selectable() self.frame.focus_position = 2 super().__init__(self.frame)
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 __init__(self, model, controller): self.model = model self.controller = controller self.dev_to_row = {} self.cur_netdevs = [] self.error = Text("", align='center') self.device_table = TablePile(self._build_model_inputs(), spacing=2, colspecs={ 0: ColSpec(rpad=1), 4: ColSpec(can_shrink=True, rpad=1), }) self._create_bond_btn = menu_btn(_("Create bond"), on_press=self._create_bond) bp = button_pile([self._create_bond_btn]) bp.align = 'left' self.listbox = ListBox([self.device_table] + [ bp, ]) self.bottom = Pile([ Text(""), self._build_buttons(), Text(""), ]) self.error_showing = False self.frame = Pile([('pack', Text("")), ('pack', Padding.center_79(Text(_(self.excerpt)))), ('pack', Text("")), Padding.center_90(self.listbox), ('pack', self.bottom)]) self.frame.set_focus(self.bottom) super().__init__(self.frame)
def __init__(self, model, controller): log.debug('FileSystemView init start()') self.model = model self.controller = controller self.mount_list = MountList(self) self.avail_list = DeviceList(self, True) self.used_list = DeviceList(self, False) self.avail_list.table.bind(self.used_list.table) body = [ Text(_("FILE SYSTEM SUMMARY")), Text(""), Padding.push_2(self.mount_list), Text(""), Text(""), Text(_("AVAILABLE DEVICES")), Text(""), Padding.push_2(self.avail_list), Text(""), Text(""), Text(_("USED DEVICES")), Text(""), Padding.push_2(self.used_list), Text(""), ] self.lb = ListBox(body) frame = screen(self.lb, self._build_buttons(), focus_buttons=self.model.can_install()) frame.width = ('relative', 95) super().__init__(frame) log.debug('FileSystemView init complete()')
def _build_choices(self): choices = [] for label, path in self.model.paths: log.debug("Building inputs: {}".format(path)) choices.append( forward_btn(label=label, on_press=self.confirm, user_arg=path)) return ListBox(choices)
def __init__(self, parent, snap, cur_channel): self.parent = parent self.snap = snap self.channels = [] self.needs_focus = True channel_width = (max(len(csi.channel_name) for csi in snap.channels) + StarRadioButton.reserve_columns + 1) max_version = max(len(csi.version) for csi in snap.channels) max_revision = max(len(str(csi.revision)) for csi in snap.channels) + 2 max_size = max(len(humanize_size(csi.size)) for csi in snap.channels) self.description = Text(snap.description.replace('\r', '').strip()) self.lb_description = ListBox([self.description]) radio_group = [] for csi in snap.channels: notes = '-' if csi.confinement != "strict": notes = csi.confinement btn = StarRadioButton(radio_group, "{}:".format(csi.channel_name), state=csi.channel_name == cur_channel, on_state_change=self.state_change, user_data=SnapSelection( channel=csi.channel_name, is_classic=csi.confinement == "classic")) self.channels.append( Color.menu_button( Columns([ (channel_width, btn), (max_version, Text(csi.version)), (max_revision, Text("({})".format(csi.revision))), (max_size, Text(humanize_size(csi.size))), ('pack', Text(notes)), ], dividechars=1))) self.lb_channels = NoTabCyclingListBox(self.channels) title = Columns([ Text(snap.name), ('pack', Text(_("Publisher: {}").format(snap.publisher), align='right')), ], dividechars=1) contents = [ ('pack', title), ('pack', Text("")), ('pack', Text(snap.summary)), ('pack', Text("")), self.lb_description, # overwritten in render() ('pack', Text("")), ('weight', 1, self.lb_channels), ] self.description_index = contents.index(self.lb_description) self.pile = Pile(contents) super().__init__(self.pile)
def __init__(self): self.header = Header("", self.right_icon) self.pile = Pile([ ('pack', self.header), ListBox([Text("")]), ]) self.pile.focus_position = 1 super().__init__(Color.body(self.pile))
def __init__(self, parent, ssids): self.parent = parent button = cancel_btn(_("Cancel"), on_press=self.do_cancel) ssid_list = [menu_btn(label=ssid, on_press=self.do_network) for ssid in ssids] p = Pile([BoxAdapter(ListBox(ssid_list), height=10), Padding.fixed_10(button)]) box = LineBox(p, title="Select a network") super().__init__(box)