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