6 Copyright (C) 2008 Alberto Gomez-Casado (University of Twente).
8 This program is released under the GNU General Public License version 2.
11 def alphainput (message, default, repeat, valid):
13 message: prompt for the user
14 default: return value if user input was not correct (and repeat=0)
15 repeat: keeps asking user till it gets a valid input
16 valid: list of allowed answers, empty list for "anything"
18 if default and not repeat:
19 print 'Press [enter] for default: ('+str(default)+')'
20 reply=raw_input(message)
26 while reply not in valid:
27 reply=raw_input('You should enter any of these: '+ str(valid) +'\n'+ message)
40 reply=raw_input(message)
45 def checkalphainput (test, default, valid):
46 #useful when input was taken form command args
53 #TODO: raise exception?
60 def numinput(message, default, repeat, limits):
62 message: prompt for the user
63 default: return value if user input was not correct (and repeat=0)
64 repeat: keeps asking user till it gets a valid input
65 limits: pair of values, input is checked to be between them, empty list for "any number"
67 if default and not repeat:
68 print 'Enter for default: '+str(default)
69 reply=raw_input(message)
73 high=int(limits.pop())
75 if reply>=low and reply <= high:
79 while reply<low or reply>high :
80 reply=raw_input('You should enter values between: '+ str(low)+' and '+str(high) +'\n'+ message)
95 reply=raw_input(message)
98 def checknuminput(test,default,limits):
99 #useful when input was taken from command args
101 high=int(limits.pop())
102 low=int(limits.pop())
103 if test>=low and test <= high: