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