[0277d084] | 1 | |
---|
| 2 | import wx |
---|
| 3 | import wx.lib.newevent |
---|
| 4 | import numpy |
---|
| 5 | import copy |
---|
| 6 | import math |
---|
| 7 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
| 8 | |
---|
| 9 | from sans.guicomm.events import StatusEvent |
---|
| 10 | from sans.guiframe.utils import format_number |
---|
| 11 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
| 12 | _BOX_WIDTH = 76 |
---|
| 13 | |
---|
| 14 | import basepage |
---|
| 15 | from basepage import BasicPage |
---|
| 16 | from basepage import PageInfoEvent |
---|
| 17 | |
---|
| 18 | class ModelPanel(BasicPage): |
---|
| 19 | """ |
---|
[74755ff] | 20 | FitPanel class contains fields allowing to display results when |
---|
| 21 | fitting a model and one data |
---|
| 22 | |
---|
| 23 | :note: For Fit to be performed the user should check at least |
---|
[0277d084] | 24 | one parameter on fit Panel window. |
---|
| 25 | """ |
---|
| 26 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 27 | CENTER_PANE = True |
---|
[693500a] | 28 | ## Internal name for the AUI manager |
---|
| 29 | window_name = "Theory model" |
---|
| 30 | ## Title to appear on top of the window |
---|
| 31 | window_caption = "Theory Model" |
---|
[0277d084] | 32 | def __init__(self,parent, page_info, model_list_box): |
---|
| 33 | BasicPage.__init__(self, parent, page_info , model_list_box) |
---|
| 34 | """ |
---|
[74755ff] | 35 | Initialization of the Panel |
---|
[0277d084] | 36 | """ |
---|
| 37 | self._fill_model_sizer( self.sizer1) |
---|
| 38 | self._fill_range_sizer() |
---|
| 39 | self.engine_type = None |
---|
| 40 | |
---|
| 41 | description="" |
---|
| 42 | if self.model!=None: |
---|
| 43 | |
---|
| 44 | description = self.model.description |
---|
| 45 | |
---|
| 46 | self.select_model(self.model) |
---|
| 47 | self.set_model_description(description,self.sizer2) |
---|
| 48 | |
---|
| 49 | def _on_display_description(self, event): |
---|
| 50 | """ |
---|
[74755ff] | 51 | Show or Hide description |
---|
| 52 | |
---|
| 53 | :param event: wx.EVT_RADIOBUTTON |
---|
| 54 | |
---|
[0277d084] | 55 | """ |
---|
| 56 | self._on_display_description_helper() |
---|
| 57 | |
---|
| 58 | self.SetScrollbars(20,20,25,65) |
---|
| 59 | self.Refresh() |
---|
| 60 | |
---|
| 61 | def _on_display_description_helper(self): |
---|
| 62 | """ |
---|
[74755ff] | 63 | Show or Hide description |
---|
| 64 | |
---|
| 65 | :param event: wx.EVT_RADIOBUTTON |
---|
| 66 | |
---|
[0277d084] | 67 | """ |
---|
| 68 | ## Show description |
---|
| 69 | if self.description_hide.GetValue(): |
---|
| 70 | self.sizer_description.Clear(True) |
---|
| 71 | |
---|
| 72 | else: |
---|
| 73 | description="Model contains no description" |
---|
| 74 | if self.model!=None: |
---|
| 75 | description = self.model.description |
---|
| 76 | if description.lstrip().rstrip() =="": |
---|
| 77 | description="Model contains no description" |
---|
| 78 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
| 79 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
| 80 | |
---|
| 81 | self.Layout() |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | def _fill_range_sizer(self): |
---|
| 85 | """ |
---|
[74755ff] | 86 | Fill the sizer containing the plotting range |
---|
| 87 | add access to npts |
---|
| 88 | |
---|
[0277d084] | 89 | """ |
---|
| 90 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
| 91 | title = "Plotted Q Range" |
---|
| 92 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 93 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 94 | |
---|
| 95 | sizer_npts= wx.GridSizer(1, 1,5, 5) |
---|
| 96 | self.npts = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 97 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 98 | self.npts.SetToolTipString("Number of point to plot.") |
---|
| 99 | |
---|
| 100 | sizer_npts.Add(wx.StaticText(self, -1, 'Npts'),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 13) |
---|
| 101 | |
---|
| 102 | sizer_npts.Add(self.npts,1,wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 103 | self._set_range_sizer( title=title, box_sizer=boxsizer1, object= sizer_npts) |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | def _on_select_model(self, event): |
---|
| 107 | """ |
---|
[74755ff] | 108 | call back for model selection |
---|
| 109 | |
---|
[0277d084] | 110 | """ |
---|
| 111 | self._on_select_model_helper() |
---|
| 112 | #Reset dispersity that was not done in _on_select_model_helper() |
---|
| 113 | self._reset_dispersity() |
---|
| 114 | self.select_model(self.model) |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | def _fill_model_sizer(self, sizer): |
---|
| 118 | """ |
---|
[74755ff] | 119 | fill sizer containing model info |
---|
| 120 | |
---|
[0277d084] | 121 | """ |
---|
| 122 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
| 123 | title = "Model" |
---|
| 124 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 125 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 126 | |
---|
| 127 | id = wx.NewId() |
---|
| 128 | self.model_view =wx.Button(self,id,'View 2D', size=(80,23)) |
---|
| 129 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D,id=id) |
---|
| 130 | self.model_view.SetToolTipString("View model in 2D") |
---|
| 131 | |
---|
| 132 | ## class base method to add view 2d button |
---|
| 133 | self._set_model_sizer(sizer=sizer,box_sizer=boxsizer1, title=title,object= self.model_view ) |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | #def _set_sizer_gaussian(self): |
---|
| 137 | def _set_sizer_dispersion(self, dispersity): |
---|
| 138 | """ |
---|
[74755ff] | 139 | draw sizer with gaussian, log or schulz dispersity parameters |
---|
| 140 | |
---|
[0277d084] | 141 | """ |
---|
| 142 | self.fittable_param=[] |
---|
| 143 | self.fixed_param=[] |
---|
| 144 | self.orientation_params_disp=[] |
---|
| 145 | #self.temp=[] |
---|
| 146 | |
---|
| 147 | self.sizer4_4.Clear(True) |
---|
| 148 | if self.model==None: |
---|
| 149 | ##no model is selected |
---|
| 150 | return |
---|
| 151 | if not self.enable_disp.GetValue(): |
---|
| 152 | ## the user didn't select dispersity display |
---|
| 153 | return |
---|
| 154 | self._reset_dispersity() |
---|
| 155 | # Create the dispersion objects |
---|
| 156 | for item in self.model.dispersion.keys(): |
---|
| 157 | #disp_model = GaussianDispersion() |
---|
| 158 | disp_model = dispersity() |
---|
| 159 | self._disp_obj_dict[item] = disp_model |
---|
| 160 | self.model.set_dispersion(item, disp_model) |
---|
| 161 | self.state._disp_obj_dict[item]= disp_model |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | ix=0 |
---|
| 165 | iy=1 |
---|
[52efcc5] | 166 | disp = wx.StaticText(self, -1, ' ') |
---|
[0277d084] | 167 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 168 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 169 | ix += 1 |
---|
[52efcc5] | 170 | values = wx.StaticText(self, -1, 'Sigma (STD)') |
---|
[1a94c36] | 171 | values.SetToolTipString("Polydispersity multiplied by the value of the original parameter.") |
---|
[0277d084] | 172 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 173 | |
---|
| 174 | ix += 1 |
---|
| 175 | npts = wx.StaticText(self, -1, 'Npts') |
---|
[1a94c36] | 176 | npts.SetToolTipString("Number of points for weighting.") |
---|
[0277d084] | 177 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 178 | ix += 1 |
---|
| 179 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
[1a94c36] | 180 | nsigmas.SetToolTipString("Number of sigmas between which the range of the distribution function will be used for weighting. The value '3' covers 99.5% for Gaussian distribution function.") |
---|
[0277d084] | 181 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 182 | |
---|
| 183 | for item in self.model.dispersion.keys(): |
---|
| 184 | if not item in self.model.orientation_params: |
---|
| 185 | self.disp_cb_dict[item]= None |
---|
| 186 | name1=item+".width" |
---|
| 187 | name2=item+".npts" |
---|
| 188 | name3=item+".nsigmas" |
---|
| 189 | iy += 1 |
---|
| 190 | for p in self.model.dispersion[item].keys(): |
---|
| 191 | if p=="width": |
---|
| 192 | ix = 0 |
---|
| 193 | name = wx.StaticText(self, -1, name1) |
---|
| 194 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
| 195 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 196 | ix = 1 |
---|
| 197 | value= self.model.getParam(name1) |
---|
| 198 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 199 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 200 | ctl1.SetToolTipString("Polydispersity multiplied by the value of the '%s'."%item) |
---|
[0277d084] | 201 | ctl1.SetValue(str (format_number(value))) |
---|
| 202 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 203 | self.fittable_param.append([None,name1,ctl1,None, |
---|
| 204 | None, None, None,None]) |
---|
| 205 | elif p=="npts": |
---|
| 206 | ix =2 |
---|
| 207 | value= self.model.getParam(name2) |
---|
| 208 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 209 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 210 | |
---|
[0277d084] | 211 | Tctl1.SetValue(str (format_number(value))) |
---|
| 212 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
| 213 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 214 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
| 215 | None, None,None]) |
---|
| 216 | elif p=="nsigmas": |
---|
| 217 | ix =3 |
---|
| 218 | value= self.model.getParam(name3) |
---|
| 219 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 220 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 221 | |
---|
[0277d084] | 222 | Tctl2.SetValue(str (format_number(value))) |
---|
| 223 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
| 224 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 225 | ix +=1 |
---|
| 226 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 227 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 228 | self.fixed_param.append([None,name3, Tctl2, |
---|
| 229 | None,None, None, None,None]) |
---|
| 230 | for item in self.model.dispersion.keys(): |
---|
| 231 | if item in self.model.orientation_params: |
---|
| 232 | self.disp_cb_dict[item]= None |
---|
| 233 | name1=item+".width" |
---|
| 234 | name2=item+".npts" |
---|
| 235 | name3=item+".nsigmas" |
---|
| 236 | iy += 1 |
---|
| 237 | for p in self.model.dispersion[item].keys(): |
---|
| 238 | if p=="width": |
---|
| 239 | ix = 0 |
---|
| 240 | name = wx.StaticText(self, -1, name1) |
---|
| 241 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
| 242 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 243 | if not self.enable2D: |
---|
| 244 | name.Hide() |
---|
| 245 | else: |
---|
| 246 | name.Show(True) |
---|
| 247 | ix = 1 |
---|
| 248 | value= self.model.getParam(name1) |
---|
| 249 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 250 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 251 | ctl1.SetToolTipString("Polydispersity multiplied by the value of '%s'."%item) |
---|
[0277d084] | 252 | ctl1.SetValue(str (format_number(value))) |
---|
| 253 | if not self.enable2D: |
---|
| 254 | ctl1.Hide() |
---|
| 255 | ctl1.Disable() |
---|
| 256 | else: |
---|
| 257 | ctl1.Show(True) |
---|
| 258 | ctl1.Enable() |
---|
| 259 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 260 | self.fittable_param.append([None,name1,ctl1,None, |
---|
| 261 | None, None, None,None]) |
---|
| 262 | self.orientation_params_disp.append([None,name1,ctl1,None, |
---|
| 263 | None, None, None,None]) |
---|
| 264 | elif p=="npts": |
---|
| 265 | ix =2 |
---|
| 266 | value= self.model.getParam(name2) |
---|
| 267 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 268 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 269 | |
---|
[0277d084] | 270 | Tctl1.SetValue(str (format_number(value))) |
---|
| 271 | if not self.enable2D: |
---|
| 272 | Tctl1.Hide() |
---|
| 273 | Tctl1.Disable() |
---|
| 274 | else: |
---|
| 275 | Tctl1.Show(True) |
---|
| 276 | Tctl1.Enable() |
---|
| 277 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
| 278 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 279 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
| 280 | None, None,None]) |
---|
| 281 | self.orientation_params_disp.append([None,name2, Tctl1,None,None, |
---|
| 282 | None, None,None]) |
---|
| 283 | elif p=="nsigmas": |
---|
| 284 | ix =3 |
---|
| 285 | value= self.model.getParam(name3) |
---|
| 286 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 287 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 288 | |
---|
[0277d084] | 289 | Tctl2.SetValue(str (format_number(value))) |
---|
| 290 | if not self.enable2D: |
---|
| 291 | Tctl2.Hide() |
---|
| 292 | Tctl2.Disable() |
---|
| 293 | else: |
---|
| 294 | Tctl2.Show(True) |
---|
| 295 | Tctl2.Enable() |
---|
| 296 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
| 297 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 298 | ix +=1 |
---|
| 299 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 300 | #wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 301 | self.fixed_param.append([None,name3, Tctl2, |
---|
| 302 | None,None, None, None,None]) |
---|
| 303 | self.orientation_params_disp.append([None,name3, Tctl2, |
---|
| 304 | None,None, None, None,None]) |
---|
| 305 | |
---|
| 306 | msg = " Selected Distribution: Gaussian" |
---|
| 307 | wx.PostEvent(self.parent, StatusEvent( status= msg )) |
---|
| 308 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 309 | ix =0 |
---|
| 310 | iy +=1 |
---|
| 311 | #self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 312 | self.sizer4_4.Layout() |
---|
| 313 | self.sizer4.Layout() |
---|
| 314 | self.SetScrollbars(20,20,25,65) |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | def _onModel2D(self, event): |
---|
| 318 | """ |
---|
[74755ff] | 319 | call manager to plot model in 2D |
---|
| 320 | |
---|
[0277d084] | 321 | """ |
---|
| 322 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
| 323 | # and set the enable2D flag. |
---|
| 324 | |
---|
| 325 | if self.fitrange: |
---|
| 326 | self.enable2D = True |
---|
| 327 | |
---|
| 328 | if self.enable2D: |
---|
| 329 | self._draw_model() |
---|
| 330 | self.model_view.Disable() |
---|
| 331 | |
---|
| 332 | n = self.disp_box.GetCurrentSelection() |
---|
| 333 | dispersity= self.disp_box.GetClientData(n) |
---|
| 334 | #TODO:Find a better way to reinitialize the parameters containers |
---|
| 335 | # when resetting the page and 2D view is enable |
---|
| 336 | #self.set_model_param_sizer(self.model): called here is using a lot |
---|
| 337 | #of for loops and redraw the sizer again .How to avoid it? |
---|
| 338 | self.set_model_param_sizer(self.model) |
---|
| 339 | |
---|
| 340 | if len(self.orientation_params)>0: |
---|
| 341 | for item in self.orientation_params: |
---|
| 342 | if item[2]!=None: |
---|
| 343 | item[2].Enable() |
---|
| 344 | # same as above why do we have to redraw the sizer of dispersity to get |
---|
| 345 | # the appropriate value of parameters containers on reset page? |
---|
| 346 | # Reset containers of dispersity parameters for the appropriate dispersity |
---|
| 347 | #and model |
---|
| 348 | if self.disp_name.lower()in ["array","arraydispersion"]: |
---|
| 349 | self._set_sizer_arraydispersion() |
---|
| 350 | else: |
---|
| 351 | self._set_sizer_dispersion(dispersity) |
---|
| 352 | if len(self.orientation_params_disp)>0: |
---|
| 353 | |
---|
| 354 | for item in self.orientation_params_disp: |
---|
| 355 | if item[2]!=None: |
---|
| 356 | item[2].Enable() |
---|
| 357 | |
---|
| 358 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 359 | self.Layout() |
---|
| 360 | ## post state to fit panel |
---|
| 361 | #self._undo.Enable(True) |
---|
| 362 | event = PageInfoEvent(page = self) |
---|
| 363 | wx.PostEvent(self.parent, event) |
---|
| 364 | |
---|
[3c44c66] | 365 | def set_data(self, list=[], state=None): |
---|
| 366 | """ |
---|
| 367 | Receive a list of data from gui_manager to plot theory |
---|
| 368 | """ |
---|
[e99126a] | 369 | pass |
---|
| 370 | |
---|
[0277d084] | 371 | def reset_page(self, state): |
---|
| 372 | """ |
---|
[74755ff] | 373 | reset the state |
---|
| 374 | |
---|
[0277d084] | 375 | """ |
---|
| 376 | self.reset_page_helper(state) |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | def select_model(self, model): |
---|
| 380 | """ |
---|
[74755ff] | 381 | Select a new model |
---|
| 382 | |
---|
| 383 | :param model: model object |
---|
| 384 | |
---|
[0277d084] | 385 | """ |
---|
| 386 | self.model = model |
---|
| 387 | if self.model !=None: |
---|
| 388 | self.disp_list= self.model.getDispParamList() |
---|
| 389 | self.set_model_param_sizer(self.model) |
---|
| 390 | ## keep the sizer view consistent with the model menu selecting |
---|
| 391 | self._set_model_sizer_selection( self.model ) |
---|
| 392 | self.enable_disp.SetValue(False) |
---|
| 393 | self.disable_disp.SetValue(True) |
---|
| 394 | self.set_dispers_sizer() |
---|
| 395 | |
---|
| 396 | self.model_view.SetFocus() |
---|
| 397 | if self.model !=None: |
---|
| 398 | self._draw_model() |
---|
| 399 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 400 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 401 | |
---|
| 402 | ## post state to fit panel |
---|
| 403 | #self._undo.Enable(True) |
---|
| 404 | event = PageInfoEvent(page = self) |
---|
| 405 | wx.PostEvent(self.parent, event) |
---|
| 406 | |
---|
| 407 | |
---|
| 408 | def set_model_description(self,description,sizer): |
---|
| 409 | """ |
---|
[74755ff] | 410 | fill a sizer with description |
---|
| 411 | |
---|
| 412 | :param description: of type string |
---|
| 413 | :param sizer: wx.BoxSizer() |
---|
| 414 | |
---|
[0277d084] | 415 | """ |
---|
| 416 | |
---|
| 417 | sizer.Clear(True) |
---|
| 418 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
| 419 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 420 | |
---|
| 421 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 422 | self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) |
---|
| 423 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
| 424 | |
---|
| 425 | |
---|
| 426 | if description=="": |
---|
| 427 | self.description_hide.SetValue(True) |
---|
| 428 | description=" Description unavailable. Click for details" |
---|
| 429 | |
---|
| 430 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
| 431 | |
---|
| 432 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 433 | id=self.description_hide.GetId() ) |
---|
| 434 | |
---|
| 435 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 436 | id=self.description_show.GetId() ) |
---|
| 437 | #MAC needs SetValue |
---|
| 438 | self.description_hide.SetValue(True) |
---|
| 439 | |
---|
| 440 | self.model_description = wx.Button(self,-1, label="Details", size=(80,23)) |
---|
| 441 | |
---|
| 442 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
| 443 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
| 444 | self.model_description.SetFocus() |
---|
| 445 | sizer_selection.Add( self.description_show ) |
---|
| 446 | sizer_selection.Add( (20,20)) |
---|
| 447 | sizer_selection.Add( self.description_hide ) |
---|
| 448 | sizer_selection.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,75) |
---|
| 449 | sizer_selection.Add( self.model_description ) |
---|
| 450 | |
---|
| 451 | |
---|
| 452 | self.sizer_description=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 453 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
| 454 | boxsizer1.Add( sizer_selection) |
---|
| 455 | boxsizer1.Add( (20,20)) |
---|
| 456 | boxsizer1.Add( self.sizer_description) |
---|
| 457 | |
---|
| 458 | self._on_display_description(event=None) |
---|
| 459 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 460 | sizer.Layout() |
---|
| 461 | |
---|
| 462 | def on_button_clicked(self,event): |
---|
| 463 | """ |
---|
[74755ff] | 464 | On 'More details' button |
---|
[0277d084] | 465 | """ |
---|
| 466 | from help_panel import HelpWindow |
---|
| 467 | |
---|
| 468 | if self.model == None: |
---|
| 469 | name = 'FuncHelp' |
---|
| 470 | else: |
---|
| 471 | name = self.model.name |
---|
[e071b1c] | 472 | frame = HelpWindow(None, -1, pageToOpen="media/model_functions.html") |
---|
[0277d084] | 473 | frame.Show(True) |
---|
| 474 | if frame.rhelp.HasAnchor(name): |
---|
| 475 | frame.rhelp.ScrollToAnchor(name) |
---|
| 476 | else: |
---|
| 477 | msg= "Model does not contains an available description " |
---|
| 478 | msg +="Please.Search in the Help window" |
---|
| 479 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 480 | |
---|
| 481 | def set_range(self, qmin_x, qmax_x, npts): |
---|
| 482 | """ |
---|
[74755ff] | 483 | Set the range for the plotted models |
---|
| 484 | |
---|
| 485 | :param qmin: minimum Q |
---|
| 486 | :param qmax: maximum Q |
---|
| 487 | :param npts: number of Q bins |
---|
| 488 | |
---|
[0277d084] | 489 | """ |
---|
| 490 | # Set the data members |
---|
| 491 | self.qmin_x = qmin_x |
---|
| 492 | self.qmax_x = qmax_x |
---|
| 493 | self.num_points = npts |
---|
| 494 | # Set the controls |
---|
| 495 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
| 496 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 497 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 498 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 499 | |
---|
| 500 | def set_model_param_sizer(self, model): |
---|
| 501 | """ |
---|
[74755ff] | 502 | Build the panel from the model content |
---|
| 503 | |
---|
| 504 | :param model: the model selected in combo box for fitting purpose |
---|
| 505 | |
---|
[0277d084] | 506 | """ |
---|
| 507 | self.sizer3.Clear(True) |
---|
| 508 | self.parameters = [] |
---|
| 509 | self.param_toFit=[] |
---|
| 510 | self.fixed_param=[] |
---|
| 511 | self.orientation_params=[] |
---|
| 512 | self.orientation_params_disp=[] |
---|
| 513 | #self.temp=[] |
---|
| 514 | if model ==None: |
---|
| 515 | ##no model avaiable to draw sizer |
---|
| 516 | self.sizer3.Layout() |
---|
| 517 | self.SetScrollbars(20,20,25,65) |
---|
| 518 | return |
---|
| 519 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 520 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 521 | sizer = wx.GridBagSizer(5,5) |
---|
| 522 | |
---|
| 523 | self.model = model |
---|
| 524 | self.set_model_description(self.model.description,self.sizer2) |
---|
| 525 | |
---|
| 526 | keys = self.model.getParamList() |
---|
| 527 | ##list of dispersion parameters |
---|
| 528 | self.disp_list=self.model.getDispParamList() |
---|
| 529 | |
---|
| 530 | keys.sort() |
---|
| 531 | |
---|
| 532 | iy = 0 |
---|
| 533 | ix = 0 |
---|
| 534 | self.text1_2 = wx.StaticText(self, -1, 'Names') |
---|
| 535 | sizer.Add(self.text1_2,(iy, ix),(1,1),\ |
---|
| 536 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 537 | ix +=1 |
---|
| 538 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 539 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 540 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 541 | ix +=1 |
---|
| 542 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 543 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 544 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 545 | self.text2_4.Hide() |
---|
| 546 | |
---|
| 547 | for item in keys: |
---|
| 548 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
| 549 | iy += 1 |
---|
| 550 | ix = 0 |
---|
| 551 | name = wx.StaticText(self, -1,item) |
---|
| 552 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 553 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 554 | |
---|
| 555 | ix += 1 |
---|
| 556 | value= self.model.getParam(item) |
---|
| 557 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 558 | style=wx.TE_PROCESS_ENTER) |
---|
| 559 | |
---|
| 560 | ctl1.SetValue(str (format_number(value))) |
---|
| 561 | |
---|
| 562 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 563 | ix +=1 |
---|
| 564 | # Units |
---|
| 565 | if self.model.details.has_key(item): |
---|
| 566 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 567 | else: |
---|
| 568 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 569 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 570 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 571 | self.parameters.append([None,item, ctl1, |
---|
| 572 | None,None, None, None,None]) |
---|
| 573 | iy+=1 |
---|
| 574 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 575 | iy += 1 |
---|
| 576 | ix = 0 |
---|
| 577 | |
---|
| 578 | #Add tile for orientational angle parameters |
---|
| 579 | for item in keys: |
---|
| 580 | if item in self.model.orientation_params: |
---|
| 581 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
| 582 | sizer.Add(orient_angle,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 583 | if not self.enable2D: |
---|
| 584 | orient_angle.Hide() |
---|
| 585 | else: |
---|
| 586 | orient_angle.Show(True) |
---|
| 587 | break |
---|
| 588 | |
---|
| 589 | for item in self.model.orientation_params: |
---|
| 590 | if not item in self.disp_list and item in keys: |
---|
| 591 | iy += 1 |
---|
| 592 | ix = 0 |
---|
| 593 | name = wx.StaticText(self, -1,item) |
---|
| 594 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 595 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 596 | if not self.enable2D: |
---|
| 597 | name.Hide() |
---|
| 598 | else: |
---|
| 599 | name.Show(True) |
---|
| 600 | |
---|
| 601 | ix += 1 |
---|
| 602 | value= self.model.getParam(item) |
---|
| 603 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 604 | style=wx.TE_PROCESS_ENTER) |
---|
| 605 | |
---|
| 606 | ctl1.SetValue(str (format_number(value))) |
---|
| 607 | if not self.enable2D: |
---|
| 608 | ctl1.Hide() |
---|
| 609 | ctl1.Disable() |
---|
| 610 | else: |
---|
| 611 | ctl1.Show(True) |
---|
| 612 | ctl1.Enable() |
---|
| 613 | |
---|
| 614 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 615 | ix +=1 |
---|
| 616 | # Units |
---|
| 617 | if self.model.details.has_key(item): |
---|
| 618 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 619 | else: |
---|
| 620 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 621 | if not self.enable2D: |
---|
| 622 | units.Hide() |
---|
| 623 | else: |
---|
| 624 | units.Show(True) |
---|
| 625 | |
---|
| 626 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 627 | #Save 2D orient. params |
---|
| 628 | #self.temp.append([name,ctl1,units,orient_angle]) |
---|
| 629 | |
---|
| 630 | |
---|
| 631 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 632 | self.parameters.append([None,item, ctl1, |
---|
| 633 | None,None, None, None,None]) |
---|
| 634 | self.orientation_params.append([None,item, ctl1, |
---|
[199cef2] | 635 | None,None, None, None,None]) |
---|
| 636 | iy += 1 |
---|
[0277d084] | 637 | |
---|
| 638 | #Display units text on panel |
---|
| 639 | for item in keys: |
---|
| 640 | self.text2_4.Show() |
---|
| 641 | |
---|
| 642 | boxsizer1.Add(sizer) |
---|
| 643 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 644 | self.sizer3.Layout() |
---|
| 645 | self.SetScrollbars(20,20,25,65) |
---|
| 646 | |
---|