From ae51481aed853483c7db47bbb7ddcc1b48670d8a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 12 May 2010 14:51:11 -0400 Subject: [PATCH] Moved txt command from hooke_cli -> hooke.plugin.curvetools stub. --- hooke/hooke_cli.py | 57 -------------------------------------- hooke/plugin/curvetools.py | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/hooke/hooke_cli.py b/hooke/hooke_cli.py index dac1cdc..2930abf 100644 --- a/hooke/hooke_cli.py +++ b/hooke/hooke_cli.py @@ -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() - - diff --git a/hooke/plugin/curvetools.py b/hooke/plugin/curvetools.py index 088e48e..f760cb8 100755 --- a/hooke/plugin/curvetools.py +++ b/hooke/plugin/curvetools.py @@ -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() -- 2.26.2