Пример #1
0
 def __init__(self, model, controller, method):
     self.model = model
     self.controller = controller
     self.method = method
     cancel = cancel_btn(_("Cancel"), on_press=self.cancel)
     rows = []
     for disk in self.model.all_disks():
         if disk.size >= dehumanize_size("6G"):
             disk_btn = ClickableIcon(disk.label)
             connect_signal(
                 disk_btn, 'click', self.choose_disk, disk)
             attr = Color.done_button
         else:
             disk_btn = Text("  "+disk.label)
             attr = Color.info_minor
         rows.append(attr(TableRow([
             Text('['),
             disk_btn,
             Text(humanize_size(disk.size), align='right'),
             Text('\N{BLACK RIGHT-POINTING SMALL TRIANGLE}'),
             Text(']'),
             ])))
     super().__init__(screen(
         TableListBox(rows, spacing=1, colspecs={
             1: ColSpec(can_shrink=True, min_width=20, rpad=2),
             2: ColSpec(min_width=9),
             }),
         button_pile([cancel]),
         focus_buttons=False,
         excerpt=(
             excerpts[method]
             + "\n\n"
             + _("Choose the disk to install to:"))))
Пример #2
0
    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)
Пример #3
0
 def make_main_screen(self, snap_list):
     self.snap_boxes = {}
     body = []
     for snap in snap_list:
         box = self.snap_boxes[snap.name] = SnapCheckBox(self, snap)
         row = [
             box,
             Text(snap.publisher),
             Text(snap.summary, wrap='clip'),
         ]
         body.append(Color.menu_button(TableRow(row)))
     table = NoTabCyclingTableListBox(body,
                                      colspecs={
                                          1: ColSpec(omittable=True),
                                          2: ColSpec(pack=False,
                                                     min_width=40),
                                      })
     ok = ok_btn(label=_("Done"), on_press=self.done)
     self._main_screen = screen(
         table, [ok],
         focus_buttons=False,
         excerpt=_(
             "These are popular snaps in server environments. Select or "
             "deselect with SPACE, press ENTER to see more details of the "
             "package, publisher and versions available."))
Пример #4
0
    def __init__(self, controller, netdev_infos):
        self.controller = controller
        self.dev_name_to_table = {}
        self.cur_netdev_names = []
        self.error = Text("", align='center')

        self.device_colspecs = {
            0: ColSpec(rpad=1),
            3: ColSpec(min_width=15),
            4: ColSpec(can_shrink=True, rpad=1),
        }

        self.heading_table = TablePile([
            TableRow([
                Color.info_minor(Text(header)) for header in [
                    "",
                    "NAME",
                    "TYPE",
                    "NOTES",
                    "",
                ]
            ])
        ],
                                       spacing=2,
                                       colspecs=self.device_colspecs)

        self.device_pile = Pile([self.heading_table])

        for dev_info in netdev_infos:
            self.new_link(dev_info)

        self._create_bond_btn = menu_btn(_("Create bond"),
                                         on_press=self._create_bond)
        bp = button_pile([self._create_bond_btn])
        bp.align = 'left'

        rows = [
            self.device_pile,
            bp,
        ]

        self.buttons = button_pile([
            done_btn("TBD", on_press=self.done),  # See _route_watcher
            back_btn(_("Back"), on_press=self.cancel),
        ])
        self.bottom = Pile([
            ('pack', self.buttons),
        ])

        self.error_showing = False

        super().__init__(
            screen(rows=rows,
                   buttons=self.bottom,
                   focus_buttons=True,
                   excerpt=_(self.excerpt)))
Пример #5
0
 def __init__(self, parent):
     self.parent = parent
     self.table = TableListBox([], spacing=2, colspecs={
         0: ColSpec(rpad=2),
         1: ColSpec(rpad=2),
         2: ColSpec(rpad=2),
         3: ColSpec(rpad=2),
     })
     self._no_zdev_content = Color.info_minor(
         Text(_("No zdev devices found.")))
     super().__init__(self.table)
Пример #6
0
 def __init__(self, parent):
     self.parent = parent
     self.table = Table([],
                        spacing=2,
                        colspecs={
                            0: ColSpec(can_shrink=True),
                            1: ColSpec(min_width=9),
                        })
     self._no_mounts_content = Color.info_minor(
         Text(_("No disks or partitions mounted.")))
     super().__init__(self.table)
     self.refresh_model_inputs()
Пример #7
0
 def __init__(self, parent, show_available):
     self.parent = parent
     self.show_available = show_available
     self.table = TablePile([],  spacing=2, colspecs={
         0: ColSpec(rpad=1),
         2: ColSpec(can_shrink=True),
         4: ColSpec(min_width=9),
         5: ColSpec(rpad=1),
     })
     if show_available:
         text = _("No available devices")
     else:
         text = _("No used devices")
     self._no_devices_content = Color.info_minor(Text(text))
     super().__init__(self.table)
Пример #8
0
 def test_no_inherent_width_confined(self):
     #    [[(2, "longer content567890"), "shorter890"],
     #     ["shorter890", (2, "longer content5")]]
     #
     # should be rendered like this if the view is not quite wide
     # enough (and column 1 has can_shrink=True):
     #
     #    +--------------------+------------+
     #    | longer content5678 | shorter890 |
     #    | 90                 |            |
     #    +------------+-------+------------+
     #    | shorter890 | longer content5    |
     #    +------------+--------------------+
     #
     # This is represented by column 1 not being assigned a width
     # at all, so urwid gives it as much space as it can.
     trows = self.rowsForContentSizes([[(2, 20), 10], [10, (2, 15)]])
     colspecs = defaultdict(ColSpec, {1: ColSpec(can_shrink=True)})
     widths, total, has_unpacked = _compute_widths_for_size(
         28, trows, colspecs, 0)
     self.assertEqual(
         ({
             0: 10,
             1: 0,
             3: 0,
             4: 10
         }, 28, False),
         (widths, total, has_unpacked),
     )
Пример #9
0
 def __init__(self, app):
     rows = []
     keys = GLOBAL_KEYS
     if app.opts.run_on_serial:
         keys += SERIAL_GLOBAL_HELP_KEYS
     for key, text in keys:
         rows.append(TableRow([Text(_(key)), Text(_(text))]))
     if app.opts.dry_run:
         dro = _('(dry-run only)')
         for key, text in DRY_RUN_KEYS:
             rows.append(TableRow([Text(_(key)),
                                   Text(_(text) + ' ' + dro)]))
     table = TablePile(rows,
                       spacing=2,
                       colspecs={1: ColSpec(can_shrink=True)})
     widgets = [
         Pile([
             ('pack', Text(rewrap(GLOBAL_KEY_HELP))),
             ('pack', Text("")),
             ('pack', table),
         ]),
         Text(""),
         button_pile([close_btn(app, self)]),
     ]
     super().__init__(_("Shortcut Keys"), widgets, 0, 2)
Пример #10
0
 def __init__(self, app):
     self.app = app
     rows = [
         TableRow([
             Text(""),
             Text(_("DATE")),
             Text(_("KIND")),
             Text(_("STATUS")),
             Text(""),
         ])
     ]
     self.report_to_row = {}
     self.app.error_reporter.load_reports()
     for report in self.app.error_reporter.reports:
         connect_signal(report, "changed", self._report_changed, report)
         r = self.report_to_row[report] = self.row_for_report(report)
         rows.append(r)
     self.table = TablePile(rows, colspecs={1: ColSpec(can_shrink=True)})
     widgets = [
         Text(_("Select an error report to view:")),
         Text(""),
         self.table,
         Text(""),
         button_pile([close_btn(self)]),
     ]
     super().__init__("", widgets, 2, 2)
Пример #11
0
 def __init__(self, parent, show_available):
     self.parent = parent
     self.show_available = show_available
     self.table = Table([],
                        spacing=2,
                        colspecs={
                            0: ColSpec(can_shrink=True),
                            1: ColSpec(min_width=9),
                        })
     if show_available:
         text = _("No available devices")
     else:
         text = _("No used devices")
     self._no_devices_content = Color.info_minor(Text(text))
     super().__init__(self.table)
     self.refresh_model_inputs()
     # I don't really know why this is required:
     self.table._select_first_selectable()
Пример #12
0
    def __init__(self, model, controller):
        self.model = model
        self.controller = controller
        self.dev_to_table = {}
        self.cur_netdevs = []
        self.error = Text("", align='center')

        self.device_colspecs = {
            0: ColSpec(rpad=1),
            3: ColSpec(min_width=15),
            4: ColSpec(can_shrink=True, rpad=1),
        }

        self.device_pile = Pile(self._build_model_inputs())

        self._create_bond_btn = menu_btn(_("Create bond"),
                                         on_press=self._create_bond)
        bp = button_pile([self._create_bond_btn])
        bp.align = 'left'

        rows = [
            self.device_pile,
            bp,
        ]

        self.buttons = button_pile([
            done_btn("TBD", on_press=self.done),  # See _route_watcher
            back_btn(_("Back"), on_press=self.cancel),
        ])
        self.bottom = Pile([
            ('pack', self.buttons),
        ])

        self.controller.network_event_receiver.add_default_route_watcher(
            self._route_watcher)

        self.error_showing = False

        super().__init__(
            screen(rows=rows,
                   buttons=self.bottom,
                   focus_buttons=True,
                   excerpt=_(self.excerpt)))
Пример #13
0
 def make_main_screen(self, snap_list):
     self.snap_boxes = {}
     body = []
     preinstalled = self.get_preinstalled_snaps()
     for snap in snap_list:
         if snap.name in preinstalled:
             log.debug("not offering preseeded snap %r", snap.name)
             continue
         box = self.snap_boxes[snap.name] = SnapCheckBox(
             self, snap, snap.name in self.to_install)
         publisher = snap.publisher
         if snap.verified:
             publisher = [publisher, ('verified', '\N{check mark}')]
         row = [
             box,
             Text(publisher),
             Text(snap.summary, wrap='clip'),
             Text("\N{BLACK RIGHT-POINTING SMALL TRIANGLE}")
         ]
         body.append(
             AttrMap(
                 TableRow(row),
                 'menu_button',
                 {
                     None: 'menu_button focus',
                     'verified': 'verified focus'
                 },
             ))
     table = NoTabCyclingTableListBox(body,
                                      colspecs={
                                          1: ColSpec(omittable=True),
                                          2: ColSpec(pack=False,
                                                     min_width=40),
                                      })
     ok = ok_btn(label=_("Done"), on_press=self.done)
     cancel = cancel_btn(label=_("Back"), on_press=self.cancel)
     self._main_screen = screen(
         table, [ok, cancel],
         focus_buttons=False,
         excerpt=_(
             "These are popular snaps in server environments. Select or "
             "deselect with SPACE, press ENTER to see more details of the "
             "package, publisher and versions available."))
Пример #14
0
 def __init__(self, model, controller, method):
     self.model = model
     self.controller = controller
     self.method = method
     cancel = cancel_btn(_("Cancel"), on_press=self.cancel)
     rows = []
     for disk in self.model.all_disks():
         for obj, cells in summarize_device(disk):
             wrap = Color.info_minor
             if obj is disk:
                 start, end = '[', ']'
                 arrow = '\N{BLACK RIGHT-POINTING SMALL TRIANGLE}'
                 if disk.size >= dehumanize_size("6G"):
                     arrow = ClickableIcon(arrow)
                     connect_signal(arrow, 'click', self.choose_disk, disk)
                     wrap = _wrap_button_row
             else:
                 start, arrow, end = '', '', ''
             if isinstance(arrow, str):
                 arrow = Text(arrow)
             rows.append(
                 wrap(TableRow([Text(start)] + cells +
                               [arrow, Text(end)])))
         rows.append(TableRow([Text("")]))
     super().__init__(
         screen(TableListBox(rows[:-1],
                             spacing=2,
                             colspecs={
                                 0: ColSpec(rpad=1),
                                 2: ColSpec(can_shrink=True),
                                 4: ColSpec(min_width=9),
                                 5: ColSpec(rpad=1),
                             },
                             align='center'),
                button_pile([cancel]),
                focus_buttons=False,
                excerpt=(excerpts[method] + "\n\n" +
                         _("Choose the disk to install to:"))))
Пример #15
0
    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'

        rows = [
            self.device_table,
            bp,
        ]

        buttons = button_pile([
                    done_btn(_("Done"), on_press=self.done),
                    back_btn(_("Back"), on_press=self.cancel),
                    ])
        self.bottom = Pile([
            ('pack', buttons),
        ])

        self.error_showing = False

        super().__init__(screen(
            rows=rows,
            buttons=self.bottom,
            focus_buttons=True,
            excerpt=self.excerpt))
Пример #16
0
 def __init__(self, parent, disk):
     self.parent = parent
     dinfo = disk.info_for_display()
     rows = []
     for label, key in labels_keys:
         v = str(dinfo[key])
         rows.append(TableRow([Text(label, align='right'), Text(v)]))
     widgets = [
         TablePile(rows, colspecs={1: ColSpec(can_shrink=True)}),
         Text(""),
         button_pile([done_btn(_("Close"), on_press=self.close)]),
         ]
     title = _("Info for {}").format(disk.label)
     super().__init__(title, widgets, 0, 2)
Пример #17
0
 def test_two_cols_confined(self):
     # When there is not enough space for the table, a column with
     # can_shrink=True is not assigned a width so urwid can give
     # that column as much space as it can.
     trows = self.rowsForContentSizes([[10, 10]])
     colspecs = defaultdict(ColSpec, {0: ColSpec(can_shrink=True)})
     widths, total, has_unpacked = _compute_widths_for_size(
         15, trows, colspecs, 0)
     self.assertEqual(
         ({
             1: 0,
             2: 10
         }, 15, False),
         (widths, total, has_unpacked),
     )
Пример #18
0
 def test_three_cols_spacing_rpad(self):
     # rpad overrides the spacing to the right of a column
     trows = self.rowsForContentSizes([[10, 10, 10]])
     colspecs = defaultdict(ColSpec, {0: ColSpec(rpad=40)})
     widths, total, has_unpacked = _compute_widths_for_size(
         100, trows, colspecs, 2)
     self.assertEqual(
         ({
             0: 10,
             1: 40,
             2: 10,
             3: 2,
             4: 10
         }, 72, False),
         (widths, total, has_unpacked),
     )
Пример #19
0
 def __init__(self, app, parent):
     rows = []
     for key, text in GLOBAL_KEYS:
         rows.append(TableRow([Text(_(key)), Text(_(text))]))
     if app.opts.dry_run:
         for key, text in DRY_RUN_KEYS:
             rows.append(TableRow([Text(_(key)), Text(_(text))]))
     table = TablePile(
         rows, spacing=2, colspecs={1: ColSpec(can_shrink=True)})
     widgets = [
         Pile([
             ('pack', Text(rewrap(GLOBAL_KEY_HELP))),
             ('pack', Text("")),
             ('pack', table),
             ]),
         Text(""),
         button_pile([close_btn(parent)]),
         ]
     super().__init__(_("Shortcut Keys"), widgets, 0, 2)
Пример #20
0
    @abc.abstractmethod
    def _make_widget(self, form):
        pass

    def bind(self, form):
        widget = self._make_widget(form)
        return BoundFormField(self, form, widget)


class WantsToKnowFormField(object):
    """A marker class."""
    def set_bound_form_field(self, bff):
        self.bff = bff


form_colspecs = {1: ColSpec(pack=False)}


class BoundFormField(object):
    def __init__(self, field, form, widget):
        self.field = field
        self.form = form
        self.widget = widget

        self.in_error = False
        self._enabled = True
        self._help = None
        self.showing_extra = False

        self._build_table()
Пример #21
0
    def __init__(self, parent, snap, cur_channel):
        self.parent = parent
        self.snap = snap
        self.needs_focus = True

        self.description = Text(snap.description.replace('\r', '').strip())
        self.lb_description = ListBox([self.description])

        latest_update = datetime.datetime.min
        radio_group = []
        channel_rows = []
        for csi in snap.channels:
            latest_update = max(latest_update, csi.released_at)
            btn = StarRadioButton(radio_group,
                                  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"))
            channel_rows.append(
                Color.menu_button(
                    TableRow([
                        btn,
                        Text(csi.version),
                        Text("(" + csi.revision + ")"),
                        Text(humanize_size(csi.size)),
                        Text(format_datetime(csi.released_at)),
                        Text(csi.confinement),
                    ])))

        first_info_row = TableRow([
            (3, Text([
                ('info_minor', "LICENSE: "),
                snap.license,
            ],
                     wrap='clip')),
            (3,
             Text([
                 ('info_minor', "LAST UPDATED: "),
                 format_datetime(latest_update),
             ])),
        ])
        heading_row = Color.info_minor(
            TableRow([
                Text("CHANNEL"),
                (2, Text("VERSION")),
                Text("SIZE"),
                Text("PUBLISHED"),
                Text("CONFINEMENT"),
            ]))
        colspecs = {
            1: ColSpec(can_shrink=True),
        }
        info_table = TablePile([
            first_info_row,
            TableRow([Text("")]),
            heading_row,
        ],
                               spacing=2,
                               colspecs=colspecs)
        self.lb_channels = NoTabCyclingTableListBox(channel_rows,
                                                    spacing=2,
                                                    colspecs=colspecs)
        info_table.bind(self.lb_channels)
        self.info_padding = Padding.pull_1(info_table)

        publisher = [('info_minor header', "by: "), snap.publisher]
        if snap.verified:
            publisher.append(('verified header', ' \N{check mark}'))

        self.title = Columns([
            Text(snap.name),
            ('pack', Text(publisher, align='right')),
        ],
                             dividechars=1)

        contents = [
            ('pack', Text(snap.summary)),
            ('pack', Text("")),
            self.lb_description,  # overwritten in render()
            ('pack', Text("")),
            ('pack', self.info_padding),
            ('pack', Text("")),
            ('weight', 1, self.lb_channels),
        ]
        self.description_index = contents.index(self.lb_description)
        self.pile = Pile(contents)
        super().__init__(self.pile)