5.14. Utilisation de NormalTUISpoke pour définir un spoke d'interface texte
5.14. Utilisation de NormalTUISpoke pour définir un spoke d'interface texte
L'exemple de la définition d'une interface utilisateur simple a montré une façon d'implémenter une interface utilisateur dont les méthodes gèrent l'impression et le traitement des données disponibles et fournies. Cependant, il existe une autre façon d'y parvenir en utilisant la classe Normal EditTUISpoke du paquetage pyanaconda.ui.tui.spokes. En héritant de cette classe, vous pouvez mettre en œuvre un rayon d'interface utilisateur typique en spécifiant uniquement les champs et les attributs qui doivent être définis dans ce rayon. L'exemple suivant en est la démonstration :
Créez des modules avec toutes les définitions requises pour ajouter la prise en charge de l'interface utilisateur textuelle (TUI) du module complémentaire, conformément aux exemples suivants.
Exemple 5.12. Utilisation de NormalTUISpoke pour définir un spoke d'interface texte
class HelloWorldEditSpoke(NormalTUISpoke):
"""Example class demonstrating usage of editing in TUI"""
category = HelloWorldCategory
def init(self, data, storage, payload):
"""
:see: simpleline.render.screen.UIScreen
:param data: data object passed to every spoke to load/store data
from/to it
:type data: pykickstart.base.BaseHandler
:param storage: object storing storage-related information
(disks, partitioning, bootloader, etc.)
:type storage: blivet.Blivet
:param payload: object storing packaging-related information
:type payload: pyanaconda.packaging.Payload
"""
NormalTUISpoke.init(self, data, storage, payload)
self.title = N_("Hello World Edit")
self._container = None
# values for user to set
self._checked = False
self._unconditional_input = ""
self._conditional_input = ""
def refresh(self, args=None):
"""
The refresh method that is called every time the spoke is displayed.
It should update the UI elements according to the contents of
self.data.
:see: pyanaconda.ui.common.UIObject.refresh
:see: simpleline.render.screen.UIScreen.refresh
:param args: optional argument that may be used when the screen is
scheduled
:type args: anything
"""
super().refresh(args)
self._container = ListColumnContainer(columns=1)
# add ListColumnContainer to window (main window container)
# this will automatically add numbering and will call callbacks when required
self.window.add(self._container)
self._container.add(CheckboxWidget(title="Simple checkbox", completed=self._checked),
callback=self._checkbox_called)
self._container.add(EntryWidget(title="Unconditional text input",
value=self._unconditional_input),
callback=self._get_unconditional_input)
# show conditional input only if the checkbox is checked
if self._checked:
self._container.add(EntryWidget(title="Conditional password input",
value="Password set" if self._conditional_input
else ""),
callback=self._get_conditional_input)
self._window.add_separator()
@property
def completed(self):
# completed if user entered something non-empty to the Conditioned input
return bool(self._conditional_input)
@property
def status(self):
return "Hidden input %s" % ("entered" if self._conditional_input
else "not entered")
def apply(self):
# nothing needed here, values are set in the self.args tree
pass
class HelloWorldEditSpoke(NormalTUISpoke):
"""Example class demonstrating usage of editing in TUI"""
category = HelloWorldCategory
def init(self, data, storage, payload):
"""
:see: simpleline.render.screen.UIScreen
:param data: data object passed to every spoke to load/store data
from/to it
:type data: pykickstart.base.BaseHandler
:param storage: object storing storage-related information
(disks, partitioning, bootloader, etc.)
:type storage: blivet.Blivet
:param payload: object storing packaging-related information
:type payload: pyanaconda.packaging.Payload
"""
NormalTUISpoke.init(self, data, storage, payload)
self.title = N_("Hello World Edit")
self._container = None
# values for user to set
self._checked = False
self._unconditional_input = ""
self._conditional_input = ""
def refresh(self, args=None):
"""
The refresh method that is called every time the spoke is displayed.
It should update the UI elements according to the contents of
self.data.
:see: pyanaconda.ui.common.UIObject.refresh
:see: simpleline.render.screen.UIScreen.refresh
:param args: optional argument that may be used when the screen is
scheduled
:type args: anything
"""
super().refresh(args)
self._container = ListColumnContainer(columns=1)
# add ListColumnContainer to window (main window container)
# this will automatically add numbering and will call callbacks when required
self.window.add(self._container)
self._container.add(CheckboxWidget(title="Simple checkbox", completed=self._checked),
callback=self._checkbox_called)
self._container.add(EntryWidget(title="Unconditional text input",
value=self._unconditional_input),
callback=self._get_unconditional_input)
# show conditional input only if the checkbox is checked
if self._checked:
self._container.add(EntryWidget(title="Conditional password input",
value="Password set" if self._conditional_input
else ""),
callback=self._get_conditional_input)
self._window.add_separator()
@property
def completed(self):
# completed if user entered something non-empty to the Conditioned input
return bool(self._conditional_input)
@property
def status(self):
return "Hidden input %s" % ("entered" if self._conditional_input
else "not entered")
def apply(self):
# nothing needed here, values are set in the self.args tree
pass
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.
Rendre l’open source plus inclusif
Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.
À propos de Red Hat
Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.