1717import project .widgets as pw
1818import project .project_globals as g
1919
20- main_dir = g .main_dir .read ()
21- ini = project .ini_handler .Ini (os .path .join (main_dir , 'autonomic' , 'coset.ini' ))
22- ini .return_raw = True
23-
24- #hardwares (also ensure present in GUI)
20+ # hardwares (also ensure present in GUI)
2521import hardware .opas .opas as opas
2622import hardware .spectrometers .spectrometers as spectrometers
2723import hardware .delays .delays as delays
2824import hardware .filters .filters as filters
2925all_hardwares = opas .hardwares + spectrometers .hardwares + delays .hardwares + filters .hardwares
3026
27+ main_dir = g .main_dir .read ()
28+ ini = project .ini_handler .Ini (os .path .join (main_dir , 'autonomic' , 'coset.ini' ))
29+ ini .return_raw = True
30+
3131# ensure that all elements are in the ini file
3232all_hardware_names = [hw .name for hw in all_hardwares ]
3333ini .config .read (ini .filepath )
4444 if not ini .config .has_option (section , option ):
4545 ini .write (section , option , None )
4646 ini .write (section , option + ' offset' , 0. )
47-
4847
4948
5049### objects ###################################################################
5150
5251
5352class Corr :
54-
53+
5554 def __init__ (self , path ):
5655 self .path = path
5756 # headers
@@ -92,16 +91,17 @@ def evaluate(self):
9291 '''
9392 control_position = self .control_hardware .get_destination (self .control_units )
9493 # coerce control position to be within control_points array
95- control_position = np .clip (control_position , self .control_points .min (), self .control_points .max ())
94+ control_position = np .clip (
95+ control_position , self .control_points .min (), self .control_points .max ())
9696 out = self .function (control_position )
9797 return out
98-
98+
9999 def interpolate (self ):
100100 '''
101101 Generate interpolation function.
102102 '''
103103 self .function = scipy .interpolate .interp1d (self .control_points , self .offset_points )
104-
104+
105105 def zero (self ):
106106 '''
107107 Zero based on current positions.
@@ -113,7 +113,7 @@ def zero(self):
113113
114114
115115class CoSetHW :
116-
116+
117117 def __init__ (self , hardware ):
118118 self .hardware = hardware
119119 # directly write stored offset to hardware
@@ -141,7 +141,7 @@ def __init__(self, hardware):
141141 # initialize
142142 self .update_display ()
143143 self .update_use_bool ()
144-
144+
145145 def add_table_row (self , corr ):
146146 # insert into table
147147 new_row_index = self .table .rowCount ()
@@ -216,18 +216,19 @@ def create_frame(self, layout):
216216 self .table .setColumnWidth (1 , 100 )
217217 self .table .horizontalHeader ().setStretchLastSection (True )
218218 settings_layout .addWidget (self .table )
219-
219+
220220 def launch (self ):
221221 '''
222222 Apply offsets.
223223 '''
224224 if self .use_bool .read ():
225- corr_results = [corr .evaluate () for corr in self .corrs ]
225+ corr_results = [wt .units .converter (
226+ corr .evaluate (), corr .offset_units , self .hardware .native_units ) for corr in self .corrs ]
226227 new_offset = np .sum (corr_results )
227228 if g .hardware_initialized .read ():
228229 self .hardware .set_offset (new_offset , self .hardware .native_units )
229230 ini .write (self .hardware .name , 'offset' , new_offset )
230-
231+
231232 def load_file (self , path ):
232233 '''
233234 Load a file.
@@ -238,7 +239,7 @@ def load_file(self, path):
238239 self .update_combobox ()
239240 self .update_use_bool ()
240241 return corr
241-
242+
242243 def on_add_file (self ):
243244 '''
244245 Add a file through file dialog.
@@ -262,15 +263,18 @@ def on_add_file(self):
262263 self .load_file (path )
263264 ini .write (self .hardware .name , corr .control_name , corr .path , with_apostrophe = True )
264265 self .display_combobox .write (corr .control_name )
265-
266+
266267 def on_remove_file (self , row ):
267268 '''
268269 Fires when one of the REMOVE buttons gets pushed.
269270 '''
270271 # get row as int (given as QVariant)
271- row = row .toInt ()[0 ]
272+ try :
273+ row = row .toInt ()[0 ]
274+ except AttributeError :
275+ pass # already an int?
272276 self .unload_file (row )
273-
277+
274278 def on_toggle_use (self ):
275279 ini .write (self .hardware .name , 'use' , self .use_bool .read ())
276280 if self .use_bool .read ():
@@ -279,7 +283,7 @@ def on_toggle_use(self):
279283 if g .hardware_initialized .read ():
280284 self .hardware .set_offset (0. , self .hardware .native_units )
281285 ini .write (self .hardware .name , 'offset' , 0. )
282-
286+
283287 def unload_file (self , index ):
284288 removed_corr = self .corrs .pop (index )
285289 ini .write (self .hardware .name , removed_corr .headers ['control' ], None )
@@ -300,14 +304,14 @@ def update_combobox(self):
300304 allowed_values = [corr .headers ['control' ] for corr in self .corrs ]
301305 self .display_combobox .set_allowed_values (allowed_values )
302306 self .update_display ()
303-
307+
304308 def update_use_bool (self ):
305309 if len (self .corrs ) == 0 :
306310 self .use_bool .write (False )
307311 self .use_bool .set_disabled (True )
308312 else :
309313 self .use_bool .set_disabled (False )
310-
314+
311315 def update_display (self ):
312316 if len (self .corrs ) > 0 :
313317 corr = self .corrs [self .display_combobox .read_index ()]
@@ -319,9 +323,9 @@ def update_display(self):
319323 self .plot_scatter .clear ()
320324 self .plot_scatter .setData (xi , yi )
321325 else :
322- # this doesn't work as expected, but that isn't crucial right now
326+ # this doesn't work as expected, but that isn't crucial right now
323327 # - Blaise 2015.10.24
324- self .plot_widget .set_labels ('' , '' )
328+ self .plot_widget .set_labels ('' , '' )
325329 self .plot_scatter .clear ()
326330 self .plot_widget .update ()
327331 self .plot_scatter .update ()
@@ -339,21 +343,22 @@ def zero(self):
339343 self .launch ()
340344 self .update_display ()
341345
346+
342347coset_hardwares = [] # list to contain all coset hardware objects
343348
344349
345350### control ###################################################################
346351
347352
348353class Control ():
349-
354+
350355 def __init__ (self ):
351356 pass
352-
357+
353358 def launch (self ):
354359 for coset_hardware in coset_hardwares :
355360 coset_hardware .launch ()
356-
361+
357362 def zero (self , hardware_name ):
358363 '''
359364 Offsets to zero forr all corrs based on current positions.
@@ -362,7 +367,8 @@ def zero(self, hardware_name):
362367 if coset_harware .hardware .name == hardware_name :
363368 coset_harware .zero ()
364369 break
365-
370+
371+
366372control = Control ()
367373g .hardware_waits .give_coset_control (control )
368374g .coset_control .write (control )
@@ -375,7 +381,7 @@ class GUI(QtCore.QObject):
375381 def __init__ (self ):
376382 QtCore .QObject .__init__ (self )
377383 self .create_frame ()
378-
384+
379385 def create_frame (self ):
380386 # get parent layout
381387 parent_widget = g .coset_widget .read ()
@@ -397,7 +403,7 @@ def create_frame(self):
397403 if len (filters .hardwares ) > 0 :
398404 self .create_hardware_frame ('Filters' , filters .hardwares )
399405 parent_layout .addWidget (self .tabs )
400-
406+
401407 def create_hardware_frame (self , name , hardwares ):
402408 container_widget = QtGui .QWidget ()
403409 container_box = QtGui .QHBoxLayout ()
@@ -411,7 +417,8 @@ def create_hardware_frame(self, name, hardwares):
411417 coset_hardware = CoSetHW (hardware )
412418 coset_hardwares .append (coset_hardware )
413419 tabs .addTab (coset_hardware .widget , hardware .name )
414-
420+
421+
415422gui = GUI ()
416423
417424
0 commit comments