Пример #1
0
 def load_autoinstall_data(self, ai_data):
     to_install = {}
     for snap in ai_data:
         to_install[snap['name']] = SnapSelection(
             channel=snap.get('channel', 'stable'),
             is_classic=snap.get('classic', False))
     self.model.set_installed_list(to_install)
Пример #2
0
 def state_change(self, sender, new_state):
     if new_state:
         self.parent.to_install[self.snap.name] = SnapSelection(
             channel='stable',
             is_classic=self.snap.confinement == "classic")
     else:
         self.parent.to_install.pop(self.snap.name, None)
Пример #3
0
    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)
Пример #4
0
 def default(self):
     if self.loader.failed:
         # If loading snaps failed, skip the screen.
         raise Skip()
     if 'snaps' in self.answers:
         to_install = {}
         for snap_name, selection in self.answers['snaps'].items():
             to_install[snap_name] = SnapSelection(**selection)
         self.done(to_install)
         return
     self.ui.set_body(SnapListView(self.model, self))
Пример #5
0
 def start_ui(self):
     if self.loader.failed or not self.app.base_model.network.has_network:
         # If loading snaps failed or the network is disabled, skip the
         # screen.
         self.configured()
         raise Skip()
     if 'snaps' in self.answers:
         to_install = {}
         for snap_name, selection in self.answers['snaps'].items():
             to_install[snap_name] = SnapSelection(**selection)
         self.done(to_install)
         return
     self.ui.set_body(SnapListView(self.model, self))
Пример #6
0
 def default(self):
     if self.loader.failed or not self.base_model.network.has_network:
         # If loading snaps failed or the network is disabled, skip the
         # screen.
         self.signal.emit_signal("installprogress:snap-config-done")
         raise Skip()
     if 'snaps' in self.answers:
         to_install = {}
         for snap_name, selection in self.answers['snaps'].items():
             to_install[snap_name] = SnapSelection(**selection)
         self.done(to_install)
         return
     self.ui.set_body(SnapListView(self.model, self))
Пример #7
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)