[gest_crans_lc] nettoyage de la fonction handle_exit_code

This commit is contained in:
Nicolas Dandrimont 2015-02-23 01:35:48 +01:00
parent 6ff3e180a2
commit e274be0864

View file

@ -13,33 +13,58 @@ Licence : GPLv3
### --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)
import argparse
import os
import sys
import argparse
import subprocess
if '/usr/scripts' not in sys.path:
sys.path.append('/usr/scripts')
import lc_ldap.objets as objets
import lc_ldap.attributs as attributs
import lc_ldap.objets as objets
from dialog import adherent, club, machine
from dialog.CPS import TailCall, tailcaller
from dialog.lc import main
def handle_exit_code(d, code):
"""Gère les codes de retour dialog du menu principal"""
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
if code == d.DIALOG_CANCEL:
#msg = "Vous avez choisi Annuler dans la dernière fenêtre de dialogue.\n\n" \
# "Voulez vous quitter le programme ?"
os.system('clear')
sys.exit(0)
else:
msg = "Vous avez appuyé sur ESC ou CTRL+C dans la dernière fenêtre de dialogue.\n\n" \
"Voulez vous quitter le programme ?"
if d.yesno(msg, width=60) == d.DIALOG_OK:
os.system('clear')
def handle_dialog_exit_code(dialog, code):
"""Gère les codes de retour du menu principal.
Paramètres:
- ``dialog``: (pythondialog.Dialog) instance courante de l'objet Dialog
- ``code`` : (int) code de retour de la fenêtre Dialog
Retourne:
- ``True`` quand dialog a quitté correctement (l'utilisateur a bien
saisi une valeur)
- ``False`` quand l'utilisateur annule la sortie du programme
(aucune valeur n'a été saisie)
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
else:
return True
@ -143,10 +168,10 @@ class GestCrans(adherent.Dialog, club.Dialog, machine.Dialog):
backtitle=self._connected_as(),
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)
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))
else:
return self_cont