[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: |
---|
| 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 |
---|
[3595309d] | 319 | self._undo.Enable(True) |
---|
[dad49a0] | 320 | event = PageInfoEvent(page = self) |
---|
| 321 | wx.PostEvent(self.parent, event) |
---|
| 322 | |
---|
| 323 | |
---|
[2097efb] | 324 | |
---|
| 325 | def reset_page(self, state): |
---|
| 326 | """ |
---|
| 327 | reset the state |
---|
| 328 | """ |
---|
| 329 | self.reset_page_helper(state) |
---|
| 330 | |
---|
| 331 | |
---|
[fbf4bf8] | 332 | def select_model(self, model): |
---|
[3dc83be] | 333 | """ |
---|
| 334 | Select a new model |
---|
| 335 | @param model: model object |
---|
| 336 | """ |
---|
[ef8b580] | 337 | self.model = model |
---|
[71f0373] | 338 | if self.model !=None: |
---|
| 339 | self.disp_list= self.model.getDispParamList() |
---|
[70c57ebf] | 340 | self.set_model_param_sizer(self.model) |
---|
[c77d859] | 341 | ## keep the sizer view consistent with the model menu selecting |
---|
[376916c] | 342 | self._set_model_sizer_selection( self.model ) |
---|
[3b605bb] | 343 | self.enable_disp.SetValue(False) |
---|
| 344 | self.disable_disp.SetValue(True) |
---|
[1c1436d] | 345 | self.set_dispers_sizer() |
---|
[848a2ef] | 346 | |
---|
[c77d859] | 347 | self.model_view.SetFocus() |
---|
[70c57ebf] | 348 | if self.model !=None: |
---|
| 349 | self._draw_model() |
---|
[3b9e023] | 350 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 351 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 352 | #print "_on_select_model",self.state.structurecombobox,self.state.formfactorcombobox |
---|
| 353 | |
---|
[330573d] | 354 | ## post state to fit panel |
---|
[3595309d] | 355 | self._undo.Enable(True) |
---|
[330573d] | 356 | event = PageInfoEvent(page = self) |
---|
| 357 | wx.PostEvent(self.parent, event) |
---|
| 358 | |
---|
[c77d859] | 359 | |
---|
| 360 | def set_model_description(self,description,sizer): |
---|
[1b07935d] | 361 | """ |
---|
[c77d859] | 362 | fill a sizer with description |
---|
| 363 | @param description: of type string |
---|
| 364 | @param sizer: wx.BoxSizer() |
---|
[1b07935d] | 365 | """ |
---|
[c77d859] | 366 | |
---|
| 367 | sizer.Clear(True) |
---|
| 368 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
| 369 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
[848a2ef] | 370 | |
---|
[c77d859] | 371 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
[6ea1b87] | 372 | self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) |
---|
[a81e613] | 373 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
| 374 | |
---|
[51d47b5] | 375 | |
---|
[c77d859] | 376 | if description=="": |
---|
| 377 | self.description_hide.SetValue(True) |
---|
| 378 | description=" Description unavailable. Click for details" |
---|
[bb18ef1] | 379 | |
---|
[c77d859] | 380 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
[51d47b5] | 381 | |
---|
[c77d859] | 382 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 383 | id=self.description_hide.GetId() ) |
---|
[51d47b5] | 384 | |
---|
[c77d859] | 385 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 386 | id=self.description_show.GetId() ) |
---|
[51d47b5] | 387 | |
---|
[fa58441] | 388 | self.model_description = wx.Button(self,-1, label="Details") |
---|
[9d091ed] | 389 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
| 390 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
[a074145] | 391 | |
---|
[c77d859] | 392 | sizer_selection.Add( self.description_show ) |
---|
| 393 | sizer_selection.Add( (20,20)) |
---|
| 394 | sizer_selection.Add( self.description_hide ) |
---|
[fa58441] | 395 | sizer_selection.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,67) |
---|
[c77d859] | 396 | sizer_selection.Add( self.model_description ) |
---|
[fa58441] | 397 | |
---|
[c77d859] | 398 | |
---|
| 399 | self.sizer_description=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 400 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
| 401 | boxsizer1.Add( sizer_selection) |
---|
| 402 | boxsizer1.Add( (20,20)) |
---|
| 403 | boxsizer1.Add( self.sizer_description) |
---|
| 404 | |
---|
[6ea1b87] | 405 | self._on_display_description(event=None) |
---|
[c77d859] | 406 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 407 | sizer.Layout() |
---|
| 408 | |
---|
[9d091ed] | 409 | def on_button_clicked(self,event): |
---|
| 410 | """ |
---|
[b94a0a6] | 411 | #On 'More details' button |
---|
| 412 | """ |
---|
[9d091ed] | 413 | from helpPanel import HelpWindow |
---|
[1d64748] | 414 | |
---|
[1f9ff448] | 415 | if self.model == None: |
---|
[1d64748] | 416 | name = 'FuncHelp' |
---|
[1f9ff448] | 417 | else: |
---|
| 418 | name = self.model.name |
---|
[1d64748] | 419 | frame = HelpWindow(None, -1, name) |
---|
[9d091ed] | 420 | frame.Show(True) |
---|
[6fb01b6] | 421 | if frame.rhelp.HasAnchor(name): |
---|
| 422 | frame.rhelp.ScrollToAnchor(name) |
---|
[27976fd0] | 423 | else: |
---|
| 424 | msg= "Model does not contains an available description " |
---|
| 425 | msg +="Please.Search in the Help window" |
---|
| 426 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 427 | |
---|
[6fb01b6] | 428 | |
---|
| 429 | |
---|
[aa306e4] | 430 | def set_range(self, qmin_x, qmax_x, npts): |
---|
[ed2ea6a] | 431 | """ |
---|
[c77d859] | 432 | Set the range for the plotted models |
---|
| 433 | @param qmin: minimum Q |
---|
| 434 | @param qmax: maximum Q |
---|
| 435 | @param npts: number of Q bins |
---|
[ed2ea6a] | 436 | """ |
---|
[c77d859] | 437 | # Set the data members |
---|
| 438 | self.qmin_x = qmin_x |
---|
| 439 | self.qmax_x = qmax_x |
---|
| 440 | self.num_points = npts |
---|
[26bf293] | 441 | |
---|
[c77d859] | 442 | # Set the controls |
---|
[b5e98540] | 443 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
| 444 | """ |
---|
[c77d859] | 445 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
| 446 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
| 447 | self.npts.SetValue(format_number(self.num_points)) |
---|
[b5e98540] | 448 | """ |
---|
[aa1e9a72] | 449 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 450 | self.qmax.SetValue(str(self.qmax_x)) |
---|
[b5e98540] | 451 | self.npts.SetValue(format_number(self.num_points)) |
---|
[51d47b5] | 452 | |
---|
[c77d859] | 453 | |
---|
| 454 | def set_model_param_sizer(self, model): |
---|
[51d47b5] | 455 | """ |
---|
[c77d859] | 456 | Build the panel from the model content |
---|
| 457 | @param model: the model selected in combo box for fitting purpose |
---|
[51d47b5] | 458 | """ |
---|
[c77d859] | 459 | self.sizer3.Clear(True) |
---|
| 460 | self.parameters = [] |
---|
| 461 | self.param_toFit=[] |
---|
| 462 | self.fixed_param=[] |
---|
[780d095] | 463 | self.orientation_params=[] |
---|
[60132ef] | 464 | self.orientation_params_disp=[] |
---|
[c77d859] | 465 | if model ==None: |
---|
| 466 | ##no model avaiable to draw sizer |
---|
[fbf4bf8] | 467 | self.sizer3.Layout() |
---|
| 468 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 469 | return |
---|
| 470 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 471 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 472 | sizer = wx.GridBagSizer(5,5) |
---|
[1b07935d] | 473 | |
---|
[c77d859] | 474 | self.model = model |
---|
| 475 | self.set_model_description(self.model.description,self.sizer2) |
---|
| 476 | |
---|
| 477 | keys = self.model.getParamList() |
---|
[780d095] | 478 | ##list of dispersion parameters |
---|
[c77d859] | 479 | self.disp_list=self.model.getDispParamList() |
---|
| 480 | |
---|
| 481 | keys.sort() |
---|
| 482 | |
---|
| 483 | iy = 1 |
---|
| 484 | ix = 0 |
---|
| 485 | self.text1_2 = wx.StaticText(self, -1, 'Names') |
---|
| 486 | sizer.Add(self.text1_2,(iy, ix),(1,1),\ |
---|
| 487 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 488 | ix +=1 |
---|
[d1e0473] | 489 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 490 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 491 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[6fdfc8f] | 492 | ix +=1 |
---|
| 493 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 494 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 495 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 496 | self.text2_4.Hide() |
---|
[c77d859] | 497 | |
---|
| 498 | for item in keys: |
---|
[780d095] | 499 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
[c77d859] | 500 | iy += 1 |
---|
| 501 | ix = 0 |
---|
| 502 | name = wx.StaticText(self, -1,item) |
---|
| 503 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 504 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[d1e0473] | 505 | |
---|
[c77d859] | 506 | ix += 1 |
---|
| 507 | value= self.model.getParam(item) |
---|
| 508 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[8bd4dc0] | 509 | style=wx.TE_PROCESS_ENTER) |
---|
[26bf293] | 510 | |
---|
[c77d859] | 511 | ctl1.SetValue(str (format_number(value))) |
---|
[1328e03] | 512 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
[77e23a2] | 513 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
[c77d859] | 514 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
[1328e03] | 515 | |
---|
[c77d859] | 516 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
[6fdfc8f] | 517 | ix +=1 |
---|
| 518 | # Units |
---|
| 519 | try: |
---|
| 520 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 521 | except: |
---|
| 522 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 523 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[780d095] | 524 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 525 | self.parameters.append([None,item, ctl1, |
---|
| 526 | None,None, None, None,None]) |
---|
| 527 | iy+=1 |
---|
| 528 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 529 | for item in self.model.orientation_params: |
---|
| 530 | if not item in self.disp_list : |
---|
| 531 | iy += 1 |
---|
| 532 | ix = 0 |
---|
| 533 | name = wx.StaticText(self, -1,item) |
---|
| 534 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 535 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[d1e0473] | 536 | |
---|
[780d095] | 537 | ix += 1 |
---|
| 538 | value= self.model.getParam(item) |
---|
| 539 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 540 | style=wx.TE_PROCESS_ENTER) |
---|
[ed2ea6a] | 541 | |
---|
[780d095] | 542 | ctl1.SetValue(str (format_number(value))) |
---|
[a7fe3e3] | 543 | if not self.enable2D: |
---|
| 544 | ctl1.Disable() |
---|
| 545 | else: |
---|
| 546 | ctl1.Enable() |
---|
[780d095] | 547 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 548 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 549 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 550 | |
---|
| 551 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
[6fdfc8f] | 552 | ix +=1 |
---|
| 553 | # Units |
---|
| 554 | try: |
---|
| 555 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 556 | except: |
---|
| 557 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 558 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[d1e0473] | 559 | |
---|
[c77d859] | 560 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 561 | self.parameters.append([None,item, ctl1, |
---|
| 562 | None,None, None, None,None]) |
---|
[780d095] | 563 | self.orientation_params.append([None,item, ctl1, |
---|
| 564 | None,None, None, None,None]) |
---|
[ed2ea6a] | 565 | |
---|
[c77d859] | 566 | iy+=1 |
---|
[2a5bba7] | 567 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[c77d859] | 568 | |
---|
| 569 | #Display units text on panel |
---|
| 570 | for item in keys: |
---|
| 571 | if self.model.details[item][0]!='': |
---|
| 572 | self.text2_4.Show() |
---|
| 573 | break |
---|
[bb18ef1] | 574 | else: |
---|
[c77d859] | 575 | self.text2_4.Hide() |
---|
[71f0373] | 576 | |
---|
[c77d859] | 577 | boxsizer1.Add(sizer) |
---|
| 578 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 579 | self.sizer3.Layout() |
---|
| 580 | self.SetScrollbars(20,20,200,100) |
---|
[8bd4dc0] | 581 | |
---|
[dfae8b3] | 582 | |
---|
[2e10b70] | 583 | |
---|
[c77d859] | 584 | |
---|
| 585 | class HelpWindow(wx.Frame): |
---|
| 586 | def __init__(self, parent, id, title): |
---|
| 587 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
[ef8b580] | 588 | |
---|
[c77d859] | 589 | from sans.models.CylinderModel import CylinderModel |
---|
| 590 | model = CylinderModel() |
---|
| 591 | #from sans.models.LineModel import LineModel |
---|
| 592 | #model = LineModel() |
---|
[cfc0913] | 593 | from fitpanel import PageInfo |
---|
[c77d859] | 594 | myinfo = PageInfo(self,model) |
---|
| 595 | from models import ModelList |
---|
| 596 | mylist= ModelList() |
---|
[fbc3e04] | 597 | |
---|
[c77d859] | 598 | from sans.models.SphereModel import SphereModel |
---|
| 599 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
| 600 | from sans.models.DebyeModel import DebyeModel |
---|
| 601 | from sans.models.LineModel import LineModel |
---|
| 602 | name= "shapes" |
---|
| 603 | list1= [SphereModel] |
---|
| 604 | mylist.set_list( name, list1) |
---|
[fbc3e04] | 605 | |
---|
[c77d859] | 606 | name= "Shape-independent" |
---|
| 607 | list1= [DebyeModel] |
---|
| 608 | mylist.set_list( name, list1) |
---|
| 609 | |
---|
| 610 | name= "Structure Factors" |
---|
| 611 | list1= [SquareWellStructure] |
---|
| 612 | mylist.set_list( name, list1) |
---|
| 613 | |
---|
| 614 | name= "Added models" |
---|
| 615 | list1= [LineModel] |
---|
| 616 | mylist.set_list( name, list1) |
---|
| 617 | |
---|
| 618 | myinfo.model_list_box = mylist.get_list() |
---|
| 619 | |
---|
| 620 | self.page = ModelPage(self, myinfo) |
---|
| 621 | |
---|
| 622 | |
---|
| 623 | |
---|
| 624 | self.Centre() |
---|
| 625 | self.Show(True) |
---|
| 626 | |
---|
| 627 | |
---|
| 628 | |
---|
| 629 | if __name__=="__main__": |
---|
| 630 | app = wx.App() |
---|
| 631 | HelpWindow(None, -1, 'HelpWindow') |
---|
| 632 | app.MainLoop() |
---|
| 633 | |
---|