From a6b1cab0779c534543ab385649dcd5cbdd83f3bf Mon Sep 17 00:00:00 2001 From: Werner Llácer Date: Thu, 10 Mar 2022 09:42:03 +0100 Subject: Additions to Listmgr et alia (#1028) * Permit multiple default actions as a list * Define headers for list at ListManager and Menu * small corrections for default values * Make subvolume info work. The real marker that signifies that a mounted subvolume exist is the bracket notation nor the at sign --- archinstall/lib/menu/list_manager.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'archinstall/lib/menu/list_manager.py') diff --git a/archinstall/lib/menu/list_manager.py b/archinstall/lib/menu/list_manager.py index e307e41f..bacfc60e 100644 --- a/archinstall/lib/menu/list_manager.py +++ b/archinstall/lib/menu/list_manager.py @@ -90,9 +90,10 @@ from .menu import Menu from ..general import RequirementError from os import system from copy import copy +from typing import Union class ListManager: - def __init__(self,prompt :str, base_list :list ,base_actions :list = None,null_action :str = None, default_action :str = None): + def __init__(self,prompt :str, base_list :Union[list,dict] ,base_actions :list = None,null_action :str = None, default_action :Union[str,list] = None, header :Union[str,list] = None): """ param :prompt Text which will appear at the header type param: string | DeferredTranslation @@ -108,7 +109,10 @@ class ListManager: param: default_action action which will be presented at the bottom of the list. Shouldn't need a target. If not present, null_action is set there. Both Null and Default actions can be defined outside the base_actions list, as long as they are launched in exec_action - type param: string + type param: string or list + + param: header one or more header lines for the list + type param: string or list """ if not null_action and len(base_list) == 0: @@ -117,9 +121,13 @@ class ListManager: self.prompt = prompt if prompt else _('Choose an object from the list') self.null_action = str(null_action) if not default_action: - self.default_action = self.null_action + self.default_action = [self.null_action,] + elif isinstance(default_action,(list,tuple)): + self.default_action = default_action else: - self.default_action = str(default_action) + self.default_action = [str(default_action),] + + self.header = header if header else None self.cancel_action = str(_('Cancel')) self.confirm_action = str(_('Confirm and exit')) self.separator = '==>' @@ -140,23 +148,24 @@ class ListManager: self.data_formatted = self.reformat() options = self.data_formatted + [self.separator] if self.default_action: - options += [self.default_action] + options += self.default_action options += self.bottom_list system('clear') target = Menu(self.prompt, options, sort=False, clear_screen=False, - clear_menu_on_exit=False).run() + clear_menu_on_exit=False, + header=self.header).run() if not target or target in self.bottom_list: break if target and target == self.separator: continue - if target and target == self.default_action: + if target and target in self.default_action: + self.action = target target = None self.target = None - self.action = self.default_action self.exec_action() continue if isinstance(self.data,dict): @@ -216,7 +225,6 @@ class ListManager: The basic code is useful for simple lists and dictionaries (key:value pairs, both strings) """ # TODO guarantee unicity - if isinstance(self.data,list): if self.action == str(_('Add')): self.target = TextInput(_('Add :'),None).run() @@ -264,6 +272,7 @@ if __name__ == "__main__": # opciones = ['uno','dos','tres','cuatro'] # opciones = archinstall.list_mirrors() opciones = {'uno':1,'dos':2,'tres':3,'cuatro':4} - # acciones = ['editar','borrar','añadir'] - opciones = ListManager('Vamos alla',opciones,None,_('Add')).run() + acciones = ['editar','borrar','añadir'] + cabecera = ["En Jaen Donde Resido","Vive don Lope de Sosa"] + opciones = ListManager('Vamos alla',opciones,None,_('Add'),default_action=acciones,header=cabecera).run() print(opciones) -- cgit v1.2.3-54-g00ecf