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