1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #! /usr/bin/env python
import dialog
class DialogManager(dialog.Dialog):
def __init__(self, applicationtitle="No title", function=dialog.Dialog.menu):
dialog.Dialog.__init__(self)
self.applicationtitle = applicationtitle
self.add_persistent_args(["--backtitle", self.applicationtitle])
self.TIMER = 0
def dialogBox(self, function="menu", data=[("0", "title"), ("1", "menu1")], height=35, width=54, menu_height=7, **kwargs):
function = getattr(self, function)
while 1:
(code, tag) = function(self, data[0][1], height=height, width=width, menu_height=menu_height, choices=data[1:])
if DialogManager.handle_exit_code(self, code):
break
return code, tag
def handle_exit_code(self, code):
if code in (self.DIALOG_CANCEL, self.DIALOG_ESC):
if code == self.DIALOG_CANCEL:
msg = "You chose cancel in the last dialog box. Do you want to exit ?"
else:
msg = "You pressed ESC in the last dialog box. Do you want to exit ?"
if self.yesno(msg) == self.DIALOG_OK:
sys.exit(0)
return 0
else:
return 1
def main():
try:
d = DialogManager("df")
d.dialogBox()
#print d.code, d.tag, d.width
except dialog.error, exc_instance:
sys.stderr.write("Error:\n\n%s\n" % exc_instance.complete_message())
sys.exit(1)
sys.exit(0)
if __name__ == "__main__": main() |
Partager