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