[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 | """ |
---|
| 369 | if list==[]: |
---|
| 370 | msg = "Please select data for Theory perspective.\n" |
---|
| 371 | dial = wx.MessageDialog(None, msg, 'Error Loading File', |
---|
| 372 | wx.OK | wx.ICON_EXCLAMATION) |
---|
| 373 | dial.ShowModal() |
---|
| 374 | return |
---|
| 375 | else : |
---|
| 376 | msg = "Theory perspective does not allow Data.\n" |
---|
| 377 | msg += "Please import theory or go the theory perspective.\n" |
---|
| 378 | dial = wx.MessageDialog(None, msg, 'Error Loading File', |
---|
| 379 | wx.OK | wx.ICON_EXCLAMATION) |
---|
| 380 | dial.ShowModal() |
---|
| 381 | |
---|
[0277d084] | 382 | def reset_page(self, state): |
---|
| 383 | """ |
---|
[74755ff] | 384 | reset the state |
---|
| 385 | |
---|
[0277d084] | 386 | """ |
---|
| 387 | self.reset_page_helper(state) |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | def select_model(self, model): |
---|
| 391 | """ |
---|
[74755ff] | 392 | Select a new model |
---|
| 393 | |
---|
| 394 | :param model: model object |
---|
| 395 | |
---|
[0277d084] | 396 | """ |
---|
| 397 | self.model = model |
---|
| 398 | if self.model !=None: |
---|
| 399 | self.disp_list= self.model.getDispParamList() |
---|
| 400 | self.set_model_param_sizer(self.model) |
---|
| 401 | ## keep the sizer view consistent with the model menu selecting |
---|
| 402 | self._set_model_sizer_selection( self.model ) |
---|
| 403 | self.enable_disp.SetValue(False) |
---|
| 404 | self.disable_disp.SetValue(True) |
---|
| 405 | self.set_dispers_sizer() |
---|
| 406 | |
---|
| 407 | self.model_view.SetFocus() |
---|
| 408 | if self.model !=None: |
---|
| 409 | self._draw_model() |
---|
| 410 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 411 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 412 | |
---|
| 413 | ## post state to fit panel |
---|
| 414 | #self._undo.Enable(True) |
---|
| 415 | event = PageInfoEvent(page = self) |
---|
| 416 | wx.PostEvent(self.parent, event) |
---|
| 417 | |
---|
| 418 | |
---|
| 419 | def set_model_description(self,description,sizer): |
---|
| 420 | """ |
---|
[74755ff] | 421 | fill a sizer with description |
---|
| 422 | |
---|
| 423 | :param description: of type string |
---|
| 424 | :param sizer: wx.BoxSizer() |
---|
| 425 | |
---|
[0277d084] | 426 | """ |
---|
| 427 | |
---|
| 428 | sizer.Clear(True) |
---|
| 429 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
| 430 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 431 | |
---|
| 432 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 433 | self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) |
---|
| 434 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
| 435 | |
---|
| 436 | |
---|
| 437 | if description=="": |
---|
| 438 | self.description_hide.SetValue(True) |
---|
| 439 | description=" Description unavailable. Click for details" |
---|
| 440 | |
---|
| 441 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
| 442 | |
---|
| 443 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 444 | id=self.description_hide.GetId() ) |
---|
| 445 | |
---|
| 446 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 447 | id=self.description_show.GetId() ) |
---|
| 448 | #MAC needs SetValue |
---|
| 449 | self.description_hide.SetValue(True) |
---|
| 450 | |
---|
| 451 | self.model_description = wx.Button(self,-1, label="Details", size=(80,23)) |
---|
| 452 | |
---|
| 453 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
| 454 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
| 455 | self.model_description.SetFocus() |
---|
| 456 | sizer_selection.Add( self.description_show ) |
---|
| 457 | sizer_selection.Add( (20,20)) |
---|
| 458 | sizer_selection.Add( self.description_hide ) |
---|
| 459 | sizer_selection.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,75) |
---|
| 460 | sizer_selection.Add( self.model_description ) |
---|
| 461 | |
---|
| 462 | |
---|
| 463 | self.sizer_description=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 464 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
| 465 | boxsizer1.Add( sizer_selection) |
---|
| 466 | boxsizer1.Add( (20,20)) |
---|
| 467 | boxsizer1.Add( self.sizer_description) |
---|
| 468 | |
---|
| 469 | self._on_display_description(event=None) |
---|
| 470 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 471 | sizer.Layout() |
---|
| 472 | |
---|
| 473 | def on_button_clicked(self,event): |
---|
| 474 | """ |
---|
[74755ff] | 475 | On 'More details' button |
---|
[0277d084] | 476 | """ |
---|
| 477 | from help_panel import HelpWindow |
---|
| 478 | |
---|
| 479 | if self.model == None: |
---|
| 480 | name = 'FuncHelp' |
---|
| 481 | else: |
---|
| 482 | name = self.model.name |
---|
[e071b1c] | 483 | frame = HelpWindow(None, -1, pageToOpen="media/model_functions.html") |
---|
[0277d084] | 484 | frame.Show(True) |
---|
| 485 | if frame.rhelp.HasAnchor(name): |
---|
| 486 | frame.rhelp.ScrollToAnchor(name) |
---|
| 487 | else: |
---|
| 488 | msg= "Model does not contains an available description " |
---|
| 489 | msg +="Please.Search in the Help window" |
---|
| 490 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 491 | |
---|
| 492 | def set_range(self, qmin_x, qmax_x, npts): |
---|
| 493 | """ |
---|
[74755ff] | 494 | Set the range for the plotted models |
---|
| 495 | |
---|
| 496 | :param qmin: minimum Q |
---|
| 497 | :param qmax: maximum Q |
---|
| 498 | :param npts: number of Q bins |
---|
| 499 | |
---|
[0277d084] | 500 | """ |
---|
| 501 | # Set the data members |
---|
| 502 | self.qmin_x = qmin_x |
---|
| 503 | self.qmax_x = qmax_x |
---|
| 504 | self.num_points = npts |
---|
| 505 | # Set the controls |
---|
| 506 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
| 507 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 508 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 509 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 510 | |
---|
| 511 | def set_model_param_sizer(self, model): |
---|
| 512 | """ |
---|
[74755ff] | 513 | Build the panel from the model content |
---|
| 514 | |
---|
| 515 | :param model: the model selected in combo box for fitting purpose |
---|
| 516 | |
---|
[0277d084] | 517 | """ |
---|
| 518 | self.sizer3.Clear(True) |
---|
| 519 | self.parameters = [] |
---|
| 520 | self.param_toFit=[] |
---|
| 521 | self.fixed_param=[] |
---|
| 522 | self.orientation_params=[] |
---|
| 523 | self.orientation_params_disp=[] |
---|
| 524 | #self.temp=[] |
---|
| 525 | if model ==None: |
---|
| 526 | ##no model avaiable to draw sizer |
---|
| 527 | self.sizer3.Layout() |
---|
| 528 | self.SetScrollbars(20,20,25,65) |
---|
| 529 | return |
---|
| 530 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 531 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 532 | sizer = wx.GridBagSizer(5,5) |
---|
| 533 | |
---|
| 534 | self.model = model |
---|
| 535 | self.set_model_description(self.model.description,self.sizer2) |
---|
| 536 | |
---|
| 537 | keys = self.model.getParamList() |
---|
| 538 | ##list of dispersion parameters |
---|
| 539 | self.disp_list=self.model.getDispParamList() |
---|
| 540 | |
---|
| 541 | keys.sort() |
---|
| 542 | |
---|
| 543 | iy = 0 |
---|
| 544 | ix = 0 |
---|
| 545 | self.text1_2 = wx.StaticText(self, -1, 'Names') |
---|
| 546 | sizer.Add(self.text1_2,(iy, ix),(1,1),\ |
---|
| 547 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 548 | ix +=1 |
---|
| 549 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 550 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 551 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 552 | ix +=1 |
---|
| 553 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 554 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 555 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 556 | self.text2_4.Hide() |
---|
| 557 | |
---|
| 558 | for item in keys: |
---|
| 559 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
| 560 | iy += 1 |
---|
| 561 | ix = 0 |
---|
| 562 | name = wx.StaticText(self, -1,item) |
---|
| 563 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 564 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 565 | |
---|
| 566 | ix += 1 |
---|
| 567 | value= self.model.getParam(item) |
---|
| 568 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 569 | style=wx.TE_PROCESS_ENTER) |
---|
| 570 | |
---|
| 571 | ctl1.SetValue(str (format_number(value))) |
---|
| 572 | |
---|
| 573 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 574 | ix +=1 |
---|
| 575 | # Units |
---|
| 576 | if self.model.details.has_key(item): |
---|
| 577 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 578 | else: |
---|
| 579 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 580 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 581 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 582 | self.parameters.append([None,item, ctl1, |
---|
| 583 | None,None, None, None,None]) |
---|
| 584 | iy+=1 |
---|
| 585 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 586 | iy += 1 |
---|
| 587 | ix = 0 |
---|
| 588 | |
---|
| 589 | #Add tile for orientational angle parameters |
---|
| 590 | for item in keys: |
---|
| 591 | if item in self.model.orientation_params: |
---|
| 592 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
| 593 | sizer.Add(orient_angle,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 594 | if not self.enable2D: |
---|
| 595 | orient_angle.Hide() |
---|
| 596 | else: |
---|
| 597 | orient_angle.Show(True) |
---|
| 598 | break |
---|
| 599 | |
---|
| 600 | for item in self.model.orientation_params: |
---|
| 601 | if not item in self.disp_list and item in keys: |
---|
| 602 | iy += 1 |
---|
| 603 | ix = 0 |
---|
| 604 | name = wx.StaticText(self, -1,item) |
---|
| 605 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 606 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 607 | if not self.enable2D: |
---|
| 608 | name.Hide() |
---|
| 609 | else: |
---|
| 610 | name.Show(True) |
---|
| 611 | |
---|
| 612 | ix += 1 |
---|
| 613 | value= self.model.getParam(item) |
---|
| 614 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 615 | style=wx.TE_PROCESS_ENTER) |
---|
| 616 | |
---|
| 617 | ctl1.SetValue(str (format_number(value))) |
---|
| 618 | if not self.enable2D: |
---|
| 619 | ctl1.Hide() |
---|
| 620 | ctl1.Disable() |
---|
| 621 | else: |
---|
| 622 | ctl1.Show(True) |
---|
| 623 | ctl1.Enable() |
---|
| 624 | |
---|
| 625 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 626 | ix +=1 |
---|
| 627 | # Units |
---|
| 628 | if self.model.details.has_key(item): |
---|
| 629 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 630 | else: |
---|
| 631 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 632 | if not self.enable2D: |
---|
| 633 | units.Hide() |
---|
| 634 | else: |
---|
| 635 | units.Show(True) |
---|
| 636 | |
---|
| 637 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 638 | #Save 2D orient. params |
---|
| 639 | #self.temp.append([name,ctl1,units,orient_angle]) |
---|
| 640 | |
---|
| 641 | |
---|
| 642 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 643 | self.parameters.append([None,item, ctl1, |
---|
| 644 | None,None, None, None,None]) |
---|
| 645 | self.orientation_params.append([None,item, ctl1, |
---|
[199cef2] | 646 | None,None, None, None,None]) |
---|
| 647 | iy += 1 |
---|
[0277d084] | 648 | |
---|
| 649 | #Display units text on panel |
---|
| 650 | for item in keys: |
---|
| 651 | self.text2_4.Show() |
---|
| 652 | |
---|
| 653 | boxsizer1.Add(sizer) |
---|
| 654 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 655 | self.sizer3.Layout() |
---|
| 656 | self.SetScrollbars(20,20,25,65) |
---|
| 657 | |
---|