[gest_crans_lc] nettoyage de la fonction handle_exit_code
This commit is contained in:
parent
6ff3e180a2
commit
e274be0864
1 changed files with 43 additions and 18 deletions
|
@ -13,33 +13,58 @@ Licence : GPLv3
|
||||||
### --default-button pour choisir le bouton sélectionner par defaut
|
### --default-button pour choisir le bouton sélectionner par defaut
|
||||||
### --not-tags pour masquer les tags quand il ne servent à rien pour l'utilisateur (mais sont utilisé comme index par le programme)
|
### --not-tags pour masquer les tags quand il ne servent à rien pour l'utilisateur (mais sont utilisé comme index par le programme)
|
||||||
|
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import subprocess
|
||||||
|
|
||||||
if '/usr/scripts' not in sys.path:
|
if '/usr/scripts' not in sys.path:
|
||||||
sys.path.append('/usr/scripts')
|
sys.path.append('/usr/scripts')
|
||||||
|
|
||||||
import lc_ldap.objets as objets
|
|
||||||
import lc_ldap.attributs as attributs
|
import lc_ldap.attributs as attributs
|
||||||
|
import lc_ldap.objets as objets
|
||||||
|
|
||||||
from dialog import adherent, club, machine
|
from dialog import adherent, club, machine
|
||||||
from dialog.CPS import TailCall, tailcaller
|
from dialog.CPS import TailCall, tailcaller
|
||||||
from dialog.lc import main
|
from dialog.lc import main
|
||||||
|
|
||||||
def handle_exit_code(d, code):
|
|
||||||
"""Gère les codes de retour dialog du menu principal"""
|
def handle_dialog_exit_code(dialog, code):
|
||||||
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
|
"""Gère les codes de retour du menu principal.
|
||||||
if code == d.DIALOG_CANCEL:
|
|
||||||
#msg = "Vous avez choisi Annuler dans la dernière fenêtre de dialogue.\n\n" \
|
Paramètres:
|
||||||
# "Voulez vous quitter le programme ?"
|
- ``dialog``: (pythondialog.Dialog) instance courante de l'objet Dialog
|
||||||
os.system('clear')
|
- ``code`` : (int) code de retour de la fenêtre Dialog
|
||||||
sys.exit(0)
|
|
||||||
else:
|
Retourne:
|
||||||
msg = "Vous avez appuyé sur ESC ou CTRL+C dans la dernière fenêtre de dialogue.\n\n" \
|
- ``True`` quand dialog a quitté correctement (l'utilisateur a bien
|
||||||
"Voulez vous quitter le programme ?"
|
saisi une valeur)
|
||||||
if d.yesno(msg, width=60) == d.DIALOG_OK:
|
- ``False`` quand l'utilisateur annule la sortie du programme
|
||||||
os.system('clear')
|
(aucune valeur n'a été saisie)
|
||||||
sys.exit(0)
|
|
||||||
|
Lève les exceptions:
|
||||||
|
- :py:exc:`SystemExit` quand la sortie du programme est confirmée
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def exit_from_program():
|
||||||
|
"""
|
||||||
|
Quitte le programme après avoir vidé la console
|
||||||
|
|
||||||
|
Lève l'exception :py:exc:`SystemExit`
|
||||||
|
"""
|
||||||
|
subprocess.call('clear')
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if code == dialog.DIALOG_CANCEL:
|
||||||
|
exit_from_program()
|
||||||
|
elif code == dialog.DIALOG_ESC:
|
||||||
|
msg = (
|
||||||
|
"Vous avez appuyé sur ESC ou CTRL+C dans la dernière fenêtre"
|
||||||
|
" de dialogue.\n\nVoulez vous quitter le programme ?"
|
||||||
|
)
|
||||||
|
if dialog.yesno(msg, width=60) == dialog.DIALOG_OK:
|
||||||
|
exit_from_program()
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
@ -143,10 +168,10 @@ class GestCrans(adherent.Dialog, club.Dialog, machine.Dialog):
|
||||||
backtitle=self._connected_as(),
|
backtitle=self._connected_as(),
|
||||||
choices=choices)
|
choices=choices)
|
||||||
|
|
||||||
(code, tag) = self.handle_dialog(TailCall(handle_exit_code, self.dialog, self.dialog.DIALOG_ESC), box, tag)
|
(code, tag) = self.handle_dialog(TailCall(handle_dialog_exit_code, self.dialog, self.dialog.DIALOG_ESC), box, tag)
|
||||||
self_cont = TailCall(self.menu_principal, tag=tag, proprio=proprio, machine=machine)
|
self_cont = TailCall(self.menu_principal, tag=tag, proprio=proprio, machine=machine)
|
||||||
callback = menu.get(tag, menu[''])['callback']
|
callback = menu.get(tag, menu[''])['callback']
|
||||||
if handle_exit_code(self.dialog, code) and callback:
|
if handle_dialog_exit_code(self.dialog, code) and callback:
|
||||||
return TailCall(callback, cont=TailCall(self.menu_principal, tag=tag, machine=machine, proprio=proprio))
|
return TailCall(callback, cont=TailCall(self.menu_principal, tag=tag, machine=machine, proprio=proprio))
|
||||||
else:
|
else:
|
||||||
return self_cont
|
return self_cont
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue