コード例 #1
0
 def _route_watcher(self, routes):
     log.debug('view route_watcher %s', routes)
     if routes:
         label = _("Done")
     else:
         label = _("Continue without network")
     self.buttons.base_widget[0].set_label(label)
     self.buttons.width = max(
         14,
         widget_width(self.buttons.base_widget[0]),
         widget_width(self.buttons.base_widget[1]),
     )
コード例 #2
0
ファイル: error.py プロジェクト: mattlknight/subiquity
    def __init__(self, app, report, interrupting=True):
        self.app = app
        self.report = report
        self.interrupting = interrupting

        self.btns = {
            'cancel': other_btn(
                _("Cancel upload"), on_press=self.cancel_upload),
            'close': close_btn(self, _("Close report")),
            'continue': close_btn(self, _("Continue")),
            'debug_shell': other_btn(
                _("Switch to a shell"), on_press=self.debug_shell),
            'restart': other_btn(
                _("Restart the installer"), on_press=self.restart),
            'submit': other_btn(
                _("Send to Canonical"), on_press=self.submit),
            'submitted': disabled(other_btn(_("Sent to Canonical"))),
            'view': other_btn(
                _("View full report"), on_press=self.view_report),
            }
        w = 0
        for n, b in self.btns.items():
            w = max(w, widget_width(b))
        for n, b in self.btns.items():
            self.btns[n] = Padding(b, width=w, align='center')

        self.spinner = Spinner(app.aio_loop, style='dots')
        self.pile = Pile([])
        self._report_changed()
        super().__init__("", [self.pile], 0, 0)
        connect_signal(self, 'closed', self.spinner.stop)
コード例 #3
0
ファイル: help.py プロジェクト: mattlknight/subiquity
 def get_pop_up_parameters(self):
     return {
         'left': widget_width(self.btn) - self._menu.width + 1,
         'top': 0,
         'overlay_width': self._menu.width,
         'overlay_height': self._menu.height,
     }
コード例 #4
0
ファイル: table.py プロジェクト: mattlknight/subiquity
    def adjust_for_spanning_cells(self, unpacked_user_indices,
                                  no_inherent_size, widths):
        """Make sure columns are wide enough for cells with colspan > 1.

        This very roughly follows the approach in
        https://www.w3.org/TR/CSS2/tables.html#width-layout.
        """
        for user_indices, cell in self._user_indices_cells():
            if set(user_indices) & unpacked_user_indices:
                continue
            if len(user_indices) <= 1:
                continue
            cur_width = _width(widths, user_indices)
            cell_width = widget_width(cell)
            if cur_width < cell_width:
                # If any of the spanned columns have no inherent size (i.e. all
                # the cells in that column also span another column), only
                # widen those columns.
                unsized = set(user_indices) & no_inherent_size
                if unsized:
                    user_indices = unsized
                # Attempt to widen each column by about the same amount.
                # But widen the first few columns by more if that's
                # whats needed.
                div, mod = divmod(cell_width - cur_width, len(user_indices))
                for i, user_j in enumerate(user_indices):
                    widths[2 * user_j] += div + int(i < mod)
コード例 #5
0
ファイル: form.py プロジェクト: xuejinze1/subiquity
    def _build_table(self):
        widget = self.widget
        if self.field.takes_default_style:
            widget = Color.string_input(widget)

        self.caption_text = Text(self.field.caption)
        self.under_text = Text(self.help)

        if self.field.caption_first:
            self.caption_text.align = 'right'
            first_row = [self.caption_text, _Validator(self, widget)]
        else:
            first_row = [
                _Validator(
                    self,
                    UrwidPadding(widget,
                                 align='right',
                                 width=widget_width(widget))),
                self.caption_text,
            ]

        self._rows = [
            Toggleable(TableRow(row)) for row in [
                first_row,
                [Text(""), self.under_text],
            ]
        ]

        self._table = TablePile(self._rows, spacing=2, colspecs=form_colspecs)
コード例 #6
0
ファイル: utils.py プロジェクト: mattlknight/subiquity
def button_pile(buttons):
    width = 14
    for button in buttons:
        width = max(widget_width(button), width)
    return _Padding(Pile(buttons),
                    min_width=width,
                    width=width,
                    align='center')
コード例 #7
0
    def column_widths(self, size, focus=False):
        maxcol = size[0]
        btn = widget_width(self.contents[2][0])

        center = max(int_scale(79, 101, maxcol + 1), 76)
        message = center - btn
        pad = (maxcol - center) // 2
        return [pad, message, btn, pad]
コード例 #8
0
ファイル: table.py プロジェクト: vish74/subiquity
    def get_natural_widths(self, unpacked_cols):
        """Return a mapping {underlying-index:natural-width}.

        Cells spanning multiple columns are ignored (handled in
        adjust_for_spanning_cells).
        """
        widths = {}
        for user_indices, cell in self._user_indices_cells():
            if len(user_indices) == 1 and user_indices[0] not in unpacked_cols:
                widths[2*user_indices[0]] = widget_width(cell)
        return widths
コード例 #9
0
    def __init__(self, app, ref, interrupting=True):
        self.app = app
        self.error_ref = ref
        self.report = app.error_reporter.get(ref)
        self.pending = None
        if self.report is None:
            self.app.aio_loop.create_task(self._wait())
        else:
            connect_signal(self.report, 'changed', self._report_changed)
            self.report.mark_seen()
        self.interrupting = interrupting
        self.min_wait = self.app.aio_loop.create_task(asyncio.sleep(0.1))

        self.btns = {
            'cancel':
            other_btn(_("Cancel upload"), on_press=self.cancel_upload),
            'close':
            close_btn(self, _("Close report")),
            'continue':
            close_btn(self, _("Continue")),
            'debug_shell':
            other_btn(_("Switch to a shell"), on_press=self.debug_shell),
            'restart':
            other_btn(_("Restart the installer"), on_press=self.restart),
            'submit':
            other_btn(_("Send to Canonical"), on_press=self.submit),
            'submitted':
            disabled(other_btn(_("Sent to Canonical"))),
            'view':
            other_btn(_("View full report"), on_press=self.view_report),
        }
        w = 0
        for n, b in self.btns.items():
            w = max(w, widget_width(b))
        for n, b in self.btns.items():
            self.btns[n] = Padding(b, width=w, align='center')

        self.spinner = Spinner(app.aio_loop, style='dots')
        self.pile = Pile([])
        self.pile.contents[:] = [(w, self.pile.options('pack'))
                                 for w in self._pile_elements()]
        super().__init__("", [self.pile], 0, 0)
        connect_signal(self, 'closed', self.spinner.stop)
コード例 #10
0
ファイル: table.py プロジェクト: vish74/subiquity
    def adjust_for_spanning_cells(self, unpacked_user_indices, widths):
        """Make sure columns are wide enough for cells with colspan > 1.

        This very roughly follows the approach in
        https://www.w3.org/TR/CSS2/tables.html#width-layout.
        """
        for user_indices, cell in self._user_indices_cells():
            if set(user_indices) & unpacked_user_indices:
                continue
            user_indices = [
                user_i for user_i in user_indices if widths[2*user_i] > 0]
            if len(user_indices) <= 1:
                continue
            cur_width = _width(widths, user_indices)
            cell_width = widget_width(cell)
            if cur_width < cell_width:
                # Attempt to widen each column by about the same amount.
                # But widen the first few columns by more if that's
                # whats needed.
                div, mod = divmod(cell_width - cur_width, len(user_indices))
                for i, user_j in enumerate(user_indices):
                    widths[2*user_j] += div + int(i < mod)
コード例 #11
0
    def _build_table(self):
        widget = self.widget
        if self.field.takes_default_style:
            widget = Color.string_input(widget)

        if self.help is not NO_HELP:
            self.under_text = Text(self.help)
        else:
            self.under_text = Text("")
        if self.field.caption is NO_CAPTION:
            first_row = [(2, _Validator(self, widget))]
            second_row = [(2, self.under_text)]
        else:
            self.caption_text = Text(_(self.field.caption))

            if self.field.caption_first:
                self.caption_text.align = 'right'
                first_row = [self.caption_text, _Validator(self, widget)]
            else:
                first_row = [
                    _Validator(
                        self,
                        UrwidPadding(widget,
                                     align='right',
                                     width=widget_width(widget))),
                    self.caption_text,
                ]
            second_row = [Text(""), self.under_text]

        rows = [first_row]
        if self.help is not NO_HELP:
            rows.append(second_row)

        self._rows = [Toggleable(TableRow(row)) for row in rows]

        self._table = TablePile(self._rows, spacing=2, colspecs=form_colspecs)
コード例 #12
0
 def _set_button_width(self):
     w = 14
     for b, o in self.event_buttons.original_widget.contents:
         w = max(widget_width(b), w)
     self.event_buttons.width = self.event_buttons.min_width = w
コード例 #13
0
 def get_natural_width(self):
     return widget_width(self._w)
コード例 #14
0
 def options(self, val):
     self._options = val
     self._padding.width = max(
         [widget_width(o.label) for o in self._options]) + 6
コード例 #15
0
ファイル: help.py プロジェクト: mattlknight/subiquity
    def __init__(self, parent):
        self.parent = parent
        close = header_btn(parent.base_widget.label)
        about = menu_item(_("About this installer"),
                          on_press=self.parent.about)
        keys = menu_item(_("Keyboard shortcuts"),
                         on_press=self.parent.shortcuts)
        drop_to_shell = menu_item(_("Enter shell"),
                                  on_press=self.parent.debug_shell)
        buttons = {
            about,
            close,
            drop_to_shell,
            keys,
        }
        if self.parent.ssh_password is not None:
            ssh_help = menu_item(_("Help on SSH access"),
                                 on_press=self.parent.ssh_help)
            buttons.add(ssh_help)
        if self.parent.app.opts.run_on_serial:
            rich = menu_item(_("Toggle rich mode"),
                             on_press=self.parent.toggle_rich)
            buttons.add(rich)
        local_title, local_doc = parent.app.ui.body.local_help()
        if local_title is not None:
            local = menu_item(local_title,
                              on_press=self.parent.show_local(
                                  local_title, local_doc))
            buttons.add(local)
        else:
            local = Text(
                ('info_minor header', " " + _("Help on this screen") + " "))

        if self.parent.app.controllers.Error.reports:
            view_errors = menu_item(
                _("View error reports").format(local_title),
                on_press=self.parent.show_errors)
            buttons.add(view_errors)
        else:
            view_errors = Text(
                ('info_minor header', " " + _("View error reports") + " "))

        for button in buttons:
            connect_signal(button.base_widget, 'click', self._close)

        entries = [
            local,
            keys,
            drop_to_shell,
            view_errors,
            hline,
            about,
        ]

        if self.parent.ssh_password is not None:
            entries.append(ssh_help)

        if self.parent.app.opts.run_on_serial:
            entries.extend([
                hline,
                rich,
            ])

        rows = [
            Columns([
                ('fixed', 1, tlcorner),
                hline,
                (widget_width(close), close),
                ('fixed', 1, trcorner),
            ]),
        ]
        for entry in entries:
            if isinstance(entry, Divider):
                left, right = ltee, rtee
            else:
                left = right = vline
            rows.append(
                Columns([
                    ('fixed', 1, left),
                    entry,
                    ('fixed', 1, right),
                ]))
        rows.append(Columns([
            (1, blcorner),
            hline,
            (1, brcorner),
        ]))
        self.width = max(
            [widget_width(b)
             for b in entries if not isinstance(b, Divider)]) + 2
        self.height = len(entries) + 2
        super().__init__(Color.frame_header(Filler(Pile(rows))))
コード例 #16
0
    def __init__(self, parent):
        self.parent = parent
        close = header_btn(parent.base_widget.label)
        about = menu_item(_("About this installer"), on_press=self._about)
        keys = menu_item(_("Keyboard shortcuts"), on_press=self._shortcuts)
        drop_to_shell = menu_item(_("Enter shell"), on_press=self._debug_shell)
        color = menu_item(_("Toggle color on/off"),
                          on_press=self._toggle_color)
        buttons = {
            close,
            about,
            keys,
            drop_to_shell,
            color,
        }
        local_title, local_doc = parent.app.ui.body.local_help()
        if local_title is not None:
            local = menu_item(local_title,
                              on_press=self._show_local(
                                  local_title, local_doc))
            buttons.add(local)
        else:
            local = Text(
                ('info_minor header', " " + _("Help on this screen") + " "))
        for button in buttons:
            connect_signal(button.base_widget, 'click', self._close)

        entries = [
            local,
            keys,
            drop_to_shell,
            hline,
            about,
            hline,
            color,
        ]

        rows = [
            Columns([
                ('fixed', 1, tlcorner),
                hline,
                (widget_width(close), close),
                ('fixed', 1, trcorner),
            ]),
        ]
        for entry in entries:
            if isinstance(entry, Divider):
                left, right = ltee, rtee
            else:
                left = right = vline
            rows.append(
                Columns([
                    ('fixed', 1, left),
                    entry,
                    ('fixed', 1, right),
                ]))
        rows.append(Columns([
            (1, blcorner),
            hline,
            (1, brcorner),
        ]))
        self.width = max(
            [widget_width(b)
             for b in entries if not isinstance(b, Divider)]) + 2
        self.height = len(entries) + 2
        super().__init__(Color.frame_header(Filler(Pile(rows))))