(hooke_cli.py) added _clickize method to ease ClickPoint conversion
[hooke.git] / hooke_cli.py
index 4cc5510f327f9bcd6eeaf0d8cb1dd965ccde707d..a822042a4b0de5b522e0cccfdf3888af491b78b3 100755 (executable)
@@ -121,6 +121,8 @@ class HookeCli(cmd.Cmd):
             except ImportError:
                 pass
 
+        #load default list, if possible
+        self.do_loadlist(self.config['defaultlist'])
         
 #HELPER FUNCTIONS
 #Everything sending an event should be here
@@ -165,6 +167,16 @@ class HookeCli(cmd.Cmd):
         '''
         return self.plotmanip[self.config['plotmanips'].index(name)]
     
+    def _clickize(self, xvector, yvector, index):
+        '''
+        returns a ClickedPoint() object from an index and vectors of x, y coordinates       
+        '''
+        point=ClickedPoint()
+        point.index=index
+        point.absolute_coords=xvector[index],yvector[index]
+        point.find_graph_coords(xvector,yvector)
+        return point
+    
 #HERE COMMANDS BEGIN
     
     def help_set(self):
@@ -214,7 +226,7 @@ Syntax: loadlist [playlist file]
     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]
@@ -270,7 +282,7 @@ Syntax: genlist [input files]
     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]
@@ -321,7 +333,7 @@ Syntax: genlist [input files]
         Syntax: savelist [filename]
         '''
         while len(args)==0:
-            args=linp.alphainput('Output files?','',1,[])
+            args=linp.safeinput('Output file?',['savedlist.txt'])
     
         output_filename=args
         
@@ -387,7 +399,7 @@ If the curve is not in the current playlist, it politely asks if we want to add
         '''
         
         if filename=='':
-            filename=linp.alphainput('Jump to?','',0,[])
+            filename=linp.safeinput('Jump to?')
             
         filepath=os.path.abspath(filename)
         print filepath
@@ -406,7 +418,7 @@ If the curve is not in the current playlist, it politely asks if we want to add
                     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)
@@ -611,7 +623,7 @@ If you have a multiple plot, the optional plot to export argument tells Hooke wh
         
         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]
@@ -646,7 +658,7 @@ Syntax: txt [filename] {plot to export}
         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:
@@ -715,7 +727,7 @@ Syntax: txt [filename] {plot to export}
             print self.current_list[self.pointer].notes
         else:
             if self.notes_filename == None:
-                self.notes_filename=raw_input('Filename? ')
+                self.notes_filename=raw_input('Notebook filename? ')
                 title_line='Notes taken at '+time.asctime()+'\n'
                 f=open(self.notes_filename,'w')
                 f.write(title_line)
@@ -746,7 +758,7 @@ Syntax notelog [filename]
     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:
@@ -776,7 +788,7 @@ Syntax copylog [directory]
     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):
@@ -787,12 +799,11 @@ Syntax copylog [directory]
             if len(item.notes)>0:
                 try:
                     shutil.copy(item.path, mydir)
-                except OSError:
-                    print 'OSError. Cannot copy file. Perhaps you gave me a wrong directory?'
+                except (OSError, IOError):
+                    print 'Cannot copy file. '+item.path+' Perhaps you gave me a wrong directory?'
 
 #OUTLET management
-
-
+#-----------------
     def do_outlet_show(self,args):
         '''OUTLET_SHOW
         ---------
@@ -818,10 +829,6 @@ Syntax copylog [directory]
         else:
             self.outlet.delete(args)
 
-
-
-
-
 #OS INTERACTION COMMANDS
 #-----------------    
     def help_dir(self):
@@ -896,6 +903,20 @@ Syntax: current
     def do_current(self,args):
         print self.current.path
         
+    def do_info(self,args):
+        '''
+        INFO
+        ----
+        Returns informations about the current curve.
+        '''
+        print 'Path: ',self.current.path
+        print 'Experiment: ',self.current.curve.experiment
+        print 'Filetype: ',self.current.curve.filetype
+        for plot in self.current.curve.default_plots():
+            for set in plot.vectors:
+                lengths=[len(item) for item in set]
+                print 'Data set size: ',lengths
+        
     def do_version(self,args):
         '''
         VERSION
@@ -928,9 +949,9 @@ Syntax: quit
         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.safeinput('Exit?',['y'])
         
         if we_exit[0].upper()=='Y':
             wx.CallAfter(self.frame.Close)