-
Notifications
You must be signed in to change notification settings - Fork 0
/
three.py
89 lines (78 loc) · 2.37 KB
/
three.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
experiment with a main menu and switch / case construction
"""
class _Getch(object):
"""read character from stdin without return"""
def __init__(self):
try:
self.impl = _GetchWindows()
except ImportError:
self.impl = _GetchUnix()
def __call__(self):
return self.impl()
class _GetchUnix(object):
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class _GetchWindows(object):
def __init__(self):
import msvcrt
def __call__(self):
import msvcrt
return msvcrt.getch()
class Switcher(object):
def main_menu(self, argument):
"""dispatch method / main menu with switch case / three tasks"""
method_name = 'fall_' + str(argument)
# Get the method from 'self'. Default to a lambda.
method = getattr(self, method_name, lambda: "nothing to compute")
# Call the method as we return it
return method()
def fall_1(self):
#emulate slow progress
from time import sleep
import sys
i=0
for i in range (12):
sleep (0.5)
sys.stdout.write (".")
sys.stdout.flush()
print("")
return "January"
def fall_2(self):
#output Switcher dictionary
print (Switcher.__dict__)
return "February"
def fall_3(self):
#return given string
query = input ("gimme a string: ")
return query
def main():
foo = _Getch()
char = "#"
while (ord(char) != 52):
print ("----------------------------")
print ("| 1 : menu point one |")
print ("| 2 : menu point two |")
print ("| 3 : menu point three |")
print ("| 4 : ende |")
print ("----------------------------")
char = foo.impl()
wert = ord(char)
choice = wert - 48
#print (char + " _ " + str(wert))
bar = Switcher()
output = bar.main_menu(choice)
print (output)
print ("programmende")
if __name__ == "__main__":
main()