source: sasview/calculatorview/perspectives/calculator/detector_editor.py @ 91f151a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 91f151a was 91f151a, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on data editor

  • Property mode set to 100644
File size: 38.7 KB
Line 
1
2import wx
3import sys
4from copy import deepcopy
5from DataLoader.loader import Loader
6from DataLoader.data_info import Detector
7from sans.guiframe.utils import check_float
8_BOX_WIDTH = 60
9
10if sys.platform.count("win32")>0:
11    _STATICBOX_WIDTH = 465
12    PANEL_WIDTH = 500
13    PANEL_HEIGHT = 450
14    FONT_VARIANT = 0
15else:
16    _STATICBOX_WIDTH = 480
17    PANEL_WIDTH = 530
18    PANEL_HEIGHT = 450
19    FONT_VARIANT = 1
20   
21class DetectorDialog(wx.Dialog):
22    def __init__(self, parent=None, id=-1, manager=None, detector=None,
23                        title="Detector Editor",size=(PANEL_WIDTH, PANEL_HEIGHT)):
24        wx.Dialog.__init__(self, parent=parent, id=id, title=title, size=size)
25        try:
26            self.parent = parent
27            self.manager = manager
28            self._detector = detector
29         
30            self._reset_detector = deepcopy(detector)
31            self._notes = ""
32            self._description = "Edit Detector"
33            self._do_layout()
34            self.set_values()
35        except:
36            print "error", sys.exc_value
37           
38    def _define_structure(self):
39        """
40            define initial sizer
41        """
42        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
43        self.box_detector = wx.StaticBox(self, -1,str("Edit Selected Detector"))
44        self.boxsizer_detector = wx.StaticBoxSizer(self.box_detector,
45                                                    wx.VERTICAL)
46        detector_box = wx.StaticBox(self, -1, "Edit Number of Detectors")
47        self.detector_sizer = wx.StaticBoxSizer(detector_box, wx.VERTICAL)
48        self.detector_sizer.SetMinSize((_STATICBOX_WIDTH, -1))
49        self.detector_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
50        self.detector_hint_sizer = wx.BoxSizer(wx.HORIZONTAL)
51       
52        self.detector_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
53        self.detector_hint_sizer = wx.BoxSizer(wx.HORIZONTAL)
54        self.instrument_sizer = wx.BoxSizer(wx.HORIZONTAL)
55        self.distance_sizer = wx.BoxSizer(wx.HORIZONTAL)
56        self.offset_sizer = wx.BoxSizer(wx.HORIZONTAL)
57        self.orientation_sizer = wx.BoxSizer(wx.HORIZONTAL)
58        self.beam_sizer = wx.BoxSizer(wx.HORIZONTAL)
59        self.pixel_sizer = wx.BoxSizer(wx.HORIZONTAL)
60        self.slit_sizer = wx.BoxSizer(wx.HORIZONTAL)
61        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)
62       
63    def _layout_detector(self):
64        """
65            Do the layout for detector related widgets
66        """
67        detector_name_txt = wx.StaticText(self, -1, "Detector:") 
68        hint_detector_txt = 'Current available detector.'
69        detector_name_txt.SetToolTipString(hint_detector_txt) 
70        self.detector_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)
71        hint_detector_name_txt = 'Name of detectors.'
72        self.detector_cbox.SetToolTipString(hint_detector_name_txt) 
73   
74        self.bt_add_detector = wx.Button(self, -1, "Add")
75        self.bt_add_detector.SetToolTipString("Add data's detector.")
76        self.bt_add_detector.Bind(wx.EVT_BUTTON, self.add_detector)
77       
78        self.bt_remove_detector = wx.Button(self, -1, "Remove")
79        self.bt_remove_detector.SetToolTipString("Remove data's detector.")
80        self.bt_remove_detector.Bind(wx.EVT_BUTTON, self.remove_detector)
81     
82        self.detector_button_sizer.AddMany([(detector_name_txt, 0, wx.LEFT, 15),
83                                     (self.detector_cbox, 0, wx.LEFT, 5),
84                                     (self.bt_add_detector, 0, wx.LEFT, 10),
85                                     (self.bt_remove_detector, 0, wx.LEFT, 5)])
86        detector_hint_txt = 'No detector is available for this data.'
87        self.detector_txt = wx.StaticText(self, -1, detector_hint_txt) 
88        self.detector_hint_sizer.Add(self.detector_txt, 0, wx.LEFT, 10)
89        self.detector_sizer.AddMany([(self.detector_button_sizer, 0, wx.ALL, 10),
90                                     (self.detector_hint_sizer, 0, wx.ALL, 10)])
91     
92        self.fill_detector_combox()
93        self.enable_detector()
94       
95    def _layout_instrument_sizer(self):
96        """
97            Do the layout for instrument related widgets
98        """
99        #Instrument
100        instrument_name_txt = wx.StaticText(self, -1, 'Instrument Name : ') 
101        self.instrument_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) 
102        self.instrument_sizer.AddMany([(instrument_name_txt, 0, wx.LEFT|wx.RIGHT, 10),
103                                       (self.instrument_name_tcl, 0, wx.EXPAND)])
104    def _layout_distance(self):
105        """
106            Do the  layout for distance related widgets
107        """
108        distance_txt = wx.StaticText(self, -1, 'Sample to Detector Distance : ') 
109        self.distance_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0)
110        distance_unit_txt = wx.StaticText(self, -1, 'Unit: ') 
111        self.distance_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
112        self.distance_sizer.AddMany([(distance_txt, 0, wx.LEFT|wx.RIGHT, 10),
113                                     (self.distance_tcl, 0, wx.RIGHT, 10),
114                                     (distance_unit_txt, 0, wx.EXPAND),
115                                     (self.distance_unit_tcl, 0, wx.RIGHT, 10)])
116       
117    def _layout_offset(self):
118        """
119            Do the  layout for offset related widgets
120        """
121        #Offset
122        offset_txt = wx.StaticText(self, -1, 'Offset:') 
123        x_offset_txt = wx.StaticText(self, -1, 'x = ') 
124        self.x_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
125        y_offset_txt = wx.StaticText(self, -1, 'y = ') 
126        self.y_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
127        z_offset_txt = wx.StaticText(self, -1, 'z = ') 
128        self.z_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
129        offset_unit_txt = wx.StaticText(self, -1, 'Unit: ') 
130        self.offset_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0)
131        self.offset_sizer.AddMany([(offset_txt, 0, wx.LEFT|wx.RIGHT, 10),
132                                     (x_offset_txt, 0, wx.LEFT, 30),
133                                     (self.x_offset_tcl, 0, wx.RIGHT, 10),
134                                     (y_offset_txt, 0, wx.EXPAND),
135                                     (self.y_offset_tcl, 0, wx.RIGHT, 10),
136                                     (z_offset_txt, 0, wx.EXPAND),
137                                     (self.z_offset_tcl, 0, wx.RIGHT, 10),
138                                     (offset_unit_txt, 0, wx.EXPAND),
139                                     (self.offset_unit_tcl, 0, wx.RIGHT, 10)])
140         
141    def _layout_orientation(self):
142        """
143            Do the  layout for orientation related widgets
144        """
145        #Orientation
146        orientation_txt = wx.StaticText(self, -1, 'Orientation:') 
147        x_orientation_txt = wx.StaticText(self, -1, 'x = ') 
148        self.x_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
149        y_orientation_txt = wx.StaticText(self, -1, 'y = ') 
150        self.y_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
151        z_orientation_txt = wx.StaticText(self, -1, 'z = ') 
152        self.z_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
153        orientation_unit_txt = wx.StaticText(self, -1, 'Unit: ') 
154        self.orientation_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) 
155        self.orientation_sizer.AddMany([(orientation_txt, 0, wx.LEFT|wx.RIGHT, 10),
156                                     (x_orientation_txt, 0, wx.LEFT, 7),
157                                     (self.x_orientation_tcl, 0, wx.RIGHT, 10),
158                                     (y_orientation_txt, 0, wx.EXPAND),
159                                     (self.y_orientation_tcl, 0, wx.RIGHT, 10),
160                                     (z_orientation_txt, 0, wx.EXPAND),
161                                     (self.z_orientation_tcl, 0, wx.RIGHT, 10),
162                                     (orientation_unit_txt, 0, wx.EXPAND),
163                                     (self.orientation_unit_tcl, 0, wx.RIGHT, 10)]) 
164       
165    def _layout_beam_center(self):
166        """
167            Do the  layout for beam center related widgets
168        """
169        #Beam center
170        beam_center_txt = wx.StaticText(self, -1, 'Beam Center:') 
171        x_beam_center_txt = wx.StaticText(self, -1, 'x = ') 
172        self.x_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
173        y_beam_center_txt = wx.StaticText(self, -1, 'y = ') 
174        self.y_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
175        z_beam_center_txt = wx.StaticText(self, -1, 'z = ') 
176        self.z_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 
177        beam_center_unit_txt = wx.StaticText(self, -1, 'Unit: ') 
178        self.beam_center_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0)
179        self.beam_sizer.AddMany([(beam_center_txt, 0, wx.LEFT|wx.RIGHT, 10),
180                                     (x_beam_center_txt, 0, wx.EXPAND),
181                                     (self.x_beam_center_tcl, 0, wx.RIGHT, 10),
182                                     (y_beam_center_txt, 0, wx.EXPAND),
183                                     (self.y_beam_center_tcl, 0, wx.RIGHT, 10),
184                                     (z_beam_center_txt, 0, wx.EXPAND),
185                                     (self.z_beam_center_tcl, 0, wx.RIGHT, 10),
186                                     (beam_center_unit_txt, 0, wx.EXPAND),
187                                     (self.beam_center_unit_tcl, 0,wx.RIGHT, 10)])   
188   
189    def _layout_pixel_size(self):
190        """
191            Do the  layout for pixel size related widgets
192        """
193        #Pixel Size
194        pixel_size_txt = wx.StaticText(self, -1, 'Pixel Size:') 
195        x_pixel_size_txt = wx.StaticText(self, -1, 'x = ') 
196        self.x_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 
197        y_pixel_size_txt = wx.StaticText(self, -1, 'y = ') 
198        self.y_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 
199        z_pixel_size_txt = wx.StaticText(self, -1, 'z = ') 
200        self.z_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 
201        pixel_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') 
202        self.pixel_size_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) 
203        self.pixel_sizer.AddMany([(pixel_size_txt, 0, wx.LEFT|wx.RIGHT, 10),
204                                     (x_pixel_size_txt, 0, wx.LEFT, 17),
205                                     (self.x_pixel_size_tcl, 0, wx.RIGHT, 10),
206                                     (y_pixel_size_txt, 0, wx.EXPAND),
207                                     (self.y_pixel_size_tcl, 0, wx.RIGHT, 10),
208                                     (z_pixel_size_txt, 0, wx.EXPAND),
209                                     (self.z_pixel_size_tcl, 0, wx.RIGHT, 10),
210                                     (pixel_size_unit_txt, 0, wx.EXPAND),
211                                     (self.pixel_size_unit_tcl, 0, wx.RIGHT, 10)])
212   
213    def _layout_slit_length(self):
214        """
215            Do the  layout for slit length related widgets
216        """
217        #slit length
218        slit_length_txt = wx.StaticText(self, -1, 'Slit Length: ') 
219        self.slit_length_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0)
220        slit_length_unit_txt = wx.StaticText(self, -1, 'Unit: ') 
221        self.slit_length_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0)   
222        self.slit_sizer.AddMany([(slit_length_txt, 0, wx.LEFT, 10),
223                                     (self.slit_length_tcl, 0, wx.RIGHT, 10),
224                                     (slit_length_unit_txt, 0, wx.EXPAND),
225                                     (self.slit_length_unit_tcl, 0,wx.RIGHT, 10)])
226       
227    def _layout_button(self): 
228        """
229            Do the layout for the button widgets
230        """ 
231        self.bt_apply = wx.Button(self, -1,'Apply')
232        self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply)
233        self.bt_apply.SetToolTipString("Apply current changes to the detector.")
234        self.bt_cancel = wx.Button(self, -1,'Cancel')
235        self.bt_cancel.SetToolTipString("Cancel current changes.")
236        self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel)
237        self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close')
238        self.bt_close.SetToolTipString("Close window.")
239        self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200),
240                                   (self.bt_cancel, 0, wx.LEFT, 10),
241                                   (self.bt_close, 0, wx.LEFT, 10)])
242       
243    def _do_layout(self, data=None):
244        """
245             Draw the current panel
246        """
247        self._define_structure()
248        self._layout_detector()
249        self._layout_instrument_sizer()
250        self._layout_distance()
251        self._layout_offset()
252        self._layout_orientation()
253        self._layout_beam_center()
254        self._layout_pixel_size()
255        self._layout_slit_length()
256        self._layout_button()
257     
258        self.boxsizer_detector.AddMany([(self.instrument_sizer, 0,
259                                          wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
260                                   (self.distance_sizer, 0,
261                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
262                                   (self.offset_sizer, 0,
263                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
264                                   (self.orientation_sizer, 0,
265                                    wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
266                                   (self.beam_sizer, 0,
267                                    wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
268                                   (self.pixel_sizer, 0,
269                                    wx.EXPAND|wx.TOP|wx.BOTTOM, 5),
270                                   (self.slit_sizer, 0,
271                                     wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
272        self.main_sizer.AddMany([(self.detector_sizer, 0, wx.ALL, 10),
273                                 (self.boxsizer_detector, 0, wx.ALL, 10),
274                                  (self.button_sizer, 0,
275                                    wx.EXPAND|wx.TOP|wx.BOTTOM, 5)])
276       
277        self.SetSizer(self.main_sizer)
278        self.SetAutoLayout(True)
279       
280    def reset_detector(self):
281        """
282            put the default value of the detector back to the current detector
283        """
284        self._detector = deepcopy(self._reset_detector)
285        self.detector_cbox.Clear()
286        self.fill_detector_combox()
287        self.set_values()
288       
289    def set_manager(self, manager):
290        """   
291            Set manager of this window
292        """
293        self.manager = manager
294       
295    def fill_detector_combox(self):
296        """
297            fill the current combobox with the available detector
298        """
299        for detector in self._detector:
300            pos = self.detector_cbox.Append(str(detector.name))
301            self.detector_cbox.SetClientData(pos, detector)
302            self.detector_cbox.SetSelection(pos)
303            self.detector_cbox.SetStringSelection(str(detector.name)) 
304           
305    def reset_detector_combobox(self, edited_detector):
306        """
307            take all edited editor and reset clientdata of detector combo box
308        """
309        for position in range(self.detector_cbox.GetCount()):
310            detector = self.detector_cbox.GetClientData(position)
311            if detector == edited_detector:
312                detector = edited_detector
313                self.detector_cbox.SetString(position, str(detector.name)) 
314                self.detector_cbox.SetClientData(position, detector)
315                self.detector_cbox.SetStringSelection(str(detector.name)) 
316         
317    def add_detector(self, event):
318        """
319            Append empty detector to data's list of detector
320        """
321       
322        if not self.detector_cbox.IsEnabled():
323            self.detector_cbox.Enable()
324        detector = Detector()
325        self._detector.append(detector)
326        position = self.detector_cbox.Append(str(detector.name))
327        self.detector_cbox.SetClientData(position, detector)
328        self.detector_cbox.SetSelection(position) 
329        self.enable_detector() 
330        self.set_values()
331       
332    def remove_detector(self, event):
333        """
334            Remove detector to data's list of detector
335        """
336        if self.detector_cbox.IsEnabled():
337            if self.detector_cbox.GetCount() > 1:
338                position = self.detector_cbox.GetCurrentSelection()
339                detector = self.detector_cbox.GetClientData(position)
340                if detector in self._detector:
341                    self._detector.remove(detector)
342                    self.detector_cbox.Delete(position) 
343                    #set the combo box box the next available item
344                    position = self.detector_cbox.GetCount()
345                    if position > 0:
346                        position -= 1 
347                    self.detector_cbox.SetSelection(position)
348                    self.set_values()
349        #disable or enable the combo box when necessary
350        self.enable_detector()
351       
352    def enable_detector(self):
353        """
354            Enable /disable widgets crelated to detector
355        """
356        if self._detector is not None and self.detector_cbox.GetCount() > 0:
357            self.detector_cbox.Enable()
358            self.bt_remove_detector.Enable()
359            n_detector = self.detector_cbox.GetCount()
360            detector_hint_txt = 'Detectors available: %s '%str(n_detector)
361            if len(self._detector) > 1:
362                self.bt_remove_detector.Enable()
363            else:
364                self.bt_remove_detector.Disable()
365        else:
366            self.detector_cbox.Disable()
367            self.bt_remove_detector.Disable()
368            detector_hint_txt = 'No detector is available for this data.'
369        self.detector_txt.SetLabel(detector_hint_txt)
370           
371    def set_detector(self, detector):
372        """
373            set detector for data
374        """
375        if self._detector is None:
376            return
377        if self._detector:
378            for item in self._detector:
379                if item == detector:
380                    item = detector
381                    self.reset_detector_combobox(edited_detector=detector)
382                    return
383               
384    def get_current_detector(self):
385        """
386        """
387        if not self.detector_cbox.IsEnabled():
388            return None, None, None
389        position = self.detector_cbox.GetSelection() 
390        if position == wx.NOT_FOUND:
391            return None, None, None
392        detector_name = self.detector_cbox.GetStringSelection() 
393        detector = self.detector_cbox.GetClientData(position)
394        return detector, detector_name, position
395   
396    def set_values(self):
397        """
398            take the detector values of the current data and display them
399            through the panel
400        """
401        detector, _, _ = self.get_current_detector()
402        if detector is None:
403            return
404        self.instrument_name_tcl.SetValue(str(detector.name))
405        #Distance
406        distance = detector.distance
407        self.distance_tcl.SetValue(str(distance))
408        self.distance_unit_tcl.SetValue(str(detector.distance_unit))
409        #Offset
410        x, y, z = detector.offset.x, detector.offset.y , detector.offset.z
411        self.x_offset_tcl.SetValue(str(x)) 
412        self.y_offset_tcl.SetValue(str(y)) 
413        self.z_offset_tcl.SetValue(str(z)) 
414        self.offset_unit_tcl.SetValue(str(detector.offset_unit))
415        #Orientation
416        x, y, z = detector.orientation.x, detector.orientation.y, detector.orientation.z
417        self.x_orientation_tcl.SetValue(str(x)) 
418        self.y_orientation_tcl.SetValue(str(y)) 
419        self.z_orientation_tcl.SetValue(str(z)) 
420        self.orientation_unit_tcl.SetValue(str(detector.orientation_unit))
421        #Beam center
422        x, y, z = detector.beam_center.x, detector.beam_center.y, detector.beam_center.z
423        self.x_beam_center_tcl.SetValue(str(x)) 
424        self.y_beam_center_tcl.SetValue(str(y)) 
425        self.z_beam_center_tcl.SetValue(str(z)) 
426        self.beam_center_unit_tcl.SetValue(str(detector.beam_center_unit))
427        #Pixel size
428        x, y, z = detector.pixel_size.x, detector.pixel_size.y, detector.pixel_size.z
429        self.x_pixel_size_tcl.SetValue(str(x)) 
430        self.y_pixel_size_tcl.SetValue(str(y)) 
431        self.z_pixel_size_tcl.SetValue(str(z)) 
432        self.pixel_size_unit_tcl.SetValue(str(detector.pixel_size_unit))
433        #Slit length
434        slit_length = detector.slit_length
435        self.slit_length_tcl.SetValue(str(detector.slit_length))
436        self.slit_length_unit_tcl.SetValue(str(detector.slit_length_unit))
437       
438    def get_detector(self):
439        """
440            return the current detector
441        """
442        return self._detector
443   
444    def get_notes(self):
445        """
446            return notes
447        """
448        return self._notes
449   
450    def on_change_instrument(self):
451        """
452            Change instrument
453        """
454        detector, detector_name, position = self.get_current_detector()
455        if detector is None: 
456            return
457        #Change the name of the detector
458        name = self.instrument_name_tcl.GetValue().lstrip().rstrip()
459        if name == "" or name == str(None):
460            name = None
461        if detector_name != name:
462            self._notes += " Instrument's "
463            self._notes += "name from %s to %s \n"%(detector_name, name)
464            detector.name = name
465            self.detector_cbox.SetString(position, str(detector.name)) 
466            self.detector_cbox.SetClientData(position, detector)
467            self.detector_cbox.SetStringSelection(str(detector.name)) 
468       
469    def on_change_distance(self):
470        """
471            Change distance of the sample to the detector
472        """
473        detector, _, position = self.get_current_detector()
474        if detector is None:
475            return
476        #Change the distance
477        distance = self.distance_tcl.GetValue().lstrip().rstrip()
478        if distance == "" or distance  == str(None):
479            distance = None
480            detector.distance = distance
481        else:
482            if check_float(self.distance_tcl):
483                if detector.distance != float(distance):
484                    self._notes += " Change Distance from"
485                    self._notes += " %s to %s \n"%(detector.distance, distance)
486                    detector.distance = float(distance)
487            else:
488                self._notes += "Error: Expected a float for the distance won't changes "
489                self._notes += "%s to %s"%(detector.distance, distance)
490        #change the distance unit
491        unit = self.distance_unit_tcl.GetValue().lstrip().rstrip()
492        if detector.distance_unit != unit:
493            self._notes += " Change distance's unit from "
494            self._notes += "%s to %s"%(detector.distance_unit, unit)
495           
496        self.detector_cbox.SetString(position, str(detector.name)) 
497        self.detector_cbox.SetClientData(position, detector)
498        self.detector_cbox.SetStringSelection(str(detector.name)) 
499       
500    def on_change_offset(self):
501        """
502            Change the detector offset
503        """
504        detector, _, position = self.get_current_detector()
505        if detector is None:
506            return
507        #Change x coordinate
508        x_offset = self.x_offset_tcl.GetValue().lstrip().rstrip()
509        if x_offset == "" or x_offset == str(None):
510            x_offset = None
511            detector.offset.x = x_offset
512        else:
513            if check_float(self.x_offset_tcl):
514                if detector.offset.x != float(x_offset):
515                    self._notes += "Change x of offset from"
516                    self._notes += " %s to %s \n"%(detector.offset.x, x_offset)
517                    detector.offset.x = float(x_offset)
518            else:
519                self._notes += "Error: Expected a float for the offset 's x "
520                self._notes += "won't changes x offset"
521                self._notes += " from %s to %s"%(detector.offset.x, x_offset)
522        #Change y coordinate
523        y_offset = self.y_offset_tcl.GetValue().lstrip().rstrip()
524        if y_offset == "" or y_offset == str(None):
525            y_offset = None
526            detector.offset.y = y_offset
527        else:
528            if check_float(self.y_offset_tcl):
529                if detector.offset.y != float(y_offset):
530                    self._notes += "Change y of offset from "
531                    self._notes += "%s to %s \n"%(detector.offset.y, y_offset)
532                    detector.offset.y = float(y_offset)
533            else:
534                self._notes += "Error: Expected a float for the offset 's y "
535                self._notes += "won't changes y "
536                self._notes += "offset from %s to %s"%(detector.offset.y\
537                                                         ,y_offset)
538        #Change z coordinate
539        z_offset = self.z_offset_tcl.GetValue().lstrip().rstrip()
540        if z_offset == "" or z_offset == str(None):
541            z_offset = None
542            detector.offset.z = z_offset
543        else:
544            if check_float(self.z_offset_tcl):
545                if detector.offset.z != float(z_offset):
546                    self._notes += "Change z of"
547                    self._notes += "offset from %s to %s \n"%(detector.offset.z,\
548                                                              z_offset)
549                    detector.offset.= float(z_offset)
550            else:
551                self._notes += "Error: Expected a float for the offset 's x "
552                self._notes += "won't changes z"
553                self._notes += "offset from %s to %s"%(detector.offset.z, z_offset)
554        #change the offset unit
555        unit = self.offset_unit_tcl.GetValue().lstrip().rstrip()
556        if detector.offset_unit != unit:
557            self._notes += " Change Offset's"
558            self._notes += "unit from %s to %s"%(detector.offset_unit, unit)
559           
560        self.detector_cbox.SetString(position, str(detector.name)) 
561        self.detector_cbox.SetClientData(position, detector)
562        self.detector_cbox.SetStringSelection(str(detector.name)) 
563       
564    def on_change_orientation(self):
565        """
566            Change the detector orientation
567        """
568        detector, _, position = self.get_current_detector()
569        if detector is None:
570            return
571        #Change x coordinate
572        x_orientation = self.x_orientation_tcl.GetValue().lstrip().rstrip()
573        if x_orientation == "" or x_orientation == str(None):
574            x_orientation = None
575            detector.orientation.x = x_orientation
576        else:
577            if check_float(self.x_orientation_tcl):
578                if detector.orientation.x != float(x_orientation):
579                    self._notes += "Change x of orientation from "
580                    self._notes += "%s to %s \n"%(detector.orientation.x, x_orientation)
581                    detector.orientation.= float(x_orientation)
582            else:
583                self._notes += "Error: Expected a float for the orientation 's x "
584                self._notes += "won't changes x orientation from "
585                self._notes += "%s to %s"%(detector.orientation.x, x_orientation)
586        #Change y coordinate
587        y_orientation = self.y_orientation_tcl.GetValue().lstrip().rstrip()
588        if y_orientation == "" or y_orientation == str(None):
589            y_orientation = None
590            detector.orientation.y = y_orientation
591        else:
592            if check_float(self.y_orientation_tcl):
593                if detector.orientation.y != float(y_orientation):
594                    self._notes += "Change y of orientation from "
595                    self._notes += "%s to %s \n"%(detector.orientation.y, y_orientation)
596                    detector.orientation.= float(y_orientation)
597            else:
598                self._notes += "Error: Expected a float for the orientation's y "
599                self._notes += "won't changes y orientation from "
600                self._notes += "%s to %s"%(detector.orientation.y, y_orientation)
601        #Change z coordinate
602        z_orientation = self.z_orientation_tcl.GetValue().lstrip().rstrip()
603        if z_orientation == "" or z_orientation  == str(None):
604            z_orientation = None
605            detector.orientation.z = z_orientation
606        else:
607            if check_float(self.z_orientation_tcl):
608                if detector.orientation.z != float(z_orientation):
609                    self._notes += "Change z of offset from "
610                    self._notes += "%s to %s \n"%(detector.orientation.z, z_orientation)
611                    detector.orientation.= float(z_orientation)
612            else:
613                self._notes += "Error: Expected a float for the orientation 's x "
614                self._notes += "won't changes z orientation from "
615                self._notes += "%s to %s"%(detector.orientation.z, z_orientation)
616        #change the orientation unit
617        unit = self.orientation_unit_tcl.GetValue().lstrip().rstrip()
618        if detector.orientation_unit != unit:
619            self._notes += " Change orientation's unit from "
620            self._notes += "%s to %s"%(detector.orientation_unit, unit)
621           
622        self.detector_cbox.SetString(position, str(detector.name)) 
623        self.detector_cbox.SetClientData(position, detector)
624        self.detector_cbox.SetStringSelection(str(detector.name)) 
625       
626    def on_change_beam_center(self):
627        """
628            Change the detector beam center
629        """
630       
631        detector, _, position = self.get_current_detector()
632        if detector is None:
633            return
634        #Change x coordinate
635        x_beam_center = self.x_beam_center_tcl.GetValue().lstrip().rstrip()
636        if x_beam_center == "" or x_beam_center == str(None):
637            x_beam_center = None
638            detector.beam_center.x = x_beam_center
639        else:
640            if check_float(self.x_beam_center_tcl):
641                if detector.beam_center.x != float(x_beam_center):
642                    self._notes += "Change x of offset from "
643                    self._notes += "%s to %s \n"%(detector.beam_center.x, x_beam_center)
644                    detector.beam_center.= float(x_beam_center)
645            else:
646                self._notes += "Error: Expected a float for the beam center 's x "
647                self._notes += "won't changes x beam center from "
648                self._notes += "%s to %s"%(detector.beam_center.x, x_beam_center)
649        #Change y coordinate
650        y_beam_center = self.y_beam_center_tcl.GetValue().lstrip().rstrip()
651        if y_beam_center == "" or y_beam_center == str(None):
652            y_beam_center = None
653            detector.beam_center.= y_beam_center
654        else:
655            if check_float(self.y_beam_center_tcl):
656                if detector.beam_center.y != float(y_beam_center):
657                    self._notes += "Change y of beam center from "
658                    self._notes += "%s to %s \n"%(detector.beam_center.y, y_beam_center)
659                    detector.beam_center.= float(y_beam_center)
660            else:
661                self._notes += "Error: Expected a float for the beam center 's y "
662                self._notes += "won't changes y beam center from "
663                self._notes += "%s to %s"%(detector.beam_center.y, y_beam_center)
664        #Change z coordinate
665        z_beam_center = self.z_beam_center_tcl.GetValue().lstrip().rstrip()
666        if z_beam_center == "" or z_beam_center == str(None):
667            z_beam_center = None
668            detector.beam_center.z = z_beam_center
669        else:
670            if check_float(self.z_beam_center_tcl):
671                if detector.beam_center.z != float(z_beam_center):
672                    self._notes += "Change z of beam center from "
673                    self._notes += "%s to %s \n"%(detector.beam_center.z, z_beam_center)
674                    detector.beam_center.= float(z_beam_center)
675            else:
676                self._notes += "Error: Expected a float for the offset 's x "
677                self._notes += "won't changes z beam center from "
678                self._notes += "%s to %s"%(detector.beam_center.z, z_beam_center)
679        #change the beam center unit
680        unit = self.beam_center_unit_tcl.GetValue().lstrip().rstrip()
681        if detector.beam_center_unit != unit:
682            self._notes += " Change beam center's unit from "
683            self._notes += "%s to %s"%(detector.beam_center_unit, unit)
684       
685        self.detector_cbox.SetString(position, str(detector.name)) 
686        self.detector_cbox.SetClientData(position, detector)
687        self.detector_cbox.SetStringSelection(str(detector.name)) 
688       
689    def on_change_pixel_size(self):
690        """
691            Change the detector pixel size
692        """
693        detector, _, position = self.get_current_detector()
694        if detector is None:
695            return
696        #Change x coordinate
697        x_pixel_size = self.x_pixel_size_tcl.GetValue().lstrip().rstrip()
698        if x_pixel_size == "" or x_pixel_size == str(None):
699            x_pixel_size = None
700        else:
701            if check_float(self.x_pixel_size_tcl):
702                if detector.pixel_size.x != float(x_pixel_size) :
703                    self._notes += "Change x of pixel size from "
704                    self._notes += "%s to %s \n"%(detector.pixel_size.x, x_pixel_size)
705                    detector.pixel_size.= float(x_pixel_size)
706            else:
707                self._notes += "Error: Expected a float for the pixel size 's x "
708                self._notes += "won't changes x pixel size from "
709                self._notes += "%s to %s"%(detector.pixel_size.x, x_pixel_size)
710        #Change y coordinate
711        y_pixel_size = self.y_pixel_size_tcl.GetValue().lstrip().rstrip()
712        if y_pixel_size == "" or y_pixel_size == str(None):
713            y_pixel_size = None
714            detector.pixel_size.y = y_pixel_size
715        else:
716            if check_float(self.y_pixel_size_tcl):
717                if detector.pixel_size.y != float(y_pixel_size):
718                    self._notes += "Change y of pixel size from "
719                    self._notes += "%s to %s \n"%(detector.pixel_size.y, y_pixel_size)
720                    detector.pixel_size.= float(y_pixel_size)
721            else:
722                self._notes += "Error: Expected a float for the pixel size's y "
723                self._notes += "won't changes y pixel size from "
724                self._notes += "%s to %s"%(detector.pixel_size.y, y_pixel_size)
725        #Change z coordinate
726        z_pixel_size = self.z_pixel_size_tcl.GetValue().lstrip().rstrip()
727        if z_pixel_size == "" or z_pixel_size == str(None):
728            z_pixel_size = None
729            detector.pixel_size.z = z_pixel_size
730        else:
731            if check_float(self.z_pixel_size_tcl):
732                if detector.pixel_size.z != float(z_pixel_size):
733                    self._notes += "Change z of pixel size from "
734                    self._notes += "%s to %s \n"%(detector.pixel_size.z, z_pixel_size)
735                    detector.pixel_size.= float(z_pixel_size)
736            else:
737                self._notes += "Error: Expected a float for the offset 's x "
738                self._notes += "won't changes z pixel size from "
739                self._notes += "%s to %s"%(detector.pixel_size.z, z_pixel_size)
740        #change the beam center unit
741        unit = self.pixel_size_unit_tcl.GetValue().lstrip().rstrip()
742        if detector.pixel_size_unit != unit:
743            self._notes += " Change pixel size's unit from "
744            self._notes += "%s to %s"%(detector.pixel_size_unit, unit)
745           
746        self.detector_cbox.SetString(position, str(detector.name)) 
747        self.detector_cbox.SetClientData(position, detector)
748        self.detector_cbox.SetStringSelection(str(detector.name)) 
749           
750    def on_change_slit_length(self):
751        """
752            Change slit length of the detector
753        """
754        detector, _, position = self.get_current_detector()
755        if detector is None:
756            return
757        #Change the distance
758        slit_length = self.slit_length_tcl.GetValue().lstrip().rstrip()
759        if slit_length == "" or slit_length == str(None):
760            slit_length = None
761            detector.slit_length = slit_length
762        else:
763            if check_float(self.slit_length_tcl):
764                if detector.slit_length != float(slit_length):
765                    self._notes += " Change slit length from"
766                    self._notes += " %s to %s \n"%(detector.slit_length, slit_length)
767                    detector.slit_length = float(slit_length)
768            else:
769                self._notes += "Error: Expected a float for the slit length won't changes "
770                self._notes += "%s to %s"%(detector.slit_length, slit_length)
771        #change the distance unit
772        unit = self.slit_length_unit_tcl.GetValue().lstrip().rstrip()
773        if detector.slit_length_unit != unit:
774            self._notes += " Change slit length's unit from "
775            self._notes += "%s to %s"%(detector.slit_length_unit_tcl, unit) 
776           
777        self.detector_cbox.SetString(position, str(detector.name)) 
778        self.detector_cbox.SetClientData(position, detector)
779        self.detector_cbox.SetStringSelection(str(detector.name)) 
780           
781    def on_click_cancel(self, event):
782        """
783            reset the current detector to its initial values
784        """
785        self.reset_detector()
786        self.set_values()
787        if self.manager is not None:
788             self.manager.set_detector(self._detector)
789             
790    def on_click_apply(self, event):
791        """
792            Apply user values to the detector
793        """
794        self.on_change_instrument()
795        self.on_change_distance()
796        self.on_change_instrument()
797        self.on_change_beam_center()
798        self.on_change_offset()
799        self.on_change_orientation()
800        self.on_change_pixel_size()
801        self.on_change_slit_length()
802        for detector in self._detector:
803            self.manager.set_detector(self._detector, self._notes)
804           
805if __name__ == "__main__":
806    app = wx.App()
807    # Instantiate a loader
808    loader = Loader()
809    # Load data
810    output = loader.load("MAR07232_rest.ASC")
811    dlg = DetectorDialog(detector=output.detector)
812    dlg.ShowModal()
813    app.MainLoop()
814 
Note: See TracBrowser for help on using the repository browser.