[91f151a] | 1 | |
---|
| 2 | import wx |
---|
| 3 | import sys |
---|
| 4 | from copy import deepcopy |
---|
| 5 | from sans.guiframe.utils import check_float |
---|
| 6 | |
---|
| 7 | _BOX_WIDTH = 60 |
---|
| 8 | if sys.platform.count("win32")>0: |
---|
| 9 | _STATICBOX_WIDTH = 450 |
---|
| 10 | PANEL_WIDTH = 500 |
---|
| 11 | PANEL_HEIGHT = 430 |
---|
| 12 | FONT_VARIANT = 0 |
---|
| 13 | else: |
---|
| 14 | _STATICBOX_WIDTH = 480 |
---|
[ad6f597] | 15 | PANEL_WIDTH = 550 |
---|
[91f151a] | 16 | PANEL_HEIGHT = 430 |
---|
| 17 | FONT_VARIANT = 1 |
---|
| 18 | |
---|
| 19 | class SampleDialog(wx.Dialog): |
---|
| 20 | def __init__(self, parent=None, manager=None, sample=None, |
---|
| 21 | size=(PANEL_WIDTH, PANEL_HEIGHT),title='Sample Editor'): |
---|
| 22 | |
---|
| 23 | wx.Dialog.__init__(self, parent=parent, size=size, title=title) |
---|
| 24 | self.parent = parent |
---|
| 25 | self.manager = manager |
---|
| 26 | self._sample = sample |
---|
| 27 | self._reset_sample = deepcopy(sample) |
---|
| 28 | self._notes = "" |
---|
| 29 | self._description = "Edit Sample" |
---|
| 30 | self._do_layout() |
---|
| 31 | self.set_values() |
---|
| 32 | |
---|
| 33 | def _define_structure(self): |
---|
| 34 | """ |
---|
| 35 | define initial sizer |
---|
| 36 | """ |
---|
| 37 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 38 | self.box_sample = wx.StaticBox(self, -1,str("Sample")) |
---|
| 39 | self.boxsizer_sample = wx.StaticBoxSizer(self.box_sample, |
---|
| 40 | wx.VERTICAL) |
---|
| 41 | self.name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 42 | self.id_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 43 | self.thickness_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 44 | self.transmission_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 45 | self.temperature_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 46 | self.position_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 47 | self.orientation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 48 | self.details_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 49 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 50 | |
---|
| 51 | def _layout_name(self): |
---|
| 52 | """ |
---|
| 53 | Do the layout for sample name related widgets |
---|
| 54 | """ |
---|
| 55 | ## Short name for sample [string] |
---|
| 56 | sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') |
---|
| 57 | self.sample_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
| 58 | self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 59 | (self.sample_name_tcl, 0, wx.EXPAND)]) |
---|
| 60 | def _layout_id(self): |
---|
| 61 | """ |
---|
| 62 | Do the layout for id related widgets |
---|
| 63 | """ |
---|
| 64 | ## ID [String] |
---|
| 65 | id_txt = wx.StaticText(self, -1, 'ID: ') |
---|
| 66 | self.id_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
| 67 | self.id_sizer.AddMany([(id_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 68 | (self.id_tcl, 0, wx.LEFT, 55)]) |
---|
| 69 | |
---|
| 70 | def _layout_thickness(self): |
---|
| 71 | """ |
---|
| 72 | Do the layout for thickness related widgets |
---|
| 73 | """ |
---|
| 74 | ## Thickness [float] [mm] |
---|
| 75 | thickness_txt = wx.StaticText(self, -1, 'Thickness:') |
---|
| 76 | self.thickness_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
| 77 | thickness_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
| 78 | self.thickness_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 79 | style=0) |
---|
| 80 | self.thickness_sizer.AddMany([(thickness_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 81 | (self.thickness_tcl, 0, wx.LEFT, 25), |
---|
| 82 | (thickness_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 83 | (self.thickness_unit_tcl, 0, wx.EXPAND)]) |
---|
| 84 | def _layout_transmission(self): |
---|
| 85 | """ |
---|
| 86 | Do the layout for transmission related widgets |
---|
| 87 | """ |
---|
| 88 | ## Transmission [float] [fraction] |
---|
| 89 | transmission = None |
---|
| 90 | transmission_txt = wx.StaticText(self, -1, 'Transmission:') |
---|
| 91 | self.transmission_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
| 92 | self.transmission_sizer.AddMany([(transmission_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 93 | (self.transmission_tcl, 0, wx.LEFT, 12)]) |
---|
| 94 | |
---|
| 95 | def _layout_temperature(self): |
---|
| 96 | """ |
---|
| 97 | Do the layout for temperature related widgets |
---|
| 98 | """ |
---|
| 99 | ## Temperature [float] [C] |
---|
| 100 | temperature_txt = wx.StaticText(self, -1, 'Temperature:') |
---|
| 101 | self.temperature_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
| 102 | temperature_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
| 103 | self.temperature_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 104 | style=0) |
---|
| 105 | self.temperature_sizer.AddMany([(temperature_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 106 | (self.temperature_tcl, 0, wx.LEFT, 10), |
---|
| 107 | (temperature_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 108 | (self.temperature_unit_tcl, 0, wx.EXPAND)]) |
---|
| 109 | |
---|
| 110 | def _layout_position(self): |
---|
| 111 | """ |
---|
| 112 | Do the layout for position related widgets |
---|
| 113 | """ |
---|
| 114 | ## Position [Vector] [mm] |
---|
| 115 | position_txt = wx.StaticText(self, -1, 'Position:') |
---|
| 116 | x_position_txt = wx.StaticText(self, -1, 'x = ') |
---|
| 117 | self.x_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 118 | y_position_txt = wx.StaticText(self, -1, 'y = ') |
---|
| 119 | self.y_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 120 | z_position_txt = wx.StaticText(self, -1, 'z = ') |
---|
| 121 | self.z_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 122 | position_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
| 123 | self.position_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 124 | self.position_sizer.AddMany([(position_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 125 | (x_position_txt, 0, wx.LEFT, 14), |
---|
| 126 | (self.x_position_tcl, 0, wx.RIGHT, 10), |
---|
| 127 | (y_position_txt, 0, wx.EXPAND), |
---|
| 128 | (self.y_position_tcl, 0, wx.RIGHT, 10), |
---|
| 129 | (z_position_txt, 0, wx.EXPAND), |
---|
| 130 | (self.z_position_tcl, 0, wx.RIGHT, 10), |
---|
| 131 | (position_unit_txt, 0, wx.EXPAND), |
---|
| 132 | (self.position_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
| 133 | def _layout_orientation(self): |
---|
| 134 | """ |
---|
| 135 | Do the layout for orientation related widgets |
---|
| 136 | """ |
---|
| 137 | ## Orientation [Vector] [degrees] |
---|
| 138 | orientation_txt = wx.StaticText(self, -1, 'Orientation:') |
---|
| 139 | x_orientation_txt = wx.StaticText(self, -1, 'x = ') |
---|
| 140 | self.x_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 141 | y_orientation_txt = wx.StaticText(self, -1, 'y = ') |
---|
| 142 | self.y_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 143 | z_orientation_txt = wx.StaticText(self, -1, 'z = ') |
---|
| 144 | self.z_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 145 | orientation_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
| 146 | self.orientation_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
| 147 | self.orientation_sizer.AddMany([(orientation_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 148 | (x_orientation_txt, 0, wx.LEFT, 0), |
---|
| 149 | (self.x_orientation_tcl, 0, wx.RIGHT, 10), |
---|
| 150 | (y_orientation_txt, 0, wx.EXPAND), |
---|
| 151 | (self.y_orientation_tcl, 0, wx.RIGHT, 10), |
---|
| 152 | (z_orientation_txt, 0, wx.EXPAND), |
---|
| 153 | (self.z_orientation_tcl, 0, wx.RIGHT, 10), |
---|
| 154 | (orientation_unit_txt, 0, wx.EXPAND), |
---|
| 155 | (self.orientation_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
| 156 | |
---|
| 157 | def _layout_details(self): |
---|
| 158 | """ |
---|
| 159 | Do the layout for beam size name related widgets |
---|
| 160 | """ |
---|
| 161 | ## Details |
---|
| 162 | details = None |
---|
| 163 | details_txt = wx.StaticText(self, -1, 'Details: ') |
---|
| 164 | self.details_tcl = wx.TextCtrl(self, -1,size=(_BOX_WIDTH*5,_BOX_WIDTH), |
---|
| 165 | style=wx.TE_MULTILINE | wx.HSCROLL) |
---|
| 166 | self.details_sizer.AddMany([(details_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 167 | (self.details_tcl, 0, wx.EXPAND)]) |
---|
| 168 | |
---|
| 169 | def _layout_button(self): |
---|
| 170 | """ |
---|
| 171 | Do the layout for the button widgets |
---|
| 172 | """ |
---|
| 173 | self.bt_apply = wx.Button(self, -1,'Apply') |
---|
| 174 | self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) |
---|
| 175 | self.bt_apply.SetToolTipString("Apply current changes to the sample.") |
---|
| 176 | self.bt_cancel = wx.Button(self, -1,'Cancel') |
---|
| 177 | self.bt_cancel.SetToolTipString("Cancel current changes.") |
---|
| 178 | self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel) |
---|
| 179 | self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close') |
---|
| 180 | self.bt_close.SetToolTipString("Close window.") |
---|
| 181 | self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200), |
---|
| 182 | (self.bt_cancel, 0, wx.LEFT, 10), |
---|
| 183 | (self.bt_close, 0, wx.LEFT, 10)]) |
---|
| 184 | |
---|
| 185 | def _do_layout(self, data=None): |
---|
| 186 | """ |
---|
| 187 | Draw the current panel |
---|
| 188 | """ |
---|
| 189 | self._define_structure() |
---|
| 190 | self._layout_name() |
---|
| 191 | self._layout_id() |
---|
| 192 | self._layout_thickness() |
---|
| 193 | self._layout_transmission() |
---|
| 194 | self._layout_temperature() |
---|
| 195 | self._layout_position() |
---|
| 196 | self._layout_orientation() |
---|
| 197 | self._layout_details() |
---|
| 198 | self._layout_button() |
---|
| 199 | self.boxsizer_sample.AddMany([(self.name_sizer, 0, |
---|
| 200 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 201 | (self.id_sizer, 0, |
---|
| 202 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 203 | (self.thickness_sizer, 0, |
---|
| 204 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 205 | (self.transmission_sizer, 0, |
---|
| 206 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 207 | (self.temperature_sizer, 0, |
---|
| 208 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 209 | (self.position_sizer, 0, |
---|
| 210 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 211 | (self.orientation_sizer, 0, |
---|
| 212 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
| 213 | (self.details_sizer, 0, |
---|
| 214 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
| 215 | self.main_sizer.AddMany([(self.boxsizer_sample, 0, wx.ALL, 10), |
---|
| 216 | (self.button_sizer, 0, |
---|
| 217 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
| 218 | |
---|
| 219 | self.SetSizer(self.main_sizer) |
---|
| 220 | self.SetAutoLayout(True) |
---|
| 221 | |
---|
| 222 | def reset_sample(self): |
---|
| 223 | """ |
---|
| 224 | Put initial values of the sample back to the current sample |
---|
| 225 | """ |
---|
| 226 | self._sample.name = self._reset_sample.name |
---|
| 227 | self._sample.ID = self._reset_sample.ID |
---|
| 228 | self._sample.thickness = self._reset_sample.thickness |
---|
| 229 | self._sample.thickness_unit = self._reset_sample.thickness_unit |
---|
| 230 | self._sample.transmission = self._reset_sample.transmission |
---|
| 231 | self._sample.temperature = self._reset_sample.temperature |
---|
| 232 | self._sample.temperature_unit = self._reset_sample.temperature_unit |
---|
| 233 | |
---|
| 234 | self._sample.position.x = self._reset_sample.position.x |
---|
| 235 | self._sample.position.y = self._reset_sample.position.y |
---|
| 236 | self._sample.position.z = self._reset_sample.position.x |
---|
| 237 | self._sample.position_unit = self._reset_sample.position_unit |
---|
| 238 | |
---|
| 239 | self._sample.orientation.x = self._reset_sample.orientation.x |
---|
| 240 | self._sample.orientation.y = self._reset_sample.orientation.y |
---|
| 241 | self._sample.orientation.z = self._reset_sample.orientation.x |
---|
| 242 | self._sample.orientation_unit = self._reset_sample.orientation_unit |
---|
| 243 | |
---|
| 244 | self._sample.details = self._reset_sample.details |
---|
| 245 | |
---|
| 246 | def set_manager(self, manager): |
---|
| 247 | """ |
---|
| 248 | Set manager of this window |
---|
| 249 | """ |
---|
| 250 | self.manager = manager |
---|
| 251 | |
---|
| 252 | def set_values(self): |
---|
| 253 | """ |
---|
| 254 | take the sample values of the current data and display them |
---|
| 255 | through the panel |
---|
| 256 | """ |
---|
| 257 | sample = self._sample |
---|
| 258 | #Name |
---|
| 259 | self.sample_name_tcl.SetValue(str(sample.name)) |
---|
| 260 | #id |
---|
| 261 | self.id_tcl.SetValue(str(sample.ID)) |
---|
| 262 | #thickness |
---|
| 263 | self.thickness_tcl.SetValue(str(sample.thickness)) |
---|
| 264 | self.thickness_unit_tcl.SetValue(str(sample.thickness_unit)) |
---|
| 265 | #transmission |
---|
| 266 | self.transmission_tcl.SetValue(str(sample.transmission)) |
---|
| 267 | #temperature |
---|
| 268 | self.temperature_tcl.SetValue(str(sample.temperature)) |
---|
| 269 | self.temperature_unit_tcl.SetValue(str(sample.temperature_unit)) |
---|
| 270 | #position |
---|
| 271 | x, y, z = sample.position.x, sample.position.y , sample.position.z |
---|
| 272 | self.x_position_tcl.SetValue(str(x)) |
---|
| 273 | self.y_position_tcl.SetValue(str(y)) |
---|
| 274 | self.z_position_tcl.SetValue(str(z)) |
---|
| 275 | self.position_unit_tcl.SetValue(str(sample.position_unit)) |
---|
| 276 | #orientation |
---|
| 277 | x, y, z = sample.orientation.x, sample.orientation.y , sample.orientation.z |
---|
| 278 | self.x_orientation_tcl.SetValue(str(x)) |
---|
| 279 | self.y_orientation_tcl.SetValue(str(y)) |
---|
| 280 | self.z_orientation_tcl.SetValue(str(z)) |
---|
| 281 | self.orientation_unit_tcl.SetValue(str(sample.orientation_unit)) |
---|
| 282 | |
---|
| 283 | self.set_details(sample) |
---|
| 284 | |
---|
| 285 | def set_details(self, sample): |
---|
| 286 | """ |
---|
| 287 | print details on the current sample |
---|
| 288 | """ |
---|
| 289 | #detail |
---|
| 290 | msg = '' |
---|
| 291 | if sample.details is not None or sample.details: |
---|
| 292 | for item in sample.details: |
---|
| 293 | msg += " %s\n" % item |
---|
| 294 | self.details_tcl.SetValue(str(msg)) |
---|
| 295 | |
---|
| 296 | def get_sample(self): |
---|
| 297 | """ |
---|
| 298 | return the current sample |
---|
| 299 | """ |
---|
| 300 | return self._sample |
---|
| 301 | |
---|
| 302 | def get_notes(self): |
---|
| 303 | """ |
---|
| 304 | return notes |
---|
| 305 | """ |
---|
| 306 | return self._notes |
---|
| 307 | |
---|
| 308 | def on_change_name(self): |
---|
| 309 | """ |
---|
| 310 | Change name |
---|
| 311 | """ |
---|
| 312 | #Change the name of the sample |
---|
| 313 | name = self.sample_name_tcl.GetValue().lstrip().rstrip() |
---|
| 314 | if name == "" or name == str(None): |
---|
| 315 | name = None |
---|
| 316 | if self._sample.name != name: |
---|
| 317 | self._notes += "Change sample 's " |
---|
| 318 | self._notes += "name from %s to %s \n"%(self._sample.name, name) |
---|
| 319 | self._sample.name = name |
---|
| 320 | |
---|
| 321 | def on_change_id(self): |
---|
| 322 | """ |
---|
| 323 | Change id of the sample |
---|
| 324 | """ |
---|
| 325 | #Change id |
---|
| 326 | id = self.id_tcl.GetValue().lstrip().rstrip() |
---|
| 327 | self._sample.ID = id |
---|
| 328 | self._notes += " Change ID from" |
---|
| 329 | self._notes += " %s to %s \n"%(self._sample.ID, id) |
---|
| 330 | |
---|
| 331 | def on_change_thickness(self): |
---|
| 332 | """ |
---|
| 333 | Change thickness |
---|
| 334 | """ |
---|
| 335 | #Change thickness |
---|
| 336 | thickness = self.thickness_tcl.GetValue().lstrip().rstrip() |
---|
| 337 | self._sample.thickness = thickness |
---|
| 338 | self._notes += " Change thickness from" |
---|
| 339 | self._notes += " %s to %s \n"%(self._sample.thickness, thickness) |
---|
| 340 | |
---|
| 341 | def on_change_transmission(self): |
---|
| 342 | """ |
---|
| 343 | Change transmission |
---|
| 344 | """ |
---|
| 345 | #Change transmission |
---|
| 346 | transmission = self.transmission_tcl.GetValue().lstrip().rstrip() |
---|
| 347 | if self._sample.transmission != transmission: |
---|
| 348 | self._notes += " Change transmission from" |
---|
| 349 | self._notes += " %s to %s \n"%(self._sample.transmission, transmission) |
---|
| 350 | self._sample.transmission = transmission |
---|
| 351 | |
---|
| 352 | def on_change_temperature(self): |
---|
| 353 | """ |
---|
| 354 | Change temperature |
---|
| 355 | """ |
---|
| 356 | #Change temperature |
---|
| 357 | temperature = self.temperature_tcl.GetValue().lstrip().rstrip() |
---|
| 358 | self._sample.temperature = temperature |
---|
| 359 | self._notes += " Change temperature from" |
---|
| 360 | self._notes += " %s to %s \n"%(self._sample.temperature, temperature) |
---|
| 361 | #change temperature unit |
---|
| 362 | unit = self.temperature_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 363 | if self._sample.temperature_unit != unit: |
---|
| 364 | self._notes += " Change temperature's unit from " |
---|
| 365 | self._notes += "%s to %s"%(self._sample.temperature_unit, unit) |
---|
| 366 | self._sample.temperature_unit = unit |
---|
| 367 | |
---|
| 368 | def on_change_position(self): |
---|
| 369 | """ |
---|
| 370 | Change position |
---|
| 371 | """ |
---|
| 372 | #Change x coordinate |
---|
| 373 | x_position = self.x_position_tcl.GetValue().lstrip().rstrip() |
---|
| 374 | if x_position == "" or x_position == str(None): |
---|
| 375 | x_position = None |
---|
| 376 | else: |
---|
| 377 | if check_float(self.x_position_tcl): |
---|
| 378 | if self._sample.position.x != float(x_position) : |
---|
| 379 | self._notes += "Change x of position from " |
---|
| 380 | self._notes += "%s to %s \n"%(self._sample.position.x, x_position) |
---|
| 381 | self._sample.position.x = float(x_position) |
---|
| 382 | else: |
---|
| 383 | self._notes += "Error: Expected a float for the position 's x " |
---|
| 384 | self._notes += "won't changes x position from " |
---|
| 385 | self._notes += "%s to %s"%(self._sample.position.x, x_position) |
---|
| 386 | #Change y coordinate |
---|
| 387 | y_position = self.y_position_tcl.GetValue().lstrip().rstrip() |
---|
| 388 | if y_position == "" or y_position == str(None): |
---|
| 389 | y_position = None |
---|
| 390 | self._sample.position.y = y_position |
---|
| 391 | else: |
---|
| 392 | if check_float(self.y_position_tcl): |
---|
| 393 | if self._sample.position.y != float(y_position): |
---|
| 394 | self._notes += "Change y of position from " |
---|
| 395 | self._notes += "%s to %s \n"%(self._sample.position.y, y_position) |
---|
| 396 | self._sample.position.y = float(y_position) |
---|
| 397 | else: |
---|
| 398 | self._notes += "Error: Expected a float for the beam size's y " |
---|
| 399 | self._notes += "won't changes y position from " |
---|
| 400 | self._notes += "%s to %s"%(self._sample.position.y, y_position) |
---|
| 401 | #Change z coordinate |
---|
| 402 | z_position = self.z_position_tcl.GetValue().lstrip().rstrip() |
---|
| 403 | if z_position == "" or z_position == str(None): |
---|
| 404 | z_position = None |
---|
| 405 | self._sample.position.z = z_position |
---|
| 406 | else: |
---|
| 407 | if check_float(self.z_position_tcl): |
---|
| 408 | if self._sample.position.z != float(z_position): |
---|
| 409 | self._notes += "Change z of position from " |
---|
| 410 | self._notes += "%s to %s \n"%(self._sample.position.z, z_position) |
---|
| 411 | self._sample.position.z = float(z_position) |
---|
| 412 | else: |
---|
| 413 | self._notes += "Error: Expected a float for position's x " |
---|
| 414 | self._notes += "won't changes z position from " |
---|
| 415 | self._notes += "%s to %s"%(self._sample.position.z, z_position) |
---|
| 416 | #change the beam center unit |
---|
| 417 | unit = self.position_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 418 | if self._sample.position_unit != unit: |
---|
| 419 | self._notes += " Change position's unit from " |
---|
| 420 | self._notes += "%s to %s"%(self._sample.position_unit, unit) |
---|
| 421 | |
---|
| 422 | def on_change_orientation(self): |
---|
| 423 | """ |
---|
| 424 | Change orientation |
---|
| 425 | """ |
---|
| 426 | #Change x coordinate |
---|
| 427 | x_orientation = self.x_orientation_tcl.GetValue().lstrip().rstrip() |
---|
| 428 | if x_orientation == "" or x_orientation == str(None): |
---|
| 429 | x_orientation = None |
---|
| 430 | else: |
---|
| 431 | if check_float(self.x_orientation_tcl): |
---|
| 432 | if self._sample.orientation.x != float(x_orientation) : |
---|
| 433 | self._notes += "Change x of orientation from " |
---|
| 434 | self._notes += "%s to %s \n"%(self._sample.orientation.x, |
---|
| 435 | x_orientation) |
---|
| 436 | self._sample.orientation.x = float(x_orientation) |
---|
| 437 | else: |
---|
| 438 | self._notes += "Error: Expected a float for orientation 's x " |
---|
| 439 | self._notes += "won't changes x orientation from " |
---|
| 440 | self._notes += "%s to %s"%(self._sample.orientation.x, x_orientation) |
---|
| 441 | #Change y coordinate |
---|
| 442 | y_orientation = self.y_orientation_tcl.GetValue().lstrip().rstrip() |
---|
| 443 | if y_orientation == "" or y_orientation == str(None): |
---|
| 444 | y_orientation = None |
---|
| 445 | self._sample.orientation.y = y_orientation |
---|
| 446 | else: |
---|
| 447 | if check_float(self.y_orientation_tcl): |
---|
| 448 | if self._sample.orientation.y != float(y_orientation): |
---|
| 449 | self._notes += "Change y of orientation from " |
---|
| 450 | self._notes += "%s to %s \n"%(self._sample.orientation.y, y_orientation) |
---|
| 451 | self._sample.orientation.y = float(y_orientation) |
---|
| 452 | else: |
---|
| 453 | self._notes += "Error: Expected a float for orientation's y " |
---|
| 454 | self._notes += "won't changes y orientation from " |
---|
| 455 | self._notes += "%s to %s"%(self._sample.orientation.y, y_orientation) |
---|
| 456 | #Change z coordinate |
---|
| 457 | z_orientation = self.z_orientation_tcl.GetValue().lstrip().rstrip() |
---|
| 458 | if z_orientation == "" or z_orientation == str(None): |
---|
| 459 | z_orientation = None |
---|
| 460 | self._sample.orientation.z = z_orientation |
---|
| 461 | else: |
---|
| 462 | if check_float(self.z_orientation_tcl): |
---|
| 463 | if self._sample.orientation.z != float(z_orientation): |
---|
| 464 | self._notes += "Change z of orientation from " |
---|
| 465 | self._notes += "%s to %s \n"%(self._sample.orientation.z, z_orientation) |
---|
| 466 | self._sample.orientation.z = float(z_orientation) |
---|
| 467 | else: |
---|
| 468 | self._notes += "Error: Expected a float for orientation 's x " |
---|
| 469 | self._notes += "won't changes z orientation from " |
---|
| 470 | self._notes += "%s to %s"%(self._sample.orientation.z, z_orientation) |
---|
| 471 | #change the beam center unit |
---|
| 472 | unit = self.orientation_unit_tcl.GetValue().lstrip().rstrip() |
---|
| 473 | if self._sample.orientation_unit != unit: |
---|
| 474 | self._notes += " Change orientation's unit from " |
---|
| 475 | self._notes += "%s to %s"%(self._sample.orientation_unit, unit) |
---|
| 476 | |
---|
| 477 | def on_change_details(self): |
---|
| 478 | """ |
---|
| 479 | Change details |
---|
| 480 | """ |
---|
| 481 | #Change details |
---|
| 482 | details = self.details_tcl.GetValue().lstrip().rstrip() |
---|
| 483 | msg = "" |
---|
| 484 | if self._sample.details is not None or self._sample.details: |
---|
| 485 | for item in self._sample.details: |
---|
| 486 | if item != details: |
---|
| 487 | msg += " %s\n" % item |
---|
| 488 | self._notes += " Change details from" |
---|
| 489 | self._notes += " %s to %s \n"%(msg, details) |
---|
| 490 | self._sample.details.append(details) |
---|
| 491 | |
---|
| 492 | def on_click_apply(self, event): |
---|
| 493 | """ |
---|
| 494 | Apply user values to the sample |
---|
| 495 | """ |
---|
| 496 | self.on_change_name() |
---|
| 497 | self.on_change_id() |
---|
| 498 | self.on_change_thickness() |
---|
| 499 | self.on_change_transmission() |
---|
| 500 | self.on_change_temperature() |
---|
| 501 | self.on_change_position() |
---|
| 502 | self.on_change_orientation() |
---|
| 503 | self.on_change_details() |
---|
| 504 | self.set_details(self._sample) |
---|
| 505 | if self.manager is not None: |
---|
| 506 | self.manager.set_sample(self._sample) |
---|
| 507 | |
---|
| 508 | def on_click_cancel(self, event): |
---|
| 509 | """ |
---|
| 510 | leave the sample as it is and close |
---|
| 511 | """ |
---|
| 512 | self.reset_sample() |
---|
| 513 | self.set_values() |
---|
| 514 | if self.manager is not None: |
---|
| 515 | self.manager.set_sample(self._sample, self._notes) |
---|
| 516 | |
---|
| 517 | if __name__ =="__main__": |
---|
| 518 | |
---|
| 519 | app = wx.App() |
---|
[ad6f597] | 520 | from DataLoader.data_info import Sample |
---|
| 521 | sample = Sample() |
---|
| 522 | dlg = SampleDialog(sample=sample) |
---|
[91f151a] | 523 | dlg.ShowModal() |
---|
| 524 | app.MainLoop() |
---|
| 525 | |
---|