def do_loadlist(self, args):
#checking for args: if nothing is given as input, we warn and exit.
while len(args)==0:
- args=linp.alphainput('File to load?','',0,[])
+ args=linp.safeinput('File to load?')
arglist=args.split()
play_to_load=arglist[0]
def do_genlist(self,args):
#args list is: input path, output name
if len(args)==0:
- args=linp.alphainput('Input files?','',1,[])
+ args=linp.safeinput('Input files?',[])
arglist=args.split()
list_path=arglist[0]
Syntax: savelist [filename]
'''
while len(args)==0:
- args=linp.alphainput('Output files?','',1,[])
+ args=linp.safeinput('Output file?',['savedlist.txt'])
output_filename=args
'''
if filename=='':
- filename=linp.alphainput('Jump to?','',0,[])
+ filename=linp.safeinput('Jump to?')
filepath=os.path.abspath(filename)
print filepath
c+=1
except IndexError:
#We've found the end of the list.
- answer=linp.alphainput('Curve not found in playlist. Add it to list?','y',0,[])
+ answer=linp.safeinput('Curve not found in playlist. Add it to list?',['y'])
if answer.lower()[0]=='y':
try:
self.do_addtolist(filepath)
dest=0
if args=='':
- name=linp.alphainput('Filename?',self.current.path+'.png',0,[])
+ name=linp.safeinput('Filename?',[self.current.path+'.png'])
else:
args=args.split()
name=args[0]
whichplot=0
args=args.split()
if len(args)==0:
- filename=linp.alphainput('Filename?',self.current.path+'.txt',0,[])
+ filename=linp.safeinput('Filename?',[self.current.path+'.txt'])
else:
filename=linp.checkalphainput(args[0],self.current.path+'.txt',[])
try:
def do_notelog(self,args):
if len(args)==0:
- args=linp.alphainput('Notelog filename?','notelog.txt',0,[])
+ args=linp.safeinput('Notelog filename?',['notelog.txt'])
note_lines='Notes taken at '+time.asctime()+'\n'
for item in self.current_list:
def do_copylog(self,args):
if len(args)==0:
- args=linp.alphainput('Destination directory?','',0,[]) #TODO default
+ args=linp.safeinput('Destination directory?') #TODO default
mydir=os.path.abspath(args)
if not os.path.isdir(mydir):
we_exit='N'
if (not self.playlist_saved) or (not self.notes_saved):
- we_exit=linp.alphainput('You did not save your playlist and/or notes. Exit?','n',0,[])
+ we_exit=linp.safeinput('You did not save your playlist and/or notes. Exit?',['n'])
else:
- we_exit=linp.alphainput('Exit?','y',0,[])
+ we_exit=linp.alphainput('Exit?',['y'])
if we_exit[0].upper()=='Y':
wx.CallAfter(self.frame.Close)
This program is released under the GNU General Public License version 2.
'''
+from types import *
+
+
+
+def safeinput (message, valid=[]):
+ '''
+ friendlier frontend for alphainput and numinput
+ valid should be a list of 0...n values
+ '''
+
+ #if possible values are not listed we just ask for any non-null input
+ if len(valid)==0:
+ return alphainput(message, '',1,[])
+
+
+ if len(valid)>0:
+ #if valid values are string we use alphainput, if it is only one we take as default
+ if type(valid[0]) is StringType:
+ if len(valid)==1:
+ return alphainput(message, valid[0], 0,[])
+ else:
+ return alphainput(message,'', 1,valid)
+
+ #if valid values are numbers we use numinput
+ if type(valid[0]) is IntType:
+ if len(valid)==1:
+ return numinput(message,valid[0],1,[])
+ else:
+ return numinput(message,'',1,valid)
+
+
+
def alphainput (message, default, repeat, valid):
'''
message: prompt for the user
limits: pair of values, input is checked to be between them, empty list for "any number"
'''
if default and not repeat:
- print 'Enter for default: '+str(default)
+ print 'Press [enter] for default: '+str(default)
+
reply=raw_input(message)
- if reply:
- reply=int(reply)
+
+ try:
+ intreply=int(reply)
+ except:
+ intreply=None
+
if len(limits)==2:
high=int(limits.pop())
low=int(limits.pop())
- if reply>=low and reply <= high:
- return reply
+ if intreply>=low and intreply <= high:
+ return intreply
else:
if repeat==1:
- while reply<low or reply>high :
+ while intreply<low or intreply>high :
reply=raw_input('You should enter values between: '+ str(low)+' and '+str(high) +'\n'+ message)
- if reply:
- reply=int(reply)
- return reply
+ try:
+ intreply=int(reply)
+ except:
+ intreply=None
+ return intreply
else:
return default
else:
- if len(reply)>0:
- return int(reply)
+ if intreply!=None:
+ return intreply
else:
if not repeat:
return default
else:
- while len(reply)==0:
+ while intreply==None:
print 'Try again'
reply=raw_input(message)
- return reply
+ try:
+ intreply=int(reply)
+ except:
+ intreply=None
+ return intreply
def checknuminput(test,default,limits):
#useful when input was taken from command args
import libviewer as lview
-import libinput as limput
+import libinput as linput
class viewerCommands:
def do_vwnew(self,args):
#creates a new viewer
self.viewerlist.append(lview.Ascii(self.outlet))
- dt=limput.alphainput('What type of data will this viewer handle? (force/distance/all)','',1,['force', 'distance', 'all']) #TODO update types, make a list somewhere?
+ dt=linput.safeinput('What type of data will this viewer handle? (force/distance/all)',['force', 'distance', 'all'])
+ #TODO update types, make a list somewhere?
print dt
self.viewerlist[-1].setdtype(dt)
if len(args)==0:
args=0
- self.viewerlist[int(args)].action()
+ self.viewerlist[int(args)].action()
\ No newline at end of file