source: sasview/src/sas/perspectives/calculator/collimation_editor.py @ db46d13

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 db46d13 was 49ab5d7, checked in by Doucet, Mathieu <doucetm@…>, 10 years ago

Take care of white spaces (pylint)

  • Property mode set to 100644
File size: 22.7 KB
RevLine 
[b0ab6cb]1"""
2"""
[91f151a]3import wx
4import sys
5from copy import deepcopy
[79492222]6from sas.dataloader.loader import Loader
7from sas.dataloader.data_info import Aperture, Collimation
[91f151a]8from aperture_editor import ApertureDialog
9
[79492222]10from sas.guiframe.utils import check_float
[91f151a]11_BOX_WIDTH = 60
12
[49ab5d7]13if sys.platform.count("win32") > 0:
[ad6f597]14    _STATICBOX_WIDTH = 500
[91f151a]15    PANEL_WIDTH = 530
16    PANEL_HEIGHT = 430
17    FONT_VARIANT = 0
18else:
[ad6f597]19    _STATICBOX_WIDTH = 550
[91f151a]20    PANEL_WIDTH = 600
21    PANEL_HEIGHT = 480
22    FONT_VARIANT = 1
[49ab5d7]23
[91f151a]24class CollimationDialog(wx.Dialog):
[6137b150]25    """
26    """
[91f151a]27    def __init__(self, parent=None, manager=None,
28                 collimation=[], *args, **kwds):
[ad6f597]29        """
30        """
[b0ab6cb]31        kwds['size'] = (PANEL_WIDTH, PANEL_HEIGHT)
[ad6f597]32        kwds['title'] = "Collimation Editor"
33        wx.Dialog.__init__(self, parent=parent, *args, **kwds)
34        self.parent = parent
[49ab5d7]35        self.manager = manager
[ad6f597]36        self._collimation = collimation
37        self._reset_collimation = deepcopy(collimation)
38        self._notes = ""
39        self._description = "Edit collimation"
[b0ab6cb]40        #layout attributes
41        self.main_sizer = None
42        self.box_collimation = None
43        self.boxsizer_collimation = None
[49ab5d7]44
45
[ad6f597]46        self._do_layout()
47        self.set_values()
[49ab5d7]48
[91f151a]49    def _define_structure(self):
50        """
[49ab5d7]51        define initial sizer
[91f151a]52        """
53        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
[b0ab6cb]54        self.box_collimation = wx.StaticBox(self, -1,
55                                            str("Edit Selected Collimation"))
56        self.boxsizer_collimation = wx.StaticBoxSizer(self.box_collimation,
57                                                       wx.VERTICAL)
[49ab5d7]58
[91f151a]59        collimation_box = wx.StaticBox(self, -1, "Edit Number of Collimations")
60        self.collimation_sizer = wx.StaticBoxSizer(collimation_box, wx.VERTICAL)
[ad6f597]61        self.collimation_sizer.SetMinSize((_STATICBOX_WIDTH, -1))
[91f151a]62        self.collimation_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
63        self.collimation_hint_sizer = wx.BoxSizer(wx.HORIZONTAL)
[49ab5d7]64
[91f151a]65        self.name_sizer = wx.BoxSizer(wx.HORIZONTAL)
66        self.length_sizer = wx.BoxSizer(wx.HORIZONTAL)
67        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL)
[49ab5d7]68
[91f151a]69        aperture_box = wx.StaticBox(self, -1, "Edit Aperture")
70        self.aperture_sizer = wx.StaticBoxSizer(aperture_box, wx.VERTICAL)
71        self.aperture_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
72        self.aperture_hint_sizer = wx.BoxSizer(wx.HORIZONTAL)
[49ab5d7]73
[91f151a]74    def _layout_collimation(self):
75        """
[6137b150]76        Do the layout for collimation related widgets
[91f151a]77        """
[49ab5d7]78        collimation_name_txt = wx.StaticText(self, -1, "Collimation:")
[91f151a]79        hint_collimation_txt = 'Current available collimation.'
[49ab5d7]80        collimation_name_txt.SetToolTipString(hint_collimation_txt)
[91f151a]81        self.collimation_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)
[49ab5d7]82        wx.EVT_COMBOBOX(self.collimation_cbox, -1, self.on_select_collimation)
[91f151a]83        hint_collimation_name_txt = 'Name of collimations.'
[49ab5d7]84        self.collimation_cbox.SetToolTipString(hint_collimation_name_txt)
85
[91f151a]86        self.bt_add_collimation = wx.Button(self, -1, "Add")
87        self.bt_add_collimation.SetToolTipString("Edit data's collimation.")
88        self.bt_add_collimation.Bind(wx.EVT_BUTTON, self.add_collimation)
[49ab5d7]89
[91f151a]90        self.bt_remove_collimation = wx.Button(self, -1, "Remove")
[b0ab6cb]91        hint = "Remove data's collimation."
92        self.bt_remove_collimation.SetToolTipString(hint)
[91f151a]93        self.bt_remove_collimation.Bind(wx.EVT_BUTTON, self.remove_collimation)
[49ab5d7]94
[b0ab6cb]95        self.collimation_button_sizer.AddMany([(collimation_name_txt, 0,
96                                                 wx.LEFT, 15),
[91f151a]97                                     (self.collimation_cbox, 0, wx.LEFT, 5),
98                                     (self.bt_add_collimation, 0, wx.LEFT, 10),
[b0ab6cb]99                                     (self.bt_remove_collimation,
100                                       0, wx.LEFT, 5)])
[91f151a]101        collimation_hint_txt = 'No collimation is available for this data.'
[49ab5d7]102        self.collimation_txt = wx.StaticText(self, -1, collimation_hint_txt)
[91f151a]103        self.collimation_hint_sizer.Add(self.collimation_txt, 0, wx.LEFT, 10)
[b0ab6cb]104        self.collimation_sizer.AddMany([(self.collimation_button_sizer,
105                                          0, wx.ALL, 10),
106                                     (self.collimation_hint_sizer,
107                                       0, wx.ALL, 10)])
[49ab5d7]108
[91f151a]109        self.fill_collimation_combox()
110        self.enable_collimation()
[49ab5d7]111
[91f151a]112
113    def _layout_name(self):
114        """
[6137b150]115        Do the layout for collimation name related widgets
[91f151a]116        """
117        #Collimation name [string]
[49ab5d7]118        name_txt = wx.StaticText(self, -1, 'Name : ')
119        self.name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH * 5, 20), style=0)
120        self.name_sizer.AddMany([(name_txt, 0, wx.LEFT | wx.RIGHT, 10),
[91f151a]121                                       (self.name_tcl, 0, wx.EXPAND)])
[49ab5d7]122
[91f151a]123    def _layout_length(self):
124        """
[6137b150]125        Do the  layout for length related widgets
[91f151a]126        """
127        #Collimation length
[49ab5d7]128        length_txt = wx.StaticText(self, -1, 'Length:')
129        self.length_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0)
130        length_unit_txt = wx.StaticText(self, -1, 'Unit: ')
[b0ab6cb]131        self.length_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),
[49ab5d7]132                                           style=0)
133        self.length_sizer.AddMany([(length_txt, 0, wx.LEFT | wx.RIGHT, 10),
[91f151a]134                                     (self.length_tcl, 0, wx.LEFT, 12),
[49ab5d7]135                                     (length_unit_txt, 0, wx.LEFT | wx.RIGHT, 10),
136                                     (self.length_unit_tcl, 0, wx.EXPAND)])
137
138    def _layout_button(self):
[91f151a]139        """
[6137b150]140        Do the layout for the button widgets
[49ab5d7]141        """
142        self.bt_apply = wx.Button(self, -1, 'Apply')
[91f151a]143        self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply)
144        self.bt_apply.SetToolTipString("Apply current changes to collimation.")
[49ab5d7]145        self.bt_cancel = wx.Button(self, -1, 'Cancel')
[91f151a]146        self.bt_cancel.SetToolTipString("Cancel current changes.")
147        self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel)
[49ab5d7]148        self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close')
[91f151a]149        self.bt_close.SetToolTipString("Close window.")
150        self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200),
151                                   (self.bt_cancel, 0, wx.LEFT, 10),
152                                   (self.bt_close, 0, wx.LEFT, 10)])
153    def _layout_aperture(self):
154        """
[6137b150]155        Do the layout for aperture related widgets
[91f151a]156        """
[49ab5d7]157        aperture_name_txt = wx.StaticText(self, -1, "Aperture:")
[91f151a]158        hint_aperture_txt = 'Current available aperture.'
[49ab5d7]159        aperture_name_txt.SetToolTipString(hint_aperture_txt)
[91f151a]160        self.aperture_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)
161        hint_aperture_name_txt = 'Name of apertures.'
[49ab5d7]162        self.aperture_cbox.SetToolTipString(hint_aperture_name_txt)
163
[91f151a]164        self.bt_add_aperture = wx.Button(self, -1, "Add")
165        self.bt_add_aperture.SetToolTipString("Edit data's aperture.")
166        self.bt_add_aperture.Bind(wx.EVT_BUTTON, self.add_aperture)
167        self.bt_edit_aperture = wx.Button(self, -1, "Edit")
168        self.bt_edit_aperture.SetToolTipString("Edit data's aperture.")
169        self.bt_edit_aperture.Bind(wx.EVT_BUTTON, self.edit_aperture)
170        self.bt_remove_aperture = wx.Button(self, -1, "Remove")
171        self.bt_remove_aperture.SetToolTipString("Remove data's aperture.")
172        self.bt_remove_aperture.Bind(wx.EVT_BUTTON, self.remove_aperture)
[49ab5d7]173
[91f151a]174        self.aperture_button_sizer.AddMany([(aperture_name_txt, 0, wx.LEFT, 15),
175                                     (self.aperture_cbox, 0, wx.LEFT, 5),
176                                     (self.bt_add_aperture, 0, wx.LEFT, 10),
177                                     (self.bt_edit_aperture, 0, wx.LEFT, 5),
178                                     (self.bt_remove_aperture, 0, wx.LEFT, 5)])
179        aperture_hint_txt = 'No aperture is available for this data.'
[49ab5d7]180        self.aperture_txt = wx.StaticText(self, -1, aperture_hint_txt)
[91f151a]181        self.aperture_hint_sizer.Add(self.aperture_txt, 0, wx.LEFT, 10)
[b0ab6cb]182        self.aperture_sizer.AddMany([(self.aperture_button_sizer,
183                                       0, wx.ALL, 10),
[91f151a]184                                     (self.aperture_hint_sizer, 0, wx.ALL, 10)])
185        self.fill_aperture_combox()
186        self.enable_aperture()
[49ab5d7]187
[b0ab6cb]188    def _do_layout(self):
[91f151a]189        """
[6137b150]190        Draw the current panel
[91f151a]191        """
192        self._define_structure()
193        self._layout_collimation()
194        self._layout_name()
195        self._layout_length()
196        self._layout_aperture()
197        self._layout_button()
[49ab5d7]198
[91f151a]199        self.boxsizer_collimation.AddMany([(self.name_sizer, 0,
[49ab5d7]200                                          wx.EXPAND | wx.TOP | wx.BOTTOM, 5),
[91f151a]201                                          (self.length_sizer, 0,
[49ab5d7]202                                     wx.EXPAND | wx.TOP | wx.BOTTOM, 5),
[91f151a]203                                     (self.aperture_sizer, 0,
[49ab5d7]204                                     wx.EXPAND | wx.ALL, 10)])
[91f151a]205        self.main_sizer.AddMany([(self.collimation_sizer, 0, wx.ALL, 10),
206                                  (self.boxsizer_collimation, 0, wx.ALL, 10),
207                                  (self.button_sizer, 0,
[49ab5d7]208                                    wx.EXPAND | wx.TOP | wx.BOTTOM, 5)])
[91f151a]209        self.SetSizer(self.main_sizer)
210        self.SetAutoLayout(True)
[49ab5d7]211
[91f151a]212    def get_current_collimation(self):
213        """
214        """
215        if not self.collimation_cbox.IsEnabled():
216            return None, None, None
[49ab5d7]217        position = self.collimation_cbox.GetSelection()
[91f151a]218        if position == wx.NOT_FOUND:
219            return None, None, None
[49ab5d7]220        collimation_name = self.collimation_cbox.GetStringSelection()
[91f151a]221        collimation = self.collimation_cbox.GetClientData(position)
222        return collimation, collimation_name, position
[49ab5d7]223
[91f151a]224    def fill_collimation_combox(self):
225        """
[6137b150]226        fill the current combobox with the available collimation
[91f151a]227        """
228        if self._collimation is None or self._collimation == []:
229            return
230        for collimation in self._collimation:
231            pos = self.collimation_cbox.Append(str(collimation.name))
232            self.collimation_cbox.SetClientData(pos, collimation)
233            self.collimation_cbox.SetSelection(pos)
[49ab5d7]234            self.collimation_cbox.SetStringSelection(str(collimation.name))
235
[91f151a]236    def add_collimation(self, event):
237        """
[6137b150]238        Append empty collimation to data's list of collimation
[91f151a]239        """
[49ab5d7]240
[91f151a]241        if not self.collimation_cbox.IsEnabled():
242            self.collimation_cbox.Enable()
243        collimation = Collimation()
244        self._collimation.append(collimation)
245        position = self.collimation_cbox.Append(str(collimation.name))
246        self.collimation_cbox.SetClientData(position, collimation)
[49ab5d7]247        self.collimation_cbox.SetSelection(position)
248        self.enable_collimation()
[ad6f597]249        self.bt_add_aperture.Enable()
[c5dca87]250        self.fill_aperture_combox()
251        self.enable_aperture()
[85e665e]252        self.set_values()
[49ab5d7]253
[91f151a]254    def remove_collimation(self, event):
255        """
[6137b150]256        Remove collimation to data's list of collimation
[91f151a]257        """
258        if self.collimation_cbox.IsEnabled():
[ad6f597]259            if self.collimation_cbox.GetCount() > 0:
[91f151a]260                position = self.collimation_cbox.GetCurrentSelection()
261                collimation = self.collimation_cbox.GetClientData(position)
262                if collimation in self._collimation:
263                    self._collimation.remove(collimation)
[49ab5d7]264                    self.collimation_cbox.Delete(position)
[91f151a]265                    #set the combo box box the next available item
266                    position = self.collimation_cbox.GetCount()
267                    if position > 0:
[49ab5d7]268                        position -= 1
[91f151a]269                    self.collimation_cbox.SetSelection(position)
[49ab5d7]270        if not self._collimation and self.collimation_cbox.GetCount() == 0:
271            self.bt_add_aperture.Disable()
[85e665e]272            self.name_tcl.Clear()
273            self.length_tcl.Clear()
274            self.length_unit_tcl.Clear()
275            self.aperture_cbox.Clear()
276            self.aperture_cbox.Disable()
[91f151a]277        #disable or enable the combo box when necessary
278        self.enable_collimation()
[85e665e]279        self.enable_aperture()
[49ab5d7]280
[c5dca87]281    def on_select_collimation(self, event):
282        """
[49ab5d7]283        fill the control on the panel according to
284        the current  selected collimation
[c5dca87]285        """
286        self.set_values()
287        self.fill_aperture_combox()
288        self.enable_aperture()
[49ab5d7]289
[91f151a]290    def enable_collimation(self):
291        """
[6137b150]292        Enable /disable widgets related to collimation
[91f151a]293        """
[b0ab6cb]294        if self._collimation is not None and \
295            self.collimation_cbox.GetCount() > 0:
[91f151a]296            self.collimation_cbox.Enable()
297            self.bt_remove_collimation.Enable()
298            n_collimation = self.collimation_cbox.GetCount()
[b0ab6cb]299            collimation_hint_txt = "collimations"
[49ab5d7]300            collimation_hint_txt += " available: %s " % str(n_collimation)
[ad6f597]301            if len(self._collimation) > 0:
[91f151a]302                self.bt_remove_collimation.Enable()
303            else:
304                self.bt_remove_collimation.Disable()
305        else:
306            self.collimation_cbox.Disable()
307            self.bt_remove_collimation.Disable()
308            collimation_hint_txt = 'No collimation is available for this data.'
309        self.collimation_txt.SetLabel(collimation_hint_txt)
[49ab5d7]310
311
[91f151a]312    def reset_collimation_combobox(self, edited_collimation):
313        """
[6137b150]314        take all edited editor and reset clientdata of collimation combo box
[91f151a]315        """
316        for position in range(self.collimation_cbox.GetCount()):
317            collimation = self.collimation_cbox.GetClientData(position)
318            if collimation == edited_collimation:
319                collimation = edited_collimation
[49ab5d7]320                self.collimation_cbox.SetString(position, str(collimation.name))
[91f151a]321                self.collimation_cbox.SetClientData(position, collimation)
[49ab5d7]322                self.collimation_cbox.SetStringSelection(str(collimation.name))
323
[91f151a]324    def add_aperture(self, event):
325        """
[6137b150]326        Append empty aperture to data's list of aperture
[91f151a]327        """
328        collimation, _, _ = self.get_current_collimation()
329        if not self.aperture_cbox.IsEnabled():
330            self.aperture_cbox.Enable()
331        aperture = Aperture()
332        collimation.aperture.append(aperture)
333        position = self.aperture_cbox.Append(str(aperture.name))
334        self.aperture_cbox.SetClientData(position, aperture)
[49ab5d7]335        self.aperture_cbox.SetSelection(position)
[91f151a]336        self.enable_aperture()
[49ab5d7]337
[91f151a]338    def edit_aperture(self, event):
339        """
[6137b150]340        Edit the selected aperture
[91f151a]341        """
342        if self._collimation is None or not self.aperture_cbox.IsEnabled():
[49ab5d7]343            return
344        position = self.aperture_cbox.GetSelection()
[91f151a]345        if position != wx.NOT_FOUND:
[49ab5d7]346            name = self.aperture_cbox.GetStringSelection()
[91f151a]347            aperture = self.aperture_cbox.GetClientData(position)
348            dlg = ApertureDialog(parent=self, aperture=aperture)
349            dlg.set_manager(self)
350            dlg.ShowModal()
[49ab5d7]351
[91f151a]352    def remove_aperture(self, event):
353        """
[6137b150]354        Remove aperture to data's list of aperture
[91f151a]355        """
[ad6f597]356        if self._collimation is None or not self._collimation:
[91f151a]357            return
358        collimation, _, _ = self.get_current_collimation()
359        if self.aperture_cbox.IsEnabled():
360            if self.aperture_cbox.GetCount() > 1:
361                position = self.aperture_cbox.GetCurrentSelection()
362                aperture = self.aperture_cbox.GetClientData(position)
363                if aperture in collimation.aperture:
364                    collimation.aperture.remove(aperture)
[49ab5d7]365                    self.aperture_cbox.Delete(position)
[91f151a]366                    #set the combo box box the next available item
367                    position = self.aperture_cbox.GetCount()
368                    if position > 0:
[49ab5d7]369                        position -= 1
[91f151a]370                    self.aperture_cbox.SetSelection(position)
[49ab5d7]371
[91f151a]372        #disable or enable the combo box when necessary
373        self.enable_aperture()
[49ab5d7]374
[91f151a]375    def set_aperture(self, aperture):
376        """
[6137b150]377        set aperture for data
[91f151a]378        """
[ad6f597]379        if self._collimation is None or not self._collimation:
[91f151a]380            return
381        collimation, _, _ = self.get_current_collimation()
382        if collimation.aperture:
383            for item in collimation.aperture:
384                if item == aperture:
385                    item = aperture
386                    self.reset_aperture_combobox(edited_aperture=aperture)
387                    return
[49ab5d7]388
[91f151a]389    def enable_aperture(self):
390        """
[6137b150]391        Enable /disable widgets crelated to aperture
[91f151a]392        """
393        collimation, _, _ = self.get_current_collimation()
394        if  self.aperture_cbox.GetCount() > 0:
395            self.aperture_cbox.Enable()
396            self.bt_edit_aperture.Enable()
397            self.bt_remove_aperture.Enable()
398            n_aperture = self.aperture_cbox.GetCount()
[49ab5d7]399            aperture_hint_txt = 'apertures available: %s ' % str(n_aperture)
[c5dca87]400            if len(collimation.aperture) > 0:
[91f151a]401                self.bt_remove_aperture.Enable()
402            else:
403                self.bt_remove_aperture.Disable()
404        else:
405            self.aperture_cbox.Disable()
406            self.bt_edit_aperture.Disable()
407            self.bt_remove_aperture.Disable()
408            aperture_hint_txt = 'No aperture is available for this data.'
409        self.aperture_txt.SetLabel(aperture_hint_txt)
[49ab5d7]410
[91f151a]411    def reset_aperture_combobox(self, edited_aperture):
412        """
[6137b150]413        take all edited editor and reset clientdata of aperture combo box
[91f151a]414        """
415        for position in range(self.aperture_cbox.GetCount()):
416            aperture = self.aperture_cbox.GetClientData(position)
417            if aperture == edited_aperture:
418                aperture = edited_aperture
[49ab5d7]419                self.aperture_cbox.SetString(position, str(aperture.name))
[91f151a]420                self.aperture_cbox.SetClientData(position, aperture)
[49ab5d7]421                self.aperture_cbox.SetStringSelection(str(aperture.name))
422
[91f151a]423    def fill_aperture_combox(self):
424        """
[6137b150]425        fill the current combobox with the available aperture
[91f151a]426        """
[c5dca87]427        self.aperture_cbox.Clear()
[91f151a]428        collimation, _, _ = self.get_current_collimation()
429        if collimation is None or not collimation.aperture:
430            return
431        for aperture in collimation.aperture:
432            pos = self.aperture_cbox.Append(str(aperture.name))
433            self.aperture_cbox.SetClientData(pos, aperture)
434            self.aperture_cbox.SetSelection(pos)
[49ab5d7]435            self.aperture_cbox.SetStringSelection(str(aperture.name))
436
[91f151a]437    def set_manager(self, manager):
[49ab5d7]438        """
[6137b150]439        Set manager of this window
[91f151a]440        """
441        self.manager = manager
[49ab5d7]442
[91f151a]443    def set_values(self):
444        """
[6137b150]445        take the collimation values of the current data and display them
446        through the panel
[91f151a]447        """
448        collimation, _, _ = self.get_current_collimation()
449        if collimation is None:
[ad6f597]450            self.bt_add_aperture.Disable()
451            self.length_tcl.SetValue("")
452            self.name_tcl.SetValue("")
453            self.length_unit_tcl.SetValue("")
[91f151a]454            return
455        #Name
456        self.name_tcl.SetValue(str(collimation.name))
457        #length
458        self.length_tcl.SetValue(str(collimation.length))
459        #Length unit
460        self.length_unit_tcl.SetValue(str(collimation.length_unit))
[49ab5d7]461
[91f151a]462    def get_collimation(self):
463        """
[6137b150]464        return the current collimation
[91f151a]465        """
466        return self._collimation
[49ab5d7]467
[91f151a]468    def get_notes(self):
469        """
[6137b150]470        return notes
[91f151a]471        """
472        return self._notes
[49ab5d7]473
[91f151a]474    def on_change_name(self):
475        """
[6137b150]476        Change name
[91f151a]477        """
478        collimation, collimation_name, position = self.get_current_collimation()
[49ab5d7]479        if collimation is None:
[91f151a]480            return
481        #Change the name of the collimation
482        name = self.name_tcl.GetValue().lstrip().rstrip()
483        if name == "" or name == str(None):
484            name = None
485        if collimation.name != name:
486            self._notes += "Change collimation 's "
[49ab5d7]487            self._notes += "name from %s to %s \n" % (collimation.name, name)
[91f151a]488            collimation.name = name
[49ab5d7]489            self.collimation_cbox.SetString(position, str(collimation.name))
[91f151a]490            self.collimation_cbox.SetClientData(position, collimation)
[49ab5d7]491            self.collimation_cbox.SetStringSelection(str(collimation.name))
492
[91f151a]493    def on_change_length(self):
494        """
[6137b150]495        Change the length
[91f151a]496        """
497        collimation, collimation_name, position = self.get_current_collimation()
[49ab5d7]498        if collimation is None:
[91f151a]499            return
500        #Change length 
501        length = self.length_tcl.GetValue().lstrip().rstrip()
502        if length == "" or length == str(None):
503            length = None
504            collimation.length = length
505        else:
506            if check_float(self.length_tcl):
507                if collimation.length != float(length):
508                    self._notes += "Change Collimation length from "
[49ab5d7]509                    self._notes += "%s to %s \n" % (collimation.length, length)
510                    collimation.length = float(length)
[91f151a]511            else:
[b0ab6cb]512                self._notes += "Error: Expected a float for collimation length"
513                self._notes += " won't changes length from "
[49ab5d7]514                self._notes += "%s to %s" % (collimation.length, length)
[91f151a]515        #change length  unit
516        unit = self.length_unit_tcl.GetValue().lstrip().rstrip()
517        if collimation.length_unit != unit:
518            self._notes += " Change length's unit from "
[49ab5d7]519            self._notes += "%s to %s" % (collimation.length_unit, unit)
[91f151a]520            collimation.length_unit = unit
[49ab5d7]521
[91f151a]522    def on_click_apply(self, event):
523        """
[6137b150]524        Apply user values to the collimation
[91f151a]525        """
526        self.on_change_name()
527        self.on_change_length()
528        self.set_values()
529        if self.manager is not None:
530            self.manager.set_collimation(self._collimation, self._notes)
[49ab5d7]531
[91f151a]532    def on_click_cancel(self, event):
533        """
[6137b150]534        leave the collimation as it is and close
[91f151a]535        """
[ad6f597]536        self._collimation = deepcopy(self._reset_collimation)
[91f151a]537        self.set_values()
538        if self.manager is not None:
[b0ab6cb]539            self.manager.set_collimation(self._collimation)
[49ab5d7]540
541
[b0ab6cb]542if __name__ == "__main__":
[91f151a]543
[49ab5d7]544    app = wx.App()
[ad6f597]545    dlg = CollimationDialog(collimation=[Collimation()])
[91f151a]546    dlg.ShowModal()
547    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.