Moved txt command from hooke_cli -> hooke.plugin.curvetools stub.
authorW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 18:51:11 +0000 (14:51 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 18:51:11 +0000 (14:51 -0400)
hooke/hooke_cli.py
hooke/plugin/curvetools.py

index dac1cdc7d539988bc8758abb72222d3bff7436b2..2930abfc086a18181c0278e4954a2a0ab36f79ff 100644 (file)
@@ -434,60 +434,3 @@ If you have a multiple plot, the optional plot to export argument tells Hooke wh
         wx.PostEvent(self.frame, export_image(name=name, dest=dest))
 
 
-    def help_txt(self):
-        print '''
-TXT
-Saves the current curve as a text file
-Columns are, in order:
-X1 , Y1 , X2 , Y2 , X3 , Y3 ...
-
--------------
-Syntax: txt [filename] {plot to export}
-        '''
-    def do_txt(self,args):
-
-        def transposed2(lists, defval=0):
-            '''
-            transposes a list of lists, i.e. from [[a,b,c],[x,y,z]] to [[a,x],[b,y],[c,z]] without losing
-            elements
-            (by Zoran Isailovski on the Python Cookbook online)
-            '''
-            if not lists: return []
-            return map(lambda *row: [elem or defval for elem in row], *lists)
-
-        whichplot=0
-        args=args.split()
-        if len(args)==0:
-            filename=linp.safeinput('Filename?',[self.current.path+'.txt'])
-        else:
-            filename=linp.checkalphainput(args[0],self.current.path+'.txt',[])
-            try:
-                whichplot=int(args[1])
-            except:
-                pass
-
-       try:
-            outofplot=self.plots[whichplot].vectors
-        except:
-            print "Plot index out of range."
-           return 0
-
-        columns=[]     
-        for dataset in self.plots[whichplot].vectors:
-            for i in range(0,len(dataset)):
-                columns.append([])
-                for value in dataset[i]:
-                    columns[-1].append(str(value))
-
-        rows=transposed2(columns, 'nan')
-        rows=[' , '.join(item) for item in rows]
-        text='\n'.join(rows)
-
-        txtfile=open(filename,'w+')
-        #Save units of measure in header
-        txtfile.write('X:'+self.plots[whichplot].units[0]+'\n')
-        txtfile.write('Y:'+self.plots[whichplot].units[1]+'\n')
-        txtfile.write(text)
-        txtfile.close()
-
-
index 088e48ef52a290252d7fc39161160c71f4c087d4..f760cb8a2ded7f93e1c8cd92dca11d6781cc3bc6 100755 (executable)
@@ -133,3 +133,60 @@ Syntax: current
         '''
     def do_current(self,args):
         print self.current.path
+
+
+    def help_txt(self):
+        print '''
+TXT
+Saves the current curve as a text file
+Columns are, in order:
+X1 , Y1 , X2 , Y2 , X3 , Y3 ...
+
+-------------
+Syntax: txt [filename] {plot to export}
+        '''
+    def do_txt(self,args):
+
+        def transposed2(lists, defval=0):
+            '''
+            transposes a list of lists, i.e. from [[a,b,c],[x,y,z]] to [[a,x],[b,y],[c,z]] without losing
+            elements
+            (by Zoran Isailovski on the Python Cookbook online)
+            '''
+            if not lists: return []
+            return map(lambda *row: [elem or defval for elem in row], *lists)
+
+        whichplot=0
+        args=args.split()
+        if len(args)==0:
+            filename=linp.safeinput('Filename?',[self.current.path+'.txt'])
+        else:
+            filename=linp.checkalphainput(args[0],self.current.path+'.txt',[])
+            try:
+                whichplot=int(args[1])
+            except:
+                pass
+
+       try:
+            outofplot=self.plots[whichplot].vectors
+        except:
+            print "Plot index out of range."
+           return 0
+
+        columns=[]     
+        for dataset in self.plots[whichplot].vectors:
+            for i in range(0,len(dataset)):
+                columns.append([])
+                for value in dataset[i]:
+                    columns[-1].append(str(value))
+
+        rows=transposed2(columns, 'nan')
+        rows=[' , '.join(item) for item in rows]
+        text='\n'.join(rows)
+
+        txtfile=open(filename,'w+')
+        #Save units of measure in header
+        txtfile.write('X:'+self.plots[whichplot].units[0]+'\n')
+        txtfile.write('Y:'+self.plots[whichplot].units[1]+'\n')
+        txtfile.write(text)
+        txtfile.close()