1 class HookeCli(cmd.Cmd, object):
3 def __init__(self,frame,list_of_events,events_from_gui,config,drivers):
6 self.prompt = 'hooke: '
7 self.current_list=[] #the playlist we're using
8 self.current=None #the current curve under analysis.
11 The actual hierarchy of the "current curve" is a bit complex:
13 self.current = the lhc.HookeCurve container object of the current curve
14 self.current.curve = the current "real" curve object as defined in the filetype driver class
15 self.current.curve.default_plots() = the default plots of the filetype driver.
17 The plot objects obtained by mean of self.current.curve.default_plots()
18 then undergoes modifications by the plotmanip
19 modifier functions. The modified plot is saved in self.plots and used if needed by other functions.
21 self.pointer=0 #a pointer to navigate the current list
23 #Things that come from outside
24 self.frame=frame #the wx frame we refer to
25 self.list_of_events=list_of_events #a list of wx events we use to interact with the GUI
26 self.events_from_gui=events_from_gui #the Queue object we use to have messages from the GUI
27 self.config=config #the configuration dictionary
28 self.drivers=drivers #the file format drivers
30 #get plot manipulation functions
31 plotmanip_functions=[]
32 for object_name in dir(self):
33 if object_name[0:9]=='plotmanip':
34 plotmanip_functions.append(getattr(self,object_name))
35 #put plotmanips in order
36 self.plotmanip=[None for item in self.config['plotmanips']]
37 for item in plotmanip_functions:
38 namefunction=item.__name__[10:]
39 if namefunction in self.config['plotmanips']:
40 nameindex=self.config['plotmanips'].index(namefunction) #index of function in plotmanips config
41 self.plotmanip[nameindex] = item
46 self.playlist_saved=0 #Did we save the playlist?
47 self.playlist_name='' #Name of playlist
48 self.notes_saved=1 #Did we save the notes?
49 self.notes_filename=None #Name of notes
52 self.outlet=lout.Outlet()
54 #Data that must be saved in the playlist, related to the whole playlist (not individual curves)
55 self.playlist_generics={}
57 #make sure we execute _plug_init() for every command line plugin we import
58 for plugin_name in self.config['plugins']:
60 plugin=__import__(plugin_name)
62 eval('plugin.'+plugin_name+'Commands._plug_init(self)')
63 except AttributeError:
68 #load default list, if possible
69 self.do_loadlist(self.config['defaultlist'])
72 #Everything sending an event should be here
73 def _measure_N_points(self, N, whatset=1):
75 general helper function for N-points measures
77 wx.PostEvent(self.frame,self.list_of_events['measure_points'](num_of_points=N, set=whatset))
80 points=self.frame.events_from_gui.get()
86 def _get_displayed_plot(self,dest=0):
88 returns the currently displayed plot.
90 wx.PostEvent(self.frame, self.list_of_events['get_displayed_plot'](dest=dest))
93 displayed_plot=self.events_from_gui.get()
100 def _send_plot(self,plots):
102 sends a plot to the GUI
104 wx.PostEvent(self.frame, self.list_of_events['plot_graph'](plots=plots))
107 def _find_plotmanip(self, name):
109 returns a plot manipulator function from its name
111 return self.plotmanip[self.config['plotmanips'].index(name)]
113 def _clickize(self, xvector, yvector, index):
115 returns a ClickedPoint() object from an index and vectors of x, y coordinates
119 point.absolute_coords=xvector[index],yvector[index]
120 point.find_graph_coords(xvector,yvector)
128 Sets a local configuration variable
130 Syntax: set [variable] [value]
132 def do_set(self,args):
133 #FIXME: some variables in self.config should be hidden or intelligently configurated...
136 print 'You must specify a variable and a value'
137 print 'Available variables:'
138 print self.config.keys()
140 if args[0] not in self.config.keys():
141 print 'This is not an internal Hooke variable!'
144 #FIXME:we should reload the config file and reset the config value
145 print self.config[args[0]]
148 try: #try to have a numeric value
150 except ValueError: #if it cannot be converted to float, it's None, or a string...
152 if value.lower()=='none':
157 self.config[key]=value
160 def help_printlist(self):
163 Prints the list of curves in the current playlist
167 def do_printlist(self,args):
168 for item in self.current_list:
175 Jumps to a given curve.
177 Syntax: jump {$curve}
179 If the curve is not in the current playlist, it politely asks if we want to add it.
181 def do_jump(self,filename):
183 jumps to the curve with the given filename.
184 if the filename is not in the playlist, it asks if we must add it or not.
188 filename=linp.safeinput('Jump to?')
190 filepath=os.path.abspath(filename)
195 while item_not_found:
198 if self.current_list[c].path == filepath:
200 self.current=self.current_list[self.pointer]
206 #We've found the end of the list.
207 answer=linp.safeinput('Curve not found in playlist. Add it to list?',['y'])
208 if answer.lower()[0]=='y':
210 self.do_addtolist(filepath)
212 print 'Curve file not found.'
214 self.current=self.current_list[-1]
215 self.pointer=(len(current_list)-1)
221 def do_index(self,args):
224 Prints the index of the current curve in the list
228 print self.pointer+1, 'of', len(self.current_list)
234 Go the next curve in the playlist.
235 If we are at the last curve, we come back to the first.
239 def do_next(self,args):
241 self.current.curve.close_all()
243 print 'No curve file loaded, currently!'
244 print 'This should not happen, report to http://code.google.com/p/hooke'
247 if self.pointer == (len(self.current_list)-1):
249 print 'Playlist finished; back to first curve.'
253 self.current=self.current_list[self.pointer]
262 def help_previous(self,args):
265 Go to the previous curve in the playlist.
266 If we are at the first curve, we jump to the last.
270 def do_previous(self,args):
272 self.current.curve.close_all()
274 print 'No curve file loaded, currently!'
275 print 'This should not happen, report to http://code.google.com/p/hooke'
277 if self.pointer == 0:
278 self.pointer=(len(self.current_list)-1)
279 print 'Start of playlist; jump to last curve.'
283 self.current=self.current_list[self.pointer]
290 self.do_previous(args)