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