[b0ab6cb] | 1 | """ |
---|
| 2 | """ |
---|
[91f151a] | 3 | import wx |
---|
| 4 | import sys |
---|
| 5 | from copy import deepcopy |
---|
| 6 | from sans.guiframe.utils import check_float |
---|
| 7 | |
---|
[b0ab6cb] | 8 | _BOX_WIDTH = 60 |
---|
| 9 | if sys.platform.count("win32") > 0: |
---|
[91f151a] | 10 | _STATICBOX_WIDTH = 450 |
---|
| 11 | PANEL_WIDTH = 500 |
---|
| 12 | PANEL_HEIGHT = 430 |
---|
| 13 | FONT_VARIANT = 0 |
---|
| 14 | else: |
---|
| 15 | _STATICBOX_WIDTH = 480 |
---|
[ad6f597] | 16 | PANEL_WIDTH = 550 |
---|
[91f151a] | 17 | PANEL_HEIGHT = 430 |
---|
| 18 | FONT_VARIANT = 1 |
---|
| 19 | |
---|
| 20 | class SourceDialog(wx.Dialog): |
---|
| 21 | def __init__(self, parent=None, manager=None, source=None, *args, **kwds): |
---|
| 22 | kwds['title'] = "Source Editor" |
---|
[ad6f597] | 23 | kwds['size'] = (PANEL_WIDTH, PANEL_HEIGHT) |
---|
[91f151a] | 24 | wx.Dialog.__init__(self, parent=parent, *args, **kwds) |
---|
| 25 | |
---|
| 26 | self.parent = parent |
---|
| 27 | self.manager = manager |
---|
| 28 | self._source = source |
---|
| 29 | self._reset_source = deepcopy(source) |
---|
| 30 | self._notes = "" |
---|
| 31 | self._description = "Edit source" |
---|
| 32 | self._do_layout() |
---|
| 33 | self.set_values() |
---|
| 34 | |
---|
| 35 | def _define_structure(self): |
---|
| 36 | """ |
---|
| 37 | define initial sizer |
---|
| 38 | """ |
---|
| 39 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
[b0ab6cb] | 40 | self.box_source = wx.StaticBox(self, -1, str("source")) |
---|
[91f151a] | 41 | self.boxsizer_source = wx.StaticBoxSizer(self.box_source, |
---|
| 42 | wx.VERTICAL) |
---|
| 43 | self.name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 44 | self.radiation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 45 | self.beam_shape_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 46 | self.wavelength_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 47 | self.wavelength_min_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 48 | self.wavelength_max_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 49 | self.wavelength_spread_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 50 | self.beam_size_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 51 | self.beam_size_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 52 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 53 | |
---|
| 54 | def _layout_name(self): |
---|
| 55 | """ |
---|
| 56 | Do the layout for sample name related widgets |
---|
| 57 | """ |
---|
| 58 | # Sample name [string] |
---|
| 59 | sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') |
---|
[b0ab6cb] | 60 | self.sample_name_tcl = wx.TextCtrl(self, -1, |
---|
| 61 | size=(_BOX_WIDTH*5, 20), style=0) |
---|
[91f151a] | 62 | self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 63 | (self.sample_name_tcl, 0, wx.EXPAND)]) |
---|
| 64 | def _layout_radiation(self): |
---|
| 65 | """ |
---|
| 66 | Do the layout for radiation related widgets |
---|
| 67 | """ |
---|
| 68 | #Radiation type [string] |
---|
| 69 | radiation_txt = wx.StaticText(self, -1, 'Radiation: ') |
---|
[b0ab6cb] | 70 | self.radiation_tcl = wx.TextCtrl(self, -1, |
---|
| 71 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 72 | self.radiation_sizer.AddMany([(radiation_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 73 | (self.radiation_tcl, 0, wx.LEFT, 20)]) |
---|
| 74 | |
---|
| 75 | def _layout_beam_shape(self): |
---|
| 76 | """ |
---|
| 77 | Do the layout for beam shape related widgets |
---|
| 78 | """ |
---|
| 79 | #Beam shape [string] |
---|
| 80 | beam_shape_txt = wx.StaticText(self, -1, 'Beam shape:') |
---|
[b0ab6cb] | 81 | self.beam_shape_tcl = wx.TextCtrl(self, -1, |
---|
| 82 | size=(_BOX_WIDTH, 20), style=0) |
---|
| 83 | self.beam_shape_sizer.AddMany([(beam_shape_txt, 0, |
---|
| 84 | wx.LEFT|wx.RIGHT, 10), |
---|
[91f151a] | 85 | (self.beam_shape_tcl, 0, wx.LEFT, 10)]) |
---|
| 86 | |
---|
| 87 | def _layout_wavelength(self): |
---|
| 88 | """ |
---|
| 89 | Do the layout for wavelength related widgets |
---|
| 90 | """ |
---|
| 91 | #Wavelength [float] [Angstrom] |
---|
| 92 | wavelength_txt = wx.StaticText(self, -1, 'wavelength:') |
---|
[b0ab6cb] | 93 | self.wavelength_tcl = wx.TextCtrl(self, -1, |
---|
| 94 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 95 | wavelength_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
[b0ab6cb] | 96 | self.wavelength_unit_tcl = wx.TextCtrl(self, -1, |
---|
| 97 | size=(_BOX_WIDTH, 20),style=0) |
---|
| 98 | self.wavelength_sizer.AddMany([(wavelength_txt, |
---|
| 99 | 0, wx.LEFT|wx.RIGHT, 10), |
---|
[91f151a] | 100 | (self.wavelength_tcl, 0, wx.LEFT, 12), |
---|
[b0ab6cb] | 101 | (wavelength_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
[91f151a] | 102 | (self.wavelength_unit_tcl, 0, wx.EXPAND)]) |
---|
| 103 | |
---|
| 104 | def _layout_wavelength_min(self): |
---|
| 105 | """ |
---|
| 106 | Do the layout for wavelength min related widgets |
---|
| 107 | """ |
---|
| 108 | #Minimum wavelength [float] [Angstrom] |
---|
| 109 | wavelength_min_txt = wx.StaticText(self, -1, 'Wavelength min:') |
---|
[b0ab6cb] | 110 | self.wavelength_min_tcl = wx.TextCtrl(self, -1, |
---|
| 111 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 112 | wavelength_min_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
[b0ab6cb] | 113 | self.wavelength_min_unit_tcl = wx.TextCtrl(self, -1, |
---|
| 114 | size=(_BOX_WIDTH, 20), style=0) |
---|
| 115 | self.wavelength_min_sizer.AddMany([(wavelength_min_txt, |
---|
| 116 | 0, wx.LEFT|wx.RIGHT, 10), |
---|
[91f151a] | 117 | (self.wavelength_min_tcl, 0, wx.LEFT, 10), |
---|
[b0ab6cb] | 118 | (wavelength_min_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 119 | (self.wavelength_min_unit_tcl, 0, wx.EXPAND)]) |
---|
[91f151a] | 120 | |
---|
| 121 | def _layout_wavelength_max(self): |
---|
| 122 | """ |
---|
| 123 | Do the layout for wavelength max related widgets |
---|
| 124 | """ |
---|
| 125 | #Maximum wavelength [float] [Angstrom] |
---|
| 126 | wavelength_max_txt = wx.StaticText(self, -1, 'Wavelength max:') |
---|
[b0ab6cb] | 127 | self.wavelength_max_tcl = wx.TextCtrl(self, -1, |
---|
| 128 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 129 | wavelength_max_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
[b0ab6cb] | 130 | self.wavelength_max_unit_tcl = wx.TextCtrl(self, -1, |
---|
| 131 | size=(_BOX_WIDTH, 20), style=0) |
---|
| 132 | self.wavelength_max_sizer.AddMany([(wavelength_max_txt, 0, |
---|
| 133 | wx.LEFT|wx.RIGHT, 10), |
---|
[91f151a] | 134 | (self.wavelength_max_tcl, 0, wx.LEFT, 7), |
---|
[b0ab6cb] | 135 | (wavelength_max_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 136 | (self.wavelength_max_unit_tcl, 0, wx.EXPAND)]) |
---|
[91f151a] | 137 | |
---|
| 138 | def _layout_wavelength_spread(self): |
---|
| 139 | """ |
---|
| 140 | Do the layout for wavelength spread related widgets |
---|
| 141 | """ |
---|
| 142 | ## Wavelength spread [float] [Angstrom] |
---|
| 143 | wavelength_spread = None |
---|
| 144 | wavelength_spread_unit = 'percent' |
---|
| 145 | wavelength_spread_txt = wx.StaticText(self, -1, 'Wavelength spread:') |
---|
[b0ab6cb] | 146 | self.wavelength_spread_tcl = wx.TextCtrl(self, -1, |
---|
| 147 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 148 | wavelength_spread_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
[b0ab6cb] | 149 | self.wavelength_spread_unit_tcl = wx.TextCtrl(self, -1, |
---|
| 150 | size=(_BOX_WIDTH, 20), style=0) |
---|
| 151 | self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, |
---|
| 152 | 0, wx.LEFT, 10), |
---|
| 153 | (self.wavelength_spread_tcl, 0, wx.LEFT, 5), |
---|
| 154 | (wavelength_spread_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 155 | (self.wavelength_spread_unit_tcl, 0, wx.EXPAND)]) |
---|
[91f151a] | 156 | def _layout_beam_size_name(self): |
---|
| 157 | """ |
---|
| 158 | Do the layout for beam size name related widgets |
---|
| 159 | """ |
---|
| 160 | # Beam size name [string] |
---|
| 161 | beam_size_name_txt = wx.StaticText(self, -1, 'Beam size name : ') |
---|
[b0ab6cb] | 162 | self.beam_size_name_tcl = wx.TextCtrl(self, -1, |
---|
| 163 | size=(_BOX_WIDTH*5, 20), style=0) |
---|
| 164 | self.beam_size_name_sizer.AddMany([(beam_size_name_txt, |
---|
| 165 | 0, wx.LEFT|wx.RIGHT, 10), |
---|
[91f151a] | 166 | (self.beam_size_name_tcl, 0, wx.EXPAND)]) |
---|
| 167 | |
---|
| 168 | def _layout_beam_size(self): |
---|
| 169 | """ |
---|
| 170 | Do the layout for beam size related widgets |
---|
| 171 | """ |
---|
| 172 | ## Beam size [Vector] [mm] |
---|
| 173 | beam_size = None |
---|
| 174 | beam_size_unit = 'mm' |
---|
| 175 | |
---|
| 176 | beam_size_txt = wx.StaticText(self, -1, 'Beam size:') |
---|
| 177 | x_beam_size_txt = wx.StaticText(self, -1, 'x = ') |
---|
[b0ab6cb] | 178 | self.x_beam_size_tcl = wx.TextCtrl(self, -1, |
---|
| 179 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 180 | y_beam_size_txt = wx.StaticText(self, -1, 'y = ') |
---|
[b0ab6cb] | 181 | self.y_beam_size_tcl = wx.TextCtrl(self, -1, |
---|
| 182 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 183 | z_beam_size_txt = wx.StaticText(self, -1, 'z = ') |
---|
[b0ab6cb] | 184 | self.z_beam_size_tcl = wx.TextCtrl(self, -1, |
---|
| 185 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 186 | beam_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
[b0ab6cb] | 187 | self.beam_size_unit_tcl = wx.TextCtrl(self, -1, |
---|
| 188 | size=(_BOX_WIDTH, 20), style=0) |
---|
[91f151a] | 189 | self.beam_size_sizer.AddMany([(beam_size_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 190 | (x_beam_size_txt, 0, wx.LEFT, 17), |
---|
| 191 | (self.x_beam_size_tcl, 0, wx.RIGHT, 10), |
---|
| 192 | (y_beam_size_txt, 0, wx.EXPAND), |
---|
| 193 | (self.y_beam_size_tcl, 0, wx.RIGHT, 10), |
---|
| 194 | (z_beam_size_txt, 0, wx.EXPAND), |
---|
| 195 | (self.z_beam_size_tcl, 0, wx.RIGHT, 10), |
---|
| 196 | (beam_size_unit_txt, 0, wx.EXPAND), |
---|
[b0ab6cb] | 197 | (self.beam_size_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
[91f151a] | 198 | |
---|
| 199 | def _layout_button(self): |
---|
| 200 | """ |
---|
| 201 | Do the layout for the button widgets |
---|
| 202 | """ |
---|
| 203 | self.bt_apply = wx.Button(self, -1,'Apply') |
---|
| 204 | self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) |
---|
| 205 | self.bt_apply.SetToolTipString("Apply current changes to the source.") |
---|
| 206 | self.bt_cancel = wx.Button(self, -1,'Cancel') |
---|
| 207 | self.bt_cancel.SetToolTipString("Cancel current changes.") |
---|
| 208 | self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel) |
---|
| 209 | self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close') |
---|
| 210 | self.bt_close.SetToolTipString("Close window.") |
---|
| 211 | self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200), |
---|
| 212 | (self.bt_cancel, 0, wx.LEFT, 10), |
---|
| 213 | (self.bt_close, 0, wx.LEFT, 10)]) |
---|
| 214 | |
---|
| 215 | def _do_layout(self, data=None): |
---|
| 216 | """ |
---|
| 217 | Draw the current panel |
---|
| 218 | """ |
---|
| 219 | self._define_structure() |
---|
| 220 | self._layout_name() |
---|
| 221 | self._layout_radiation() |
---|
| 222 | self._layout_beam_shape() |
---|
| 223 | self._layout_wavelength() |
---|
| 224 | self._layout_wavelength_min() |
---|
| 225 | self._layout_wavelength_max() |
---|
| 226 | self._layout_wavelength_spread() |
---|
| 227 | self._layout_beam_size_name() |
---|
| 228 | self._layout_beam_size() |
---|
| 229 | self._layout_button() |
---|
| 230 | |
---|
| 231 | self.boxsizer_source.AddMany([(self.name_sizer, 0, |
---|
| 232 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 233 | (self.radiation_sizer, 0, |
---|
| 234 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 235 | (self.beam_shape_sizer, 0, |
---|
| 236 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 237 | (self.wavelength_sizer, 0, |
---|
| 238 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 239 | (self.wavelength_min_sizer, 0, |
---|
| 240 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 241 | (self.wavelength_max_sizer, 0, |
---|
| 242 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 243 | (self.wavelength_spread_sizer, 0, |
---|
| 244 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 245 | (self.beam_size_name_sizer, 0, |
---|
| 246 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 247 | (self.beam_size_sizer, 0, |
---|
| 248 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
| 249 | self.main_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10), |
---|
| 250 | (self.button_sizer, 0, |
---|
| 251 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
| 252 | |
---|
| 253 | self.SetSizer(self.main_sizer) |
---|
| 254 | self.SetAutoLayout(True) |
---|
| 255 | |
---|
| 256 | def set_manager(self, manager): |
---|
| 257 | """ |
---|
| 258 | Set manager of this window |
---|
| 259 | """ |
---|
| 260 | self.manager = manager |
---|
| 261 | |
---|
| 262 | def reset_source(self): |
---|
| 263 | """ |
---|
| 264 | put back initial values of the source |
---|
| 265 | """ |
---|
| 266 | self._source.name = self._reset_source.name |
---|
| 267 | self._source.radiation = self._reset_source.radiation |
---|
| 268 | self._source.beam_size_name = self._reset_source.beam_size_name |
---|
| 269 | |
---|
| 270 | self._source.beam_size.x = self._reset_source.beam_size.x |
---|
| 271 | self._source.beam_size.y = self._reset_source.beam_size.y |
---|
| 272 | self._source.beam_size.z = self._reset_source.beam_size.z |
---|
| 273 | self._source.beam_size_unit = self._reset_source.beam_size_unit |
---|
| 274 | |
---|
| 275 | self._source.beam_shape = self._reset_source.beam_shape |
---|
| 276 | self._source.wavelength = self._reset_source.wavelength |
---|
| 277 | self._source.wavelength_unit = self._reset_source.wavelength_unit |
---|
| 278 | ## Minimum wavelength [float] [Angstrom] |
---|
| 279 | self._source.wavelength_min = self._reset_source.wavelength_min |
---|
| 280 | self._source.wavelength_min_unit = self._reset_source.wavelength_min_unit |
---|
| 281 | |
---|
| 282 | self._source.wavelength_max = self._reset_source.wavelength_max |
---|
| 283 | self._source.wavelength_max_unit = self._reset_source.wavelength_max_unit |
---|
| 284 | |
---|
| 285 | self._source.wavelength_spread = self._reset_source.wavelength_spread |
---|
| 286 | self._source.wavelength_spread_unit = self._reset_source.wavelength_spread_unit |
---|
| 287 | |
---|
| 288 | def set_values(self): |
---|
| 289 | """ |
---|
| 290 | take the source values of the current data and display them |
---|
| 291 | through the panel |
---|
| 292 | """ |
---|
| 293 | source = self._source |
---|
| 294 | #Name |
---|
| 295 | self.sample_name_tcl.SetValue(str(source.name)) |
---|
| 296 | #Radiation |
---|
| 297 | self.radiation_tcl.SetValue(str(source.radiation)) |
---|
| 298 | #Beam shape |
---|
| 299 | self.beam_shape_tcl.SetValue(str(source.beam_shape)) |
---|
| 300 | #Wavelength |
---|
| 301 | self.wavelength_tcl.SetValue(str(source.wavelength)) |
---|
| 302 | self.wavelength_unit_tcl.SetValue(str(source.wavelength_unit)) |
---|
| 303 | #Wavelength min |
---|
| 304 | self.wavelength_min_tcl.SetValue(str(source.wavelength_min)) |
---|
| 305 | self.wavelength_min_unit_tcl.SetValue(str(source.wavelength_min_unit)) |
---|
| 306 | #Wavelength max |
---|
| 307 | self.wavelength_max_tcl.SetValue(str(source.wavelength_max)) |
---|
| 308 | self.wavelength_max_unit_tcl.SetValue(str(source.wavelength_max_unit)) |
---|
| 309 | #Wavelength spread |
---|
| 310 | self.wavelength_spread_tcl.SetValue(str(source.wavelength_spread)) |
---|
| 311 | self.wavelength_spread_unit_tcl.SetValue(str(source.wavelength_spread_unit)) |
---|
| 312 | #Beam size |
---|
| 313 | self.beam_size_name_tcl.SetValue(str(source.beam_size_name)) |
---|
| 314 | x, y, z = source.beam_size.x, source.beam_size.y , source.beam_size.z |
---|
| 315 | self.x_beam_size_tcl.SetValue(str(x)) |
---|
| 316 | self.y_beam_size_tcl.SetValue(str(y)) |
---|
| 317 | self.z_beam_size_tcl.SetValue(str(z)) |
---|
| 318 | self.beam_size_unit_tcl.SetValue(str(source.beam_size_unit)) |
---|
| 319 | |
---|
| 320 | def get_source(self): |
---|
| 321 | """ |
---|
| 322 | return the current source |
---|
| 323 | """ |
---|
| 324 | return self._source |
---|
| 325 | |
---|
| 326 | def get_notes(self): |
---|
| 327 | """ |
---|
| 328 | return notes |
---|
| 329 | """ |
---|
| 330 | return self._notes |
---|
| 331 | |
---|
| 332 | def on_change_name(self): |
---|
| 333 | """ |
---|
| 334 | Change name |
---|
| 335 | """ |
---|
| 336 | #Change the name of the source |
---|
| 337 | name = self.sample_name_tcl.GetValue().lstrip().rstrip() |
---|
| 338 | if name == "" or name == str(None): |
---|
| 339 | name = None |
---|
| 340 | if self._source.name != name: |
---|
| 341 | self._notes += "Change sample 's " |
---|
| 342 | self._notes += "name from %s to %s \n"%(self._source.name, name) |
---|
| 343 | self._source.name = name |
---|
| 344 | |
---|
| 345 | def on_change_radiation(self): |
---|
| 346 | """ |
---|
| 347 | Change radiation of the sample |
---|
| 348 | """ |
---|
| 349 | #Change radiation |
---|
| 350 | radiation = self.radiation_tcl.GetValue().lstrip().rstrip() |
---|
| 351 | self._source.radiation = radiation |
---|
| 352 | self._notes += " Change radiation from" |
---|
| 353 | self._notes += " %s to %s \n"%(self._source.radiation, radiation) |
---|
| 354 | |
---|
| 355 | def on_change_beam_shape(self): |
---|
| 356 | """ |
---|
| 357 | Change beams shape |
---|
| 358 | """ |
---|
| 359 | #Change beam shape |
---|
| 360 | beam_shape = self.beam_shape_tcl.GetValue().lstrip().rstrip() |
---|
| 361 | self._source.beam_shape = beam_shape |
---|
| 362 | self._notes += " Change beam shape from" |
---|
| 363 | self._notes += " %s to %s \n"%(self._source.beam_shape, beam_shape) |
---|
| 364 | |
---|
| 365 | def on_change_wavelength(self): |
---|
| 366 | """ |
---|
| 367 | Change the wavelength |
---|
| 368 | """ |
---|
| 369 | #Change wavelength |
---|
| 370 | wavelength = self.wavelength_tcl.GetValue().lstrip().rstrip() |
---|
| 371 | self._source.wavelength = wavelength |
---|
| 372 | self._notes += " Change wavelength from" |
---|
| 373 | self._notes += " %s to %s \n"%(self._source.wavelength, wavelength) |
---|
| 374 | #change the wavelength unit |
---|
| 375 | unit = self.wavelength_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 376 | if self._source.wavelength_unit != unit: |
---|
| 377 | self._notes += " Change wavelength's unit from " |
---|
| 378 | self._notes += "%s to %s"%(self._source.wavelength_unit, unit) |
---|
| 379 | |
---|
| 380 | def on_change_wavelength_min(self): |
---|
| 381 | """ |
---|
| 382 | Change the wavelength minimum |
---|
| 383 | """ |
---|
| 384 | #Change wavelength min |
---|
| 385 | wavelength_min = self.wavelength_min_tcl.GetValue().lstrip().rstrip() |
---|
| 386 | self._source.wavelength_min = wavelength_min |
---|
| 387 | self._notes += " Change wavelength min from" |
---|
[b0ab6cb] | 388 | self._notes += " %s to %s \n" % (self._source.wavelength_min, |
---|
| 389 | wavelength_min) |
---|
[91f151a] | 390 | #change the wavelength min unit |
---|
| 391 | unit = self.wavelength_min_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 392 | if self._source.wavelength_min_unit != unit: |
---|
| 393 | self._notes += " Change wavelength min's unit from " |
---|
[b0ab6cb] | 394 | self._notes += "%s to %s" % (self._source.wavelength_min_unit, unit) |
---|
[91f151a] | 395 | |
---|
| 396 | def on_change_wavelength_max(self): |
---|
| 397 | """ |
---|
| 398 | Change the wavelength maximum |
---|
| 399 | """ |
---|
| 400 | #Change wavelength max |
---|
| 401 | wavelength_max = self.wavelength_max_tcl.GetValue().lstrip().rstrip() |
---|
| 402 | self._source.wavelength_max = wavelength_max |
---|
| 403 | self._notes += " Change wavelength max from" |
---|
[b0ab6cb] | 404 | self._notes += " %s to %s \n" % (self._source.wavelength_max, |
---|
| 405 | wavelength_max) |
---|
[91f151a] | 406 | #change the wavelength max unit |
---|
| 407 | unit = self.wavelength_max_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 408 | if self._source.wavelength_max_unit != unit: |
---|
| 409 | self._notes += " Change wavelength max's unit from " |
---|
| 410 | self._notes += "%s to %s"%(self._source.wavelength_max_unit, unit) |
---|
| 411 | |
---|
| 412 | def on_change_wavelength_spread(self): |
---|
| 413 | """ |
---|
| 414 | Change the wavelength spread |
---|
| 415 | """ |
---|
| 416 | #Change wavelength spread |
---|
| 417 | wavelength_spread = self.wavelength_spread_tcl.GetValue().lstrip().rstrip() |
---|
| 418 | self._notes += " Change wavelength spread from" |
---|
[b0ab6cb] | 419 | self._notes += " %s to %s \n" % (self._source.wavelength_spread, |
---|
| 420 | wavelength_spread) |
---|
[91f151a] | 421 | self._source.wavelength_spread = wavelength_spread |
---|
| 422 | #change the wavelength spread unit |
---|
| 423 | unit = self.wavelength_spread_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 424 | if self._source.wavelength_spread_unit != unit: |
---|
| 425 | self._notes += " Change wavelength spread's unit from " |
---|
[b0ab6cb] | 426 | self._notes += "%s to %s" % (self._source.wavelength_spread_unit, |
---|
| 427 | unit) |
---|
[91f151a] | 428 | self._source.wavelength_spread_unit = unit |
---|
| 429 | |
---|
| 430 | def on_change_beam_size_name(self): |
---|
| 431 | """ |
---|
| 432 | Change beam size name |
---|
| 433 | """ |
---|
| 434 | #Change beam size name |
---|
| 435 | name = self.beam_size_name_tcl.GetValue().lstrip().rstrip() |
---|
| 436 | if name == "" or name == str(None): |
---|
| 437 | name = None |
---|
| 438 | if self._source.beam_size_name != name: |
---|
| 439 | self._notes += "Change beam size 's " |
---|
[b0ab6cb] | 440 | self._notes += "name from %s to %s \n" % (self._source.beam_size_name, |
---|
| 441 | name) |
---|
[91f151a] | 442 | self._source.name = name |
---|
| 443 | |
---|
| 444 | def on_change_beam_size(self): |
---|
| 445 | """ |
---|
| 446 | Change beam size |
---|
| 447 | """ |
---|
| 448 | #Change x coordinate |
---|
| 449 | x_beam_size = self.x_beam_size_tcl.GetValue().lstrip().rstrip() |
---|
| 450 | if x_beam_size == "" or x_beam_size == str(None): |
---|
| 451 | x_beam_size = None |
---|
| 452 | else: |
---|
| 453 | if check_float(self.x_beam_size_tcl): |
---|
| 454 | if self._source.beam_size.x != float(x_beam_size) : |
---|
| 455 | self._notes += "Change x of beam size from " |
---|
[b0ab6cb] | 456 | self._notes += "%s to %s \n" % (self._source.beam_size.x, |
---|
| 457 | x_beam_size) |
---|
[91f151a] | 458 | self._source.beam_size.x = float(x_beam_size) |
---|
| 459 | else: |
---|
| 460 | self._notes += "Error: Expected a float for the beam size 's x " |
---|
| 461 | self._notes += "won't changes x beam size from " |
---|
[b0ab6cb] | 462 | self._notes += "%s to %s" % (self._source.beam_size.x, |
---|
| 463 | x_beam_size) |
---|
[91f151a] | 464 | #Change y coordinate |
---|
| 465 | y_beam_size = self.y_beam_size_tcl.GetValue().lstrip().rstrip() |
---|
| 466 | if y_beam_size == "" or y_beam_size == str(None): |
---|
| 467 | y_beam_size = None |
---|
| 468 | self._source.beam_size.y = y_beam_size |
---|
| 469 | else: |
---|
| 470 | if check_float(self.y_beam_size_tcl): |
---|
| 471 | if self._source.beam_size.y != float(y_beam_size): |
---|
| 472 | self._notes += "Change y of beam size from " |
---|
[b0ab6cb] | 473 | self._notes += "%s to %s \n" % (self._source.beam_size.y, |
---|
| 474 | y_beam_size) |
---|
[91f151a] | 475 | self._source.beam_size.y = float(y_beam_size) |
---|
| 476 | else: |
---|
| 477 | self._notes += "Error: Expected a float for the beam size's y " |
---|
| 478 | self._notes += "won't changes y beam size from " |
---|
[b0ab6cb] | 479 | self._notes += "%s to %s" % (self._source.beam_size.y, |
---|
| 480 | y_beam_size) |
---|
[91f151a] | 481 | #Change z coordinate |
---|
| 482 | z_beam_size = self.z_beam_size_tcl.GetValue().lstrip().rstrip() |
---|
| 483 | if z_beam_size == "" or z_beam_size == str(None): |
---|
| 484 | z_beam_size = None |
---|
| 485 | self._source.beam_size.z = z_beam_size |
---|
| 486 | else: |
---|
| 487 | if check_float(self.z_beam_size_tcl): |
---|
| 488 | if self._source.beam_size.z != float(z_beam_size): |
---|
| 489 | self._notes += "Change z of beam size from " |
---|
[b0ab6cb] | 490 | self._notes += "%s to %s \n" % (self._source.beam_size.z, |
---|
| 491 | z_beam_size) |
---|
[91f151a] | 492 | self._source.beam_size.z = float(z_beam_size) |
---|
| 493 | else: |
---|
| 494 | self._notes += "Error: Expected a float for the beam size 's z " |
---|
| 495 | self._notes += "won't changes z beam size from " |
---|
[b0ab6cb] | 496 | self._notes += "%s to %s" % (self._source.beam_size.z, |
---|
| 497 | z_beam_size) |
---|
[91f151a] | 498 | #change the beam center unit |
---|
| 499 | unit = self.beam_size_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 500 | if self._source.beam_size_unit != unit: |
---|
| 501 | self._notes += " Change beam size's unit from " |
---|
| 502 | self._notes += "%s to %s"%(self._source.beam_size_unit, unit) |
---|
| 503 | self._source.beam_size_unit = unit |
---|
| 504 | |
---|
| 505 | def on_click_apply(self, event): |
---|
| 506 | """ |
---|
[b0ab6cb] | 507 | Apply user values to the source |
---|
[91f151a] | 508 | """ |
---|
| 509 | self.on_change_name() |
---|
| 510 | self.on_change_radiation() |
---|
| 511 | self.on_change_beam_shape() |
---|
| 512 | self.on_change_wavelength() |
---|
| 513 | self.on_change_wavelength_min() |
---|
| 514 | self.on_change_wavelength_max() |
---|
| 515 | self.on_change_wavelength_spread() |
---|
| 516 | self.on_change_beam_size_name() |
---|
| 517 | self.on_change_beam_size() |
---|
| 518 | if self.manager is not None: |
---|
| 519 | self.manager.set_source(self._source, self._notes) |
---|
[b0ab6cb] | 520 | if event is not None: |
---|
| 521 | event.Skip() |
---|
[91f151a] | 522 | |
---|
| 523 | def on_click_cancel(self, event): |
---|
| 524 | """ |
---|
[b0ab6cb] | 525 | reset the current source |
---|
[91f151a] | 526 | """ |
---|
| 527 | self.reset_source() |
---|
| 528 | self.set_values() |
---|
| 529 | if self.manager is not None: |
---|
[b0ab6cb] | 530 | self.manager.set_source(self._source) |
---|
| 531 | if event is not None: |
---|
| 532 | event.Skip() |
---|
[91f151a] | 533 | |
---|
| 534 | if __name__ =="__main__": |
---|
| 535 | app = wx.App() |
---|
[6572274] | 536 | from sans.dataloader.data_info import Source |
---|
[ad6f597] | 537 | source = Source() |
---|
| 538 | dlg = SourceDialog(source=source) |
---|
[91f151a] | 539 | dlg.ShowModal() |
---|
| 540 | app.MainLoop() |
---|
| 541 | |
---|