Exemple #1
0
 def _action_menu_for_device(self, device):
     device_actions = []
     for action in DeviceAction.supported(device):
         label_meth = getattr(self, '_label_{}'.format(action.name),
                              lambda a, d: a.str())
         label = label_meth(action, device)
         enabled, whynot = action.can(device)
         if whynot:
             assert not enabled
             enabled = True
             label += " *"
             meth = _whynot_shower(self.parent, action, whynot)
         else:
             meth_name = '_{}_{}'.format(device.type, action.name)
             meth = getattr(self, meth_name)
         if not whynot and action in [
                 DeviceAction.DELETE, DeviceAction.REFORMAT
         ]:
             label = Color.danger_button(ActionMenuOpenButton(label))
         device_actions.append(
             Action(label=label,
                    enabled=enabled,
                    value=(action, meth),
                    opens_dialog=getattr(meth, 'opens_dialog', False)))
     menu = ActionMenu(device_actions)
     connect_signal(menu, 'action', self._action, device)
     return menu
 def _action_menu_for_device(self, device):
     device_actions = []
     for action in device.supported_actions:
         label = _(action.value)
         if action == DeviceAction.REMOVE and device.constructed_device():
             cd = device.constructed_device()
             label = _("Remove from {}").format(cd.desc())
         enabled, whynot = device.action_possible(action)
         if whynot:
             assert not enabled
             enabled = True
             label += " *"
             meth = _whynot_shower(self.parent, action, whynot)
         else:
             meth_name = '_{}_{}'.format(device.type, action.name)
             meth = getattr(self, meth_name)
         if not whynot and action == DeviceAction.DELETE:
             label = Color.danger_button(ActionMenuOpenButton(label))
         device_actions.append(Action(
             label=label,
             enabled=enabled,
             value=(action, meth),
             opens_dialog=getattr(meth, 'opens_dialog', False)))
     menu = ActionMenu(device_actions)
     connect_signal(menu, 'action', self._action, device)
     return menu
Exemple #3
0
    def __init__(self, controller, systems):
        self.controller = controller

        heading_table = TablePile([
            TableRow([
                Color.info_minor(Text(header))
                for header in ["LABEL", "MODEL", "PUBLISHER", ""]
            ])
        ],
                                  spacing=2)

        trows = []
        systems = sorted(
            systems,
            key=lambda s:
            (s.brand.display_name, s.model.display_name, s.current, s.label))
        for s in systems:
            actions = []
            log.debug('actions: %s', s.actions)
            for act in sorted(s.actions, key=by_preferred_action_type):
                actions.append(
                    Action(label=act.title.capitalize(),
                           value=act,
                           enabled=True))
            menu = ActionMenu(actions)
            connect_signal(menu, 'action', self._system_action, s)
            srow = make_action_menu_row([
                Text(s.label),
                Text(s.model.display_name),
                Text(s.brand.display_name),
                Text("(installed)" if s.current else ""),
                menu,
            ], menu)
            trows.append(srow)

        systems_table = TablePile(trows, spacing=2)
        systems_table.bind(heading_table)
        rows = [
            Pile([heading_table, systems_table]),
        ]

        buttons = []
        if controller.model.current is not None:
            # back to options of current system
            buttons.append(back_btn("BACK", on_press=self.back))

        super().__init__(
            controller.model.current,
            screen(rows=rows,
                   buttons=button_pile(buttons),
                   focus_buttons=False,
                   excerpt=self.excerpt))
Exemple #4
0
 def _action_menu_for_device(self, device):
     if can_delete(device)[0]:
         delete_btn = Color.danger_button(ActionMenuButton(_("Delete")))
     else:
         delete_btn = _("Delete *")
     device_actions = [
         (_("Information"), DeviceAction.INFO),
         (_("Edit"), DeviceAction.EDIT),
         (_("Add Partition"), DeviceAction.PARTITION),
         (_("Format / Mount"), DeviceAction.FORMAT),
         (delete_btn, DeviceAction.DELETE),
         (_("Make boot device"), DeviceAction.MAKE_BOOT),
     ]
     actions = []
     for label, action in device_actions:
         actions.append(
             Action(label=label,
                    enabled=device.supports_action(action),
                    value=action,
                    opens_dialog=action != DeviceAction.MAKE_BOOT))
     menu = ActionMenu(actions, "\N{BLACK RIGHT-POINTING SMALL TRIANGLE}")
     connect_signal(menu, 'action', self._action, device)
     return menu