Changeset 9ce7641c in sasview for invariantview/perspectives/invariant
- Timestamp:
- Mar 17, 2010 9:01:43 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- acf8bd15
- Parents:
- 90e5ca1
- Location:
- invariantview/perspectives/invariant
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
invariantview/perspectives/invariant/invariant_panel.py
rc8570c3 r9ce7641c 8 8 9 9 from sans.invariant import invariant 10 11 10 from sans.guiframe.utils import format_number, check_float 12 11 from sans.guicomm.events import NewPlotEvent, StatusEvent 13 12 from invariant_details import InvariantDetailsWindow 14 13 # The minimum q-value to be used when extrapolating 15 14 Q_MINIMUM = 1e-5 … … 24 23 #default value for the scale 25 24 SCALE = 1.0 25 #default value of the contrast 26 CONTRAST = 1.0 26 27 #Invariant panel size 27 28 _BOX_WIDTH = 76 28 _SCALE = 1e-6 29 #scale to use for a bar of value zero 30 RECTANGLE_SCALE = 0.0001 29 31 30 32 if sys.platform.count("win32")>0: … … 39 41 FONT_VARIANT = 1 40 42 43 class InvariantContainer(wx.Object): 44 def __init__(self): 45 #invariant at low range 46 self.qstar_low = None 47 #invariant at low range error 48 self.qstar_low_err = None 49 #invariant 50 self.qstar = None 51 #invariant error 52 self.qstar_err = None 53 #invariant at high range 54 self.qstar_high = None 55 #invariant at high range error 56 self.qstar_high_err = None 57 #invariant total 58 self.qstar_total = None 59 #invariant error 60 self.qstar_total_err = None 61 #scale 62 self.qstar_low_scale = RECTANGLE_SCALE 63 self.qstar_scale = RECTANGLE_SCALE 64 self.qstar_high_scale = RECTANGLE_SCALE 65 41 66 class InvariantPanel(wx.ScrolledWindow): 42 67 """ … … 61 86 #Data uses for computation 62 87 self._data = data 88 #container of invariant value 89 self.inv_container = None 63 90 #Draw the panel 64 91 self._do_layout() 65 self.SetScrollbars(20,20,25,65) 66 self.SetAutoLayout(True) 67 self.Layout() 68 92 69 93 def set_data(self, data): 70 94 """ … … 77 101 data_qmin = min (self._data.x) 78 102 data_qmax = max (self._data.x) 79 data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) 103 self.data_name_tcl.SetValue(str(data_name)) 104 self.data_min_tcl.SetLabel(str(data_qmin)) 105 self.data_max_tcl.SetLabel(str(data_qmax)) 106 107 def set_manager(self, manager): 108 """ 109 set value for the manager 110 """ 111 self._manager = manager 112 113 def get_background(self): 114 """ 115 @return the background textcrtl value as a float 116 """ 117 background = self.background_tcl.GetValue().lstrip().rstrip() 118 if background == "": 119 raise ValueError, "Need a background" 120 if check_float(self.background_tcl): 121 return float(background) 122 else: 123 raise ValueError, "Receive invalid value for background : %s"%(background) 124 125 def get_scale(self): 126 """ 127 @return the scale textcrtl value as a float 128 """ 129 scale = self.scale_tcl.GetValue().lstrip().rstrip() 130 if scale == "": 131 raise ValueError, "Need a background" 132 if check_float(self.scale_tcl): 133 return float(scale) 134 else: 135 raise ValueError, "Receive invalid value for background : %s"%(scale) 136 137 def get_contrast(self): 138 """ 139 @return the contrast textcrtl value as a float 140 """ 141 par_str = self.contrast_tcl.GetValue().strip() 142 contrast = None 143 if par_str !="" and check_float(self.contrast_tcl): 144 contrast = float(par_str) 145 return contrast 146 147 def get_extrapolation_type(self, low_q, high_q): 148 """ 149 """ 150 extrapolation = None 151 if low_q and not high_q: 152 extrapolation = "low" 153 elif not low_q and high_q: 154 extrapolation = "high" 155 elif low_q and high_q: 156 extrapolation = "both" 157 return extrapolation 80 158 81 self.data_name_txt.SetLabel('Data : '+str(data_name)) 82 self.data_range_value_txt.SetLabel(str(data_range)) 83 84 def set_manager(self, manager): 85 """ 86 set value for the manager 87 """ 88 self._manager = manager 159 def get_porod_const(self): 160 """ 161 @return the porod constant textcrtl value as a float 162 """ 163 par_str = self.porod_constant_tcl.GetValue().strip() 164 porod_const = None 165 if par_str !="" and check_float(self.porod_constant_tcl): 166 porod_const = float(par_str) 167 return porod_const 168 169 def get_volume(self, inv, contrast, extrapolation): 170 """ 171 """ 172 if contrast is not None: 173 try: 174 v, dv = inv.get_volume_fraction_with_error(contrast=contrast, 175 extrapolation=extrapolation) 176 self.volume_tcl.SetValue(format_number(v)) 177 self.volume_err_tcl.SetValue(format_number(dv)) 178 except: 179 raise 180 msg= "Error occurred computing volume fraction: %s"%sys.exc_value 181 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 182 183 def get_surface(self, inv, contrast, porod_const, extrapolation): 184 """ 185 """ 186 if contrast is not None and porod_const is not None: 187 try: 188 s, ds = inv.get_surface_with_error(contrast=contrast, 189 porod_const=porod_const, 190 extrapolation=extrapolation) 191 self.surface_tcl.SetValue(format_number(s)) 192 self.surface_err_tcl.SetValue(format_number(ds)) 193 except: 194 msg= "Error occurred computing specific surface: %s"%sys.exc_value 195 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 196 197 def get_total_qstar(self, inv, extrapolation): 198 """ 199 """ 200 try: 201 qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) 202 self.invariant_total_tcl.SetValue(format_number(qstar_total)) 203 self.invariant_total_err_tcl.SetValue(format_number(qstar_total)) 204 self.inv_container.qstar_total = qstar_total 205 self.inv_container.qstar_total_err = qstar_total_err 206 check_float(self.invariant_total_tcl) 207 check_float(self.invariant_total_err_tcl) 208 except: 209 msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value 210 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 211 212 def get_low_qstar(self, inv, npts_low, low_q=False): 213 """ 214 """ 215 if low_q: 216 try: 217 qstar_low, qstar_low_err = inv.get_qstar_low() 218 self.inv_container.qstar_low = qstar_low 219 self.inv_container.qstar_low_err = qstar_low_err 220 extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) 221 power_low = inv.get_extrapolation_power(range='low') 222 self.power_low_tcl.SetValue(str(power_low)) 223 self._manager.plot_theory(data=extrapolated_data, 224 name="Low-Q extrapolation") 225 except: 226 msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value 227 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 228 else: 229 self._manager.plot_theory(name="Low-Q extrapolation") 230 231 def get_high_qstar(self, inv, high_q=False): 232 """ 233 """ 234 if high_q: 235 try: 236 qstar_high, qstar_high_err = inv.get_qstar_high() 237 self.inv_container.qstar_high = qstar_high 238 self.inv_container.qstar_high_err = qstar_high_err 239 power_high = inv.get_extrapolation_power(range='high') 240 self.power_high_tcl.SetValue(str(power_high)) 241 high_out_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) 242 self._manager.plot_theory(data=high_out_data, 243 name="High-Q extrapolation") 244 except: 245 msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value 246 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 247 else: 248 self._manager.plot_theory(name="High-Q extrapolation") 249 250 def get_qstar(self, inv): 251 """ 252 """ 253 qstar, qstar_err = inv.get_qstar_with_error() 254 self.inv_container.qstar = qstar 255 self.inv_container.qstar_err = qstar_err 256 257 def set_extrapolation_low(self, inv, low_q=False): 258 """ 259 @return float value necessary to compute invariant a low q 260 """ 261 #get funtion 262 if self.guinier.GetValue(): 263 function_low = "guinier" 264 # get the function 265 power_low = None 266 if self.power_law_low.GetValue(): 267 function_low = "power_law" 268 if self.fit_low_cbox.GetValue(): 269 #set value of power_low to none to allow fitting 270 power_low = None 271 else: 272 power_low = self.power_low_tcl.GetValue().lstrip().rstrip() 273 if check_float(self.power_low_tcl): 274 power_low = float(power_low) 275 else: 276 if low_q : 277 #Raise error only when qstar at low q is requested 278 msg = "Expect float for power at low q , got %s"%(power_low) 279 raise ValueError, msg 280 281 #Get the number of points to extrapolated 282 npts_low = self.npts_low_tcl.GetValue().lstrip().rstrip() 283 if check_float(self.npts_low_tcl): 284 npts_low = float(npts_low) 285 else: 286 if low_q: 287 msg = "Expect float for number of points at low q , got %s"%(npts_low) 288 raise ValueError, msg 289 #Set the invariant calculator 290 inv.set_extrapolation(range="low", npts=npts_low, 291 function=function_low, power=power_low) 292 return inv, npts_low 293 294 def set_extrapolation_high(self, inv, high_q=False): 295 """ 296 @return float value necessary to compute invariant a high q 297 """ 298 function_high = "power_law" 299 power_high = None 300 if self.power_law_high.GetValue(): 301 function_high = "power_law" 302 if self.fit_high_cbox.GetValue(): 303 #set value of power_high to none to allow fitting 304 power_high = None 305 else: 306 power_high = self.power_high_tcl.GetValue().lstrip().rstrip() 307 if check_float(self.power_high_tcl): 308 power_high = float(power_high) 309 else: 310 if high_q : 311 #Raise error only when qstar at high q is requested 312 msg = "Expect float for power at high q , got %s"%(power_high) 313 raise ValueError, msg 314 315 npts_high = self.npts_high_tcl.GetValue().lstrip().rstrip() 316 if check_float(self.npts_high_tcl): 317 npts_high = float(npts_high) 318 else: 319 if high_q: 320 msg = "Expect float for number of points at high q , got %s"%(npts_high) 321 raise ValueError, msg 322 inv.set_extrapolation(range="high", npts=npts_high, 323 function=function_high, power=power_high) 324 return inv, npts_high 325 326 def display_details(self, event): 327 """ 328 open another panel for more details on invariant calculation 329 """ 330 panel = InvariantDetailsWindow(parent=self.parent, 331 qstar_container=self.inv_container) 89 332 90 333 def compute_invariant(self, event): … … 92 335 compute invariant 93 336 """ 337 if self._data is None: 338 return 94 339 #clear outputs textctrl 95 340 self._reset_output() 96 background = self.background_ctl.GetValue().lstrip().rstrip() 97 scale = self.scale_ctl.GetValue().lstrip().rstrip() 98 if background == "": 99 background = 0 100 if scale == "": 101 scale = 1 102 if check_float(self.background_ctl) and check_float(self.scale_ctl): 103 inv = invariant.InvariantCalculator(data=self._data, 104 background=float(background), 105 scale=float(scale)) 106 107 #Get the number of points to extrapolated 108 npts_low = self.npts_low_ctl.GetValue() 109 if check_float(self.npts_low_ctl): 110 npts_low = float(npts_low) 111 power_low = self.power_low_ctl.GetValue() 112 if check_float(self.power_low_ctl): 113 power_low = float(power_low) 114 npts_high = self.npts_high_ctl.GetValue() 115 if check_float(self.npts_high_ctl): 116 npts_high = float(npts_high) 117 power_high = self.power_high_ctl.GetValue() 118 if check_float(self.power_high_ctl): 119 power_high = float(power_high) 120 # get the function 121 if self.power_law_low.GetValue(): 122 function_low = "power_law" 123 if self.guinier.GetValue(): 124 function_low = "guinier" 125 #power_low = None 126 127 function_high = "power_law" 128 if self.power_law_high.GetValue(): 129 function_high = "power_law" 130 #check the type of extrapolation 131 extrapolation = None 132 low_q = self.enable_low_cbox.GetValue() 133 high_q = self.enable_high_cbox.GetValue() 134 if low_q and not high_q: 135 extrapolation = "low" 136 elif not low_q and high_q: 137 extrapolation = "high" 138 elif low_q and high_q: 139 extrapolation = "both" 140 141 #Set the invariant calculator 142 inv.set_extrapolation(range="low", npts=npts_low, 143 function=function_low, power=power_low) 144 inv.set_extrapolation(range="high", npts=npts_high, 145 function=function_high, power=power_high) 146 #Compute invariant 147 try: 148 qstar, qstar_err = inv.get_qstar_with_error() 149 self.invariant_ctl.SetValue(format_number(qstar)) 150 self.invariant_err_ctl.SetValue(format_number(qstar)) 151 except: 152 msg= "Error occurred computing invariant: %s"%sys.exc_value 153 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 154 return 155 #Compute qstar extrapolated to low q range 156 #Clear the previous extrapolated plot 157 if low_q: 158 try: 159 qstar_low, qstar_low_err = inv.get_qstar_low() 160 self.invariant_low_ctl.SetValue(format_number(qstar_low)) 161 extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) 162 self._manager.plot_theory(data=extrapolated_data, 163 name="Low-Q extrapolation") 164 except: 165 msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value 166 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 167 else: 168 self._manager.plot_theory(name="Low-Q extrapolation") 169 170 if high_q: 171 try: 172 qstar_high, qstar_high_err = inv.get_qstar_high() 173 self.invariant_high_ctl.SetValue(format_number(qstar_high)) 174 high_out_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) 175 self._manager.plot_theory(data=high_out_data, 176 name="High-Q extrapolation") 177 except: 178 msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value 179 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 180 else: 181 self._manager.plot_theory(name="High-Q extrapolation") 182 183 try: 184 qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) 185 self.invariant_total_ctl.SetValue(format_number(qstar_total)) 186 self.invariant_total_err_ctl.SetValue(format_number(qstar_total)) 187 check_float(self.invariant_total_ctl) 188 check_float(self.invariant_total_err_ctl) 189 except: 190 msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value 191 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 192 193 # Parse additional parameters 194 par_str = self.porod_const_ctl.GetValue().strip() 195 porod_const = None 196 if len(par_str)>0 and check_float(self.porod_const_ctl): 197 porod_const = float(par_str) 198 199 par_str = self.contrast_ctl.GetValue().strip() 200 contrast = None 201 if len(par_str)>0 and check_float(self.contrast_ctl): 202 contrast = float(par_str) 203 204 if contrast is not None: 205 try: 206 v, dv = inv.get_volume_fraction_with_error(contrast=contrast, 207 extrapolation=extrapolation) 208 self.volume_ctl.SetValue(format_number(v)) 209 self.volume_err_ctl.SetValue(format_number(dv)) 210 except: 211 msg= "Error occurred computing volume fraction: %s"%sys.exc_value 212 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 213 214 if contrast is not None and porod_const is not None: 215 try: 216 s, ds = inv.get_surface_with_error(contrast=contrast, 217 porod_const=porod_const, 218 extrapolation=extrapolation) 219 self.surface_ctl.SetValue(format_number(s)) 220 self.surface_err_ctl.SetValue(format_number(ds)) 221 except: 222 msg= "Error occurred computing specific surface: %s"%sys.exc_value 223 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 224 225 else: 226 msg= "A float value is required for background and scale" 341 try: 342 background = self.get_background() 343 scale = self.get_scale() 344 except: 345 msg= "Invariant Error: %s"%(sys.exc_value) 227 346 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 228 347 return 229 348 349 low_q = self.enable_low_cbox.GetValue() 350 high_q = self.enable_high_cbox.GetValue() 351 #set invariant calculator 352 inv = invariant.InvariantCalculator(data=self._data, 353 background=background, 354 scale=scale) 355 inv, npts_low = self.set_extrapolation_low(inv=inv, low_q=low_q) 356 inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) 357 #check the type of extrapolation 358 extrapolation = self.get_extrapolation_type(low_q=low_q, high_q=high_q) 359 #prepare a new container to put result of invariant 360 self.inv_container = InvariantContainer() 361 #Compute invariant 362 try: 363 self.get_qstar(inv=inv) 364 except: 365 msg= "Error occurred computing invariant: %s"%sys.exc_value 366 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 367 return 368 #Compute qstar extrapolated to low q range 369 self.get_low_qstar(inv=inv, npts_low=npts_low, low_q=low_q) 370 #Compute qstar extrapolated to high q range 371 self.get_high_qstar(inv=inv, high_q=high_q) 372 #Compute qstar extrapolated to total q range and set value to txtcrtl 373 self.get_total_qstar(inv=inv, extrapolation=extrapolation) 374 # Parse additional parameters 375 porod_const = self.get_porod_const() 376 contrast = self.get_contrast() 377 #Compute volume and set value to txtcrtl 378 self.get_volume(inv=inv, contrast=contrast, extrapolation=extrapolation) 379 #compute surface and set value to txtcrtl 380 self.get_surface(inv=inv, contrast=contrast, porod_const=porod_const, 381 extrapolation=extrapolation) 382 #enable the button_ok for more details 383 self.button_ok.Enable() 384 230 385 def _reset_output(self): 231 386 """ 232 387 clear outputs textcrtl 233 388 """ 234 self.invariant_ctl.Clear() 235 self.invariant_err_ctl.Clear() 236 self.invariant_low_ctl.Clear() 237 self.invariant_high_ctl.Clear() 238 self.invariant_total_ctl.Clear() 239 self.invariant_total_err_ctl.Clear() 240 self.volume_ctl.Clear() 241 self.volume_err_ctl.Clear() 242 self.surface_ctl.Clear() 243 self.surface_err_ctl.Clear() 244 245 def _do_layout(self): 246 """ 247 Draw window content 248 """ 249 unit_invariant = '[1/cm][1/A]' 250 unit_volume = '' 251 unit_surface = '' 252 uncertainty = "+/-" 253 npts_hint_txt = "Number of points to consider during extrapolation." 389 self.invariant_total_tcl.Clear() 390 self.invariant_total_err_tcl.Clear() 391 self.volume_tcl.Clear() 392 self.volume_err_tcl.Clear() 393 self.surface_tcl.Clear() 394 self.surface_err_tcl.Clear() 395 396 def _define_structure(self): 397 """ 398 Define main sizers needed for this panel 399 """ 400 ## Box sizers must be defined first before defining buttons/textctrls (MAC). 401 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 402 #Sizer related to outputs 403 outputs_box = wx.StaticBox(self, -1, "Outputs") 404 self.outputs_sizer = wx.StaticBoxSizer(outputs_box, wx.VERTICAL) 405 self.outputs_sizer.SetMinSize((PANEL_WIDTH,-1)) 406 #Sizer related to data 407 data_name_box = wx.StaticBox(self, -1, "I(q) Data Source") 408 self.data_name_boxsizer = wx.StaticBoxSizer(data_name_box, wx.VERTICAL) 409 self.data_name_boxsizer.SetMinSize((PANEL_WIDTH,-1)) 410 self.hint_msg_sizer = wx.BoxSizer(wx.HORIZONTAL) 411 self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) 412 self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL) 413 #Sizer related to background 414 self.background_sizer = wx.BoxSizer(wx.HORIZONTAL) 415 #Sizer related to scale 416 self.scale_sizer = wx.BoxSizer(wx.HORIZONTAL) 417 #Sizer related to contrast 418 self.contrast_sizer = wx.BoxSizer(wx.HORIZONTAL) 419 #Sizer related to Porod Constant 420 self.porod_constant_sizer = wx.BoxSizer(wx.HORIZONTAL) 421 extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") 422 self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box, 423 wx.VERTICAL) 424 self.extrapolation_sizer.SetMinSize((PANEL_WIDTH,-1)) 425 self.extrapolation_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) 426 self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL) 427 self.extrapolation_low_high_sizer = wx.BoxSizer(wx.HORIZONTAL) 428 #Sizer related to extrapolation at low q range 429 low_q_box = wx.StaticBox(self, -1, "Low Q") 430 self.low_extrapolation_sizer = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) 431 self.low_q_sizer = wx.GridBagSizer(5,5) 432 #Sizer related to extrapolation at low q range 433 high_q_box = wx.StaticBox(self, -1, "High Q") 434 self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) 435 self.high_q_sizer = wx.GridBagSizer(5,5) 436 #sizer to define outputs 437 self.volume_surface_sizer = wx.GridBagSizer(5,5) 438 #Sizer related to invariant output 439 self.invariant_sizer = wx.GridBagSizer(4, 4) 440 #Sizer related to button 441 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 442 443 def _layout_data_name(self): 444 """ 445 Draw widgets related to data's name 446 """ 447 #Sizer hint 448 hint_msg = "Load Data then right click to add the data on this panel! " 449 hint_msg_txt = wx.StaticText(self, -1, hint_msg) 450 hint_msg_txt.SetForegroundColour("red") 451 self.hint_msg_sizer.Add(hint_msg_txt) 452 #Data name [string] 453 data_name_txt = wx.StaticText(self, -1, 'Data : ') 454 455 self.data_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) 456 self.data_name_tcl.SetToolTipString("Data's name.") 457 self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), 458 (self.data_name_tcl, 0, wx.EXPAND)]) 459 #Data range [string] 460 data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') 461 data_min_txt = wx.StaticText(self, -1, 'Min : ') 462 self.data_min_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 463 self.data_min_tcl.SetToolTipString("The minimum value of q range.") 464 self.data_min_tcl.SetEditable(False) 465 data_max_txt = wx.StaticText(self, -1, 'Max : ') 466 self.data_max_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 467 self.data_max_tcl.SetToolTipString("The maximum value of q range.") 468 self.data_max_tcl.SetEditable(False) 469 self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), 470 (data_min_txt, 0, wx.RIGHT, 10), 471 (self.data_min_tcl, 0, wx.RIGHT, 10), 472 (data_max_txt, 0, wx.RIGHT, 10), 473 (self.data_max_tcl, 0, wx.RIGHT, 10)]) 474 self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 10), 475 (self.data_name_sizer, 0 , wx.RIGHT, 10), 476 (self.data_range_sizer, 0 , wx.ALL, 10)]) 477 478 def _layout_background(self): 479 """ 480 Draw widgets related to background 481 """ 482 background_txt = wx.StaticText(self, -1, 'Background : ') 483 self.background_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 484 self.background_tcl.SetValue(str(BACKGROUND)) 485 self.background_sizer.AddMany([(background_txt, 0, wx.LEFT|wx.RIGHT, 10), 486 (self.background_tcl)]) 487 def _layout_scale(self): 488 """ 489 Draw widgets related to scale 490 """ 491 scale_txt = wx.StaticText(self, -1, 'Scale : ') 492 self.scale_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 493 self.scale_tcl.SetValue(str(SCALE)) 494 self.scale_sizer.AddMany([(scale_txt, 0, wx.LEFT|wx.RIGHT, 10), 495 (self.scale_tcl, 0, wx.LEFT, 30)]) 496 497 def _layout_contrast(self): 498 """ 499 Draw widgets related to contrast 500 """ 501 contrast_txt = wx.StaticText(self, -1, 'Contrast : ') 502 self.contrast_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 503 self.contrast_tcl.SetValue(str(CONTRAST)) 504 self.contrast_sizer.AddMany([(contrast_txt, 0, wx.LEFT|wx.RIGHT, 10), 505 (self.contrast_tcl, 0, wx.LEFT, 15)]) 506 507 def _layout_porod_constant(self): 508 """ 509 Draw widgets related to porod constant 510 """ 511 porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:') 512 self.porod_constant_tcl = wx.TextCtrl(self, -1, 513 size=(_BOX_WIDTH, 20), style=0) 514 optional_txt = wx.StaticText(self, -1, '(Optional)') 515 self.porod_constant_sizer.AddMany([(porod_const_txt, 0, wx.LEFT, 10), 516 (self.porod_constant_tcl, 0, wx.LEFT, 0), 517 (optional_txt, 0, wx.LEFT, 10)]) 518 519 def _layout_extrapolation_low(self): 520 """ 521 Draw widgets related to extrapolation at low q range 522 """ 523 self.enable_low_cbox = wx.CheckBox(self, -1, "Extrapolate Low Q") 524 self.enable_low_cbox.SetValue(False) 525 self.fit_low_cbox = wx.CheckBox(self, -1, "Check to Fit Power") 526 self.fit_low_cbox.SetValue(False) 527 self.guinier = wx.RadioButton(self, -1, 'Guinier', 528 (10, 10),style=wx.RB_GROUP) 529 self.guinier.SetValue(True) 530 self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) 531 npts_low_txt = wx.StaticText(self, -1, 'Npts') 532 self.npts_low_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 533 self.npts_low_tcl.SetValue(str(NPTS)) 534 msg_hint = "Number of Q points to consider" 535 msg_hint +="while extrapolating the low-Q region" 536 self.npts_low_tcl.SetToolTipString(msg_hint) 537 power_txt = wx.StaticText(self, -1, 'Power') 538 self.power_low_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 539 self.power_low_tcl.SetValue(str(self.power_law_exponant)) 254 540 power_hint_txt = "Exponent to apply to the Power_law function." 255 256 sizer_input = wx.FlexGridSizer(5,4)#wx.GridBagSizer(5,5) 257 sizer_output = wx.GridBagSizer(5,5) 258 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 259 260 sizer1 = wx.BoxSizer(wx.VERTICAL) 261 sizer2 = wx.BoxSizer(wx.VERTICAL) 262 sizer3 = wx.BoxSizer(wx.HORIZONTAL) 263 264 sizer1.SetMinSize((_STATICBOX_WIDTH, -1)) 265 sizer2.SetMinSize((_STATICBOX_WIDTH, -1)) 266 sizer3.SetMinSize((_STATICBOX_WIDTH, -1)) 267 268 ## Box sizers must be defined first before defining buttons/textctrls (MAC). 269 vbox = wx.BoxSizer(wx.VERTICAL) 270 inputbox = wx.StaticBox(self, -1, "Input") 271 extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") 272 boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL) 273 high_q_box = wx.StaticBox(self, -1, "High Q") 274 boxsizer_high_q = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) 275 low_q_box = wx.StaticBox(self, -1, "Low Q") 276 boxsizer_low_q = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) 277 278 #---------inputs---------------- 279 data_name = "" 280 data_range = "[? - ?]" 281 if self._data is not None: 282 data_name = self._data.name 283 data_qmin = min (self._data.x) 284 data_qmax = max (self._data.x) 285 data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) 286 287 self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name)) 288 data_range_txt = wx.StaticText(self, -1, "Range : ") 289 self.data_range_value_txt = wx.StaticText(self, -1, str(data_range)) 290 291 background_txt = wx.StaticText(self, -1, 'Background') 292 self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 293 self.background_ctl.SetValue(str(BACKGROUND)) 294 self.background_ctl.SetToolTipString("Background to be subtracted from data.") 295 scale_txt = wx.StaticText(self, -1, 'Scale') 296 self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 297 self.scale_ctl.SetValue(str(SCALE)) 298 self.scale_ctl.SetToolTipString("Scaling factor to be applied to data.") 299 contrast_txt = wx.StaticText(self, -1, 'Contrast (Optional)') 300 self.contrast_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 301 msg_hint = "Enter a value for the contrast to compute the volume fraction" 302 self.contrast_ctl.SetToolTipString(str(msg_hint)) 303 porod_const_txt = wx.StaticText(self, -1, 'Porod Constant (Optional)') 304 self.porod_const_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 305 msg_hint ="Enter a Porod constant value to compute the specific surface" 306 self.porod_const_ctl.SetToolTipString(str(msg_hint)) 307 308 sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5) 309 sizer_input.Add((10,10), 0, wx.LEFT, 5) 310 sizer_input.Add(data_range_txt, 0, wx.LEFT, 10) 311 sizer_input.Add(self.data_range_value_txt) 312 sizer_input.Add(background_txt, 0, wx.ALL, 5) 313 sizer_input.Add(self.background_ctl, 0, wx.ALL, 5) 314 sizer_input.Add((10,10)) 315 sizer_input.Add((10,10)) 316 sizer_input.Add(scale_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 317 sizer_input.Add(self.scale_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 318 sizer_input.Add((10,10)) 319 sizer_input.Add((10,10)) 320 sizer_input.Add(contrast_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 321 sizer_input.Add(self.contrast_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 322 sizer_input.Add((10,10)) 323 sizer_input.Add((10,10)) 324 sizer_input.Add(porod_const_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 325 sizer_input.Add(self.porod_const_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) 326 #-------------Extrapolation sizer---------------- 327 sizer_low_q = wx.GridBagSizer(5,5) 328 329 self.enable_low_cbox = wx.CheckBox(self, -1, "Extrapolate low-Q") 330 self.enable_low_cbox.SetValue(False) 541 self.power_low_tcl.SetToolTipString(power_hint_txt) 542 iy = 0 543 ix = 0 544 self.low_q_sizer.Add(self.guinier,(iy, ix),(1,2), 545 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 546 iy += 1 547 ix = 0 548 self.low_q_sizer.Add(self.power_law_low,(iy, ix),(1,2), 549 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 550 # Parameter controls for power law 551 ix = 1 552 iy += 1 553 self.low_q_sizer.Add(self.fit_low_cbox,(iy, ix),(1,3), 554 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 555 ix = 1 556 iy += 1 557 self.low_q_sizer.Add(power_txt,(iy, ix),(1,1), 558 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 559 ix += 1 560 self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1,1), 561 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 562 iy += 1 563 ix = 1 564 self.low_q_sizer.Add(npts_low_txt,(iy, ix),(1,1), 565 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 566 ix += 1 567 self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1,1), 568 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 569 iy += 1 570 ix = 0 571 self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix),(1,5), 572 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 573 self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, 574 wx.BOTTOM|wx.RIGHT, 10)]) 575 576 577 def _layout_extrapolation_high(self): 578 """ 579 Draw widgets related to extrapolation at high q range 580 """ 331 581 self.enable_high_cbox = wx.CheckBox(self, -1, "Extrapolate high-Q") 332 582 self.enable_high_cbox.SetValue(False) 333 334 self.guinier = wx.RadioButton(self, -1, 'Guinier', 335 (10, 10),style=wx.RB_GROUP) 336 self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) 337 self.guinier.SetValue(True) 338 339 npts_low_txt = wx.StaticText(self, -1, 'Npts') 340 self.npts_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 341 self.npts_low_ctl.SetValue(str(NPTS)) 342 msg_hint = "Number of Q points to consider" 343 msg_hint +="while extrapolating the low-Q region" 344 self.npts_low_ctl.SetToolTipString(msg_hint) 345 npts_exp_txt = wx.StaticText(self, -1, 'Power') 346 self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 347 self.power_low_ctl.SetValue(str(self.power_law_exponant)) 348 self.power_low_ctl.SetToolTipString(power_hint_txt) 349 iy = 0 350 ix = 0 351 sizer_low_q.Add(self.guinier,(iy, ix),(1,2), 352 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 353 iy += 1 354 ix = 0 355 356 sizer_low_q.Add(self.power_law_low,(iy, ix),(1,2), 357 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 358 359 # Parameter controls for power law 360 ix = 1 361 iy += 1 362 sizer_low_q.Add(npts_exp_txt,(iy, ix),(1,1), 363 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 364 365 ix += 1 366 sizer_low_q.Add(self.power_low_ctl, (iy, ix), (1,1), 367 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 368 iy += 1 369 ix = 1 370 sizer_low_q.Add(npts_low_txt,(iy, ix),(1,1), 371 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 372 ix += 1 373 sizer_low_q.Add(self.npts_low_ctl, (iy, ix), (1,1), 374 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 375 iy += 1 376 ix = 0 377 sizer_low_q.Add(self.enable_low_cbox,(iy, ix),(1,5), 378 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 379 sizer_high_q = wx.GridBagSizer(5,5) 583 self.fit_high_cbox = wx.CheckBox(self, -1, "Check to Fit Power") 584 self.fit_high_cbox.SetValue(False) 380 585 self.power_law_high = wx.RadioButton(self, -1, 'Power Law', 381 586 (10, 10), style=wx.RB_GROUP) 382 587 msg_hint ="Check to extrapolate data at high-Q" 383 588 self.power_law_high.SetToolTipString(msg_hint) 384 385 #MAC needs SetValue386 589 self.power_law_high.SetValue(True) 387 590 npts_high_txt = wx.StaticText(self, -1, 'Npts') 388 npts_high_exp_txt = wx.StaticText(self, -1, 'Power') 389 self.npts_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 591 self.npts_high_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 390 592 msg_hint = "Number of Q points to consider" 391 593 msg_hint += "while extrapolating the high-Q region" 392 self.npts_high_ctl.SetToolTipString(msg_hint) 393 self.npts_high_ctl.SetValue(str(NPTS)) 394 self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) 395 self.power_high_ctl.SetValue(str(self.power_law_exponant)) 396 self.power_high_ctl.SetToolTipString(power_hint_txt) 397 594 self.npts_high_tcl.SetToolTipString(msg_hint) 595 self.npts_high_tcl.SetValue(str(NPTS)) 596 power_txt = wx.StaticText(self, -1, 'Power') 597 self.power_high_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 598 self.power_high_tcl.SetValue(str(self.power_law_exponant)) 599 power_hint_txt = "Exponent to apply to the Power_law function." 600 self.power_high_tcl.SetToolTipString(power_hint_txt) 398 601 iy = 1 399 602 ix = 0 400 s izer_high_q.Add(self.power_law_high,(iy, ix),(1,2),603 self.high_q_sizer.Add(self.power_law_high,(iy, ix),(1,2), 401 604 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 402 605 ix = 1 403 606 iy += 1 404 sizer_high_q.Add(npts_high_exp_txt,(iy, ix),(1,1), 405 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 406 407 ix += 1 408 sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1), 607 self.high_q_sizer.Add(self.fit_high_cbox,(iy, ix),(1,3), 608 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 609 ix = 1 610 iy += 1 611 self.high_q_sizer.Add(power_txt,(iy, ix),(1,1), 612 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 613 ix += 1 614 self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1,1), 409 615 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 410 616 iy += 1 411 617 ix = 1 412 s izer_high_q.Add(npts_high_txt,(iy, ix),(1,1),413 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 414 ix += 1 415 s izer_high_q.Add(self.npts_high_ctl, (iy, ix), (1,1),618 self.high_q_sizer.Add(npts_high_txt,(iy, ix),(1,1), 619 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 620 ix += 1 621 self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1,1), 416 622 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 417 623 iy += 1 418 624 ix = 0 419 sizer_high_q.Add(self.enable_high_cbox,(iy, ix),(1,5), 420 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 421 422 boxsizer_high_q.Add(sizer_high_q) 423 boxsizer_low_q.Add(sizer_low_q) 424 425 #-------------Enable extrapolation------- 625 self.high_q_sizer.Add(self.enable_high_cbox,(iy, ix),(1,5), 626 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 627 self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0, wx.RIGHT, 10)]) 628 629 def _layout_extrapolation(self): 630 """ 631 Draw widgets related to extrapolation 632 """ 426 633 extra_hint = "Extrapolation Maximum Range: " 427 extra_hint_txt= wx.StaticText(self, -1,extra_hint ) 428 extra_range = "[%s - %s]"%(str(Q_MINIMUM), str(Q_MAXIMUM)) 429 extra_range_value_txt = wx.StaticText(self, -1, str(extra_range)) 634 extra_hint_txt = wx.StaticText(self, -1, extra_hint) 635 #Extrapolation range [string] 636 extrapolation_min_txt = wx.StaticText(self, -1, 'Min : ') 637 self.extrapolation_min_tcl = wx.TextCtrl(self, -1, 638 size=(_BOX_WIDTH, 20), style=0) 639 self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) 640 self.extrapolation_min_tcl.SetToolTipString("The minimum extrapolated q value.") 641 self.extrapolation_min_tcl.SetEditable(False) 642 extrapolation_max_txt = wx.StaticText(self, -1, 'Max : ') 643 self.extrapolation_max_tcl = wx.TextCtrl(self, -1, 644 size=(_BOX_WIDTH, 20), style=0) 645 self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) 646 self.extrapolation_max_tcl.SetToolTipString("The maximum extrapolated q value.") 647 self.extrapolation_max_tcl.SetEditable(False) 648 self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, wx.LEFT, 10), 649 (extrapolation_min_txt, 0, wx.LEFT, 10), 650 (self.extrapolation_min_tcl, 651 0, wx.LEFT, 10), 652 (extrapolation_max_txt, 0, wx.LEFT, 10), 653 (self.extrapolation_max_tcl, 654 0, wx.LEFT, 10), 655 ]) 430 656 extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" 431 extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint ) 432 433 enable_sizer = wx.GridBagSizer(5,5) 434 657 extra_enable_hint_txt = wx.StaticText(self, -1, extra_enable_hint ) 658 self.extrapolation_hint_sizer.AddMany([(extra_enable_hint_txt, 0, wx.LEFT, 0) 659 ]) 660 self._layout_extrapolation_low() 661 self._layout_extrapolation_high() 662 self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer, 663 0, wx.ALL, 10), 664 (self.high_extrapolation_sizer, 665 0, wx.ALL, 10)]) 666 self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer, 0, 667 wx.RIGHT, 10), 668 (self.extrapolation_hint_sizer, 0, 669 wx.ALL, 10), 670 (self.extrapolation_low_high_sizer, 0, 671 wx.ALL, 10)]) 672 673 def _layout_volume_surface_sizer(self): 674 """ 675 Draw widgets related to volume and surface 676 """ 677 unit_volume = '' 678 unit_surface = '' 679 uncertainty = "+/-" 680 volume_txt = wx.StaticText(self, -1, 'Volume Fraction') 681 self.volume_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 682 self.volume_tcl.SetEditable(False) 683 self.volume_tcl.SetToolTipString("Volume fraction.") 684 self.volume_err_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 685 self.volume_err_tcl.SetEditable(False) 686 self.volume_err_tcl.SetToolTipString("Uncertainty on the volume fraction.") 687 volume_units_txt = wx.StaticText(self, -1, unit_volume) 688 689 surface_txt = wx.StaticText(self, -1, 'Specific surface') 690 self.surface_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 691 self.surface_tcl.SetEditable(False) 692 self.surface_tcl.SetToolTipString("Specific surface value.") 693 self.surface_err_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 694 self.surface_err_tcl.SetEditable(False) 695 self.surface_err_tcl.SetToolTipString("Uncertainty on the specific surface.") 696 surface_units_txt = wx.StaticText(self, -1, unit_surface) 435 697 iy = 0 436 698 ix = 0 437 enable_sizer.Add(extra_hint_txt,(iy, ix),(1,1), 438 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 439 ix += 1 440 enable_sizer.Add(extra_range_value_txt, (iy, ix), (1,1), 699 self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1,1), 700 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 701 ix += 1 702 self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1,1), 703 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 704 ix += 1 705 self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), 706 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) 707 ix += 1 708 self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1,1), 709 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 710 ix += 1 711 self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1,1), 712 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 713 iy += 1 714 ix = 0 715 self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1,1), 716 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 717 ix += 1 718 self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1,1), 441 719 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 442 ix = 0 443 iy += 1 444 enable_sizer.Add(extra_enable_hint_txt,(iy, ix),(1,1), 445 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 446 447 type_extrapolation_sizer = wx.BoxSizer(wx.HORIZONTAL) 448 type_extrapolation_sizer.Add((10,10)) 449 type_extrapolation_sizer.Add(boxsizer_low_q, 0, wx.ALL, 10) 450 type_extrapolation_sizer.Add((20,20)) 451 type_extrapolation_sizer.Add(boxsizer_high_q, 0, wx.ALL, 10) 452 type_extrapolation_sizer.Add((10,10)) 453 454 boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.VERTICAL) 455 boxsizer_extra.Add(enable_sizer, 0, wx.ALL, 10) 456 boxsizer_extra.Add(type_extrapolation_sizer) 457 458 boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1)) 459 boxsizer1.Add(sizer_input) 460 boxsizer1.Add(boxsizer_extra, 0, wx.ALL, 10) 461 sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) 462 463 #---------Outputs sizer-------- 464 invariant_txt = wx.StaticText(self, -1, 'Invariant') 465 self.invariant_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 466 self.invariant_ctl.SetEditable(False) 467 self.invariant_ctl.SetToolTipString("Invariant in the data set's Q range.") 468 self.invariant_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 469 self.invariant_err_ctl.SetEditable(False) 470 self.invariant_err_ctl.SetToolTipString("Uncertainty on the invariant.") 471 invariant_units_txt = wx.StaticText(self, -1, unit_invariant) 472 720 ix += 1 721 self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), 722 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 723 ix += 1 724 self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1,1), 725 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 726 ix += 1 727 self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1,1), 728 wx.EXPAND|wx.ADJUST_MINSIZE, 10) 729 730 def _layout_invariant_sizer(self): 731 """ 732 Draw widgets related to invariant 733 """ 734 uncertainty = "+/-" 735 unit_invariant = '[1/cm][1/A]' 473 736 invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total') 474 self.invariant_total_ ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))475 self.invariant_total_ ctl.SetEditable(False)737 self.invariant_total_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 738 self.invariant_total_tcl.SetEditable(False) 476 739 msg_hint = "Total invariant, including extrapolated regions." 477 self.invariant_total_ ctl.SetToolTipString(msg_hint)478 self.invariant_total_err_ ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))479 self.invariant_total_err_ ctl.SetEditable(False)480 self.invariant_total_err_ ctl.SetToolTipString("Uncertainty on invariant.")740 self.invariant_total_tcl.SetToolTipString(msg_hint) 741 self.invariant_total_err_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 742 self.invariant_total_err_tcl.SetEditable(False) 743 self.invariant_total_err_tcl.SetToolTipString("Uncertainty on invariant.") 481 744 invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) 482 483 volume_txt = wx.StaticText(self, -1, 'Volume Fraction') 484 self.volume_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 485 self.volume_ctl.SetEditable(False) 486 self.volume_ctl.SetToolTipString("Volume fraction.") 487 self.volume_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 488 self.volume_err_ctl.SetEditable(False) 489 self.volume_err_ctl.SetToolTipString("Uncertainty on the volume fraction.") 490 volume_units_txt = wx.StaticText(self, -1, unit_volume) 491 492 surface_txt = wx.StaticText(self, -1, 'Specific surface') 493 self.surface_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 494 self.surface_ctl.SetEditable(False) 495 self.surface_ctl.SetToolTipString("Specific surface value.") 496 self.surface_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 497 self.surface_err_ctl.SetEditable(False) 498 self.surface_err_ctl.SetToolTipString("Uncertainty on the specific surface.") 499 surface_units_txt = wx.StaticText(self, -1, unit_surface) 500 501 invariant_low_txt = wx.StaticText(self, -1, 'Invariant in low-Q region') 502 self.invariant_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 503 self.invariant_low_ctl.SetEditable(False) 504 self.invariant_low_ctl.SetToolTipString("Invariant computed with the extrapolated low-Q data.") 505 invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) 506 507 invariant_high_txt = wx.StaticText(self, -1, 'Invariant in high-Q region') 508 self.invariant_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 509 self.invariant_high_ctl.SetEditable(False) 510 self.invariant_high_ctl.SetToolTipString("Invariant computed with the extrapolated high-Q data") 511 invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) 512 745 746 #Invariant total 513 747 iy = 0 514 748 ix = 0 515 s izer_output.Add(invariant_low_txt, (iy, ix), (1,1),749 self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1,1), 516 750 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 517 ix +=1 518 sizer_output.Add(self.invariant_low_ctl, (iy, ix), (1,1), 519 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 520 ix += 2 521 sizer_output.Add(invariant_low_units_txt, (iy, ix), (1,1), 751 ix += 1 752 self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1,1), 522 753 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 523 iy += 1 524 ix = 0 525 sizer_output.Add(invariant_high_txt, (iy, ix), (1,1), 526 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 527 ix +=1 528 sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1), 529 wx.EXPAND|wx.ADJUST_MINSIZE, ) 530 ix += 2 531 sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1), 754 ix += 1 755 self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), 756 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 757 ix += 1 758 self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1,1), 532 759 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 533 iy += 1 534 ix = 0 535 sizer_output.Add(invariant_txt,(iy, ix),(1,1), 536 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 537 ix += 1 538 sizer_output.Add(self.invariant_ctl,(iy, ix),(1,1), 539 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 540 ix += 1 541 sizer_output.Add( wx.StaticText(self, -1, uncertainty), 542 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 543 ix +=1 544 sizer_output.Add(self.invariant_err_ctl 760 ix += 1 761 self.invariant_sizer.Add(invariant_total_units_txt 545 762 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 546 ix +=1 547 sizer_output.Add(invariant_units_txt 548 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 549 iy += 1 550 ix = 0 551 sizer_output.Add(invariant_total_txt,(iy, ix),(1,1), 552 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 553 ix += 1 554 sizer_output.Add(self.invariant_total_ctl,(iy, ix),(1,1), 555 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 556 ix += 1 557 sizer_output.Add( wx.StaticText(self, -1, uncertainty), 558 (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 559 ix +=1 560 sizer_output.Add(self.invariant_total_err_ctl 561 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 562 ix +=1 563 sizer_output.Add(invariant_total_units_txt,(iy, ix), 564 (1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 565 iy += 1 566 ix = 0 567 sizer_output.Add(volume_txt,(iy, ix),(1,1), 568 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 569 ix +=1 570 sizer_output.Add(self.volume_ctl,(iy, ix),(1,1), 571 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 572 ix +=1 573 sizer_output.Add(wx.StaticText(self, -1, uncertainty) 574 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 575 ix += 1 576 sizer_output.Add(self.volume_err_ctl 577 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 578 ix += 1 579 sizer_output.Add(volume_units_txt 580 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 581 iy += 1 582 ix = 0 583 sizer_output.Add(surface_txt,(iy, ix),(1,1), 584 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 585 ix +=1 586 sizer_output.Add(self.surface_ctl,(iy, ix),(1,1), 587 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 588 ix +=1 589 sizer_output.Add(wx.StaticText(self, -1, uncertainty) 590 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 591 ix += 1 592 sizer_output.Add(self.surface_err_ctl 593 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 594 ix +=1 595 sizer_output.Add(surface_units_txt 596 ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) 597 598 outputbox = wx.StaticBox(self, -1, "Output") 599 boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) 600 boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1)) 601 boxsizer2.Add( sizer_output ) 602 sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10) 603 #-----Button sizer------------ 763 764 def _layout_outputs_sizer(self): 765 """ 766 Draw widgets related to outputs 767 """ 768 self._layout_volume_surface_sizer() 769 self._layout_invariant_sizer() 770 static_line = wx.StaticLine(self, -1) 771 self.outputs_sizer.AddMany([(self.volume_surface_sizer, 0, wx.ALL, 10), 772 (static_line, 0, wx.EXPAND, 0), 773 (self.invariant_sizer, 0, wx.ALL, 10)]) 774 def _layout_button(self): 775 """ 776 Do the layout for the button widgets 777 """ 778 #compute button 604 779 id = wx.NewId() 605 780 button_calculate = wx.Button(self, id, "Compute") 606 781 button_calculate.SetToolTipString("Compute invariant") 607 self.Bind(wx.EVT_BUTTON, self.compute_invariant, id = id) 608 609 sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 610 sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE,20) 611 sizer3.Add(sizer_button) 612 #---------layout---------------- 613 614 vbox.Add(sizer1) 615 vbox.Add(sizer2) 616 vbox.Add(sizer3) 617 vbox.Fit(self) 618 self.SetSizer(vbox) 782 self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) 783 #detail button 784 id = wx.NewId() 785 self.button_ok = wx.Button(self, id, "Ok") 786 self.button_ok.SetToolTipString("Give Details on Computation") 787 self.Bind(wx.EVT_BUTTON, self.display_details, id=id) 788 self.button_ok.Disable() 789 details = "Details on Invariant Total Calculations" 790 details_txt = wx.StaticText(self, -1, details) 791 self.button_sizer.AddMany([((20,20), 0 , wx.LEFT, 100), 792 (details_txt, 0 , wx.ALL, 10), 793 (self.button_ok, 0 , wx.ALL, 10), 794 (button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 795 796 def _do_layout(self): 797 """ 798 Draw window content 799 """ 800 self._define_structure() 801 self._layout_data_name() 802 self._layout_background() 803 self._layout_scale() 804 self._layout_contrast() 805 self._layout_porod_constant() 806 self._layout_extrapolation() 807 self._layout_outputs_sizer() 808 self._layout_button() 809 self.main_sizer.AddMany([(self.data_name_boxsizer, 0, wx.ALL, 10), 810 (self.background_sizer, 0, 811 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 812 (self.scale_sizer, 0, 813 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 814 (self.contrast_sizer, 0, 815 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 816 (self.porod_constant_sizer, 0, 817 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 818 (self.extrapolation_sizer, 0, 819 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 820 (self.outputs_sizer, 0, 821 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 822 (self.button_sizer, 0, 823 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) 824 self.SetSizer(self.main_sizer) 825 self.SetScrollbars(20,20,25,65) 826 self.SetAutoLayout(True) 619 827 620 828 class InvariantDialog(wx.Dialog): … … 631 839 data=None, title="Invariant",base=None): 632 840 633 wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH ,634 PANEL_HEIGHT ))841 wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, 842 PANEL_HEIGHT+100)) 635 843 636 844 self.panel = InvariantPanel(self)
Note: See TracChangeset
for help on using the changeset viewer.