(autopeak.py) prints measurements before AND after choosing peaks
[hooke.git] / hooke_cli.py
index d50afcfafd3d095fb18d6f0bc14e66c877892dc6..a822042a4b0de5b522e0cccfdf3888af491b78b3 100755 (executable)
@@ -102,6 +102,7 @@ class HookeCli(cmd.Cmd):
         self.playlist_saved=0
         self.playlist_name=''
         self.notes_saved=1
+        self.notes_filename=None
 
         #create outlet
         self.outlet=lout.Outlet()
@@ -120,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
@@ -164,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):
@@ -213,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]
@@ -269,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]
@@ -320,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
         
@@ -386,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
@@ -405,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)
@@ -610,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]
@@ -645,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:
@@ -670,16 +683,20 @@ Syntax: txt [filename] {plot to export}
         
     
     #LOGGING, REPORTING, NOTETAKING
-    def help_note(self):
-        print '''
-NOTE
-Writes or displays a note about the current curve.
-If [anything] is empty, it displays the note, otherwise it adds a note.
-The note is then saved in the playlist if you issue a savelist command
----------------
-Syntax: note [anything]        
-'''
-    def do_note(self,args):
+    
+
+    def do_note_old(self,args):
+        '''
+        NOTE_OLD
+        **deprecated**: Use note instead. Will be removed in 0.9
+        
+        Writes or displays a note about the current curve.
+        If [anything] is empty, it displays the note, otherwise it adds a note.
+        The note is then saved in the playlist if you issue a savelist command
+        ---------------
+        Syntax: note_old [anything]        
+
+        '''
         if args=='':
             print self.current_list[self.pointer].notes
         else:
@@ -694,6 +711,42 @@ Syntax: note [anything]
             self.current_list[self.pointer].notes=args
         self.notes_saved=0
             
+            
+    def do_note(self,args):
+        '''
+        NOTE
+        
+        Writes or displays a note about the current curve.
+        If [anything] is empty, it displays the note, otherwise it adds a note.
+        The note is then saved in the playlist if you issue a savelist command.
+        ---------------
+        Syntax: note_old [anything]        
+
+        '''
+        if args=='':
+            print self.current_list[self.pointer].notes
+        else:
+            if self.notes_filename == None:
+                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)
+                f.close()
+                
+            #bypass UnicodeDecodeError troubles    
+            try:
+               args=args.decode('ascii')
+            except:
+               args=args.decode('ascii','ignore')
+               if len(args)==0:
+                   args='?'
+            self.current_list[self.pointer].notes=args
+            
+            f=open(self.notes_filename,'a+')
+            note_string=(self.current.path+'  |  '+self.current.notes+'\n')
+            f.write(note_string)
+            f.close()
+                           
     def help_notelog(self):
         print '''
 NOTELOG
@@ -705,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:
@@ -735,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):
@@ -746,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
         ---------
@@ -777,10 +829,6 @@ Syntax copylog [directory]
         else:
             self.outlet.delete(args)
 
-
-
-
-
 #OS INTERACTION COMMANDS
 #-----------------    
     def help_dir(self):
@@ -855,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
@@ -887,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)