class GuidedChoiceForm(SubForm): disk = ChoiceField(caption=NO_CAPTION, help=NO_HELP, choices=["x"]) use_lvm = BooleanField(_("Set up this disk as an LVM group"), help=NO_HELP) lvm_options = SubFormField(LVMOptionsForm, "", help=NO_HELP) def __init__(self, parent): super().__init__(parent) options = [] tables = [] initial = -1 for disk in parent.model.all_disks(): for obj, cells in summarize_device(disk): table = TablePile([TableRow(cells)]) tables.append(table) enabled = False if obj is disk and disk.size > 6 * (2**30): enabled = True if initial < 0: initial = len(options) options.append(Option((table, enabled, obj))) t0 = tables[0] for t in tables[1:]: t0.bind(t) self.disk.widget.options = options self.disk.widget.index = initial connect_signal(self.use_lvm.widget, 'change', self._toggle) self.lvm_options.enabled = self.use_lvm.value def _toggle(self, sender, val): self.lvm_options.enabled = val
class LVMOptionsForm(SubForm): def __init__(self, parent): super().__init__(parent) connect_signal(self.encrypt.widget, 'change', self._toggle) self.luks_options.enabled = self.encrypt.value def _toggle(self, sender, val): self.luks_options.enabled = val encrypt = BooleanField(_("Encrypt the LVM group with LUKS"), help=NO_HELP) luks_options = SubFormField(LUKSOptionsForm, "", help=NO_HELP)
class GuidedForm(Form): group = [] guided = RadioButtonField(group, _("Use an entire disk"), help=NO_HELP) guided_choice = SubFormField(GuidedChoiceForm, "", help=NO_HELP) custom = RadioButtonField(group, _("Custom storage layout"), help=NO_HELP) cancel_label = _("Back") def __init__(self, model): self.model = model super().__init__() connect_signal(self.guided.widget, 'change', self._toggle_guided) def _toggle_guided(self, sender, new_value): self.guided_choice.enabled = new_value