[1b07935d] | 1 | import sys |
---|
| 2 | import wx |
---|
| 3 | import wx.lib |
---|
| 4 | import numpy |
---|
| 5 | import copy |
---|
| 6 | |
---|
| 7 | from sans.guicomm.events import StatusEvent |
---|
| 8 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
| 9 | _BOX_WIDTH = 80 |
---|
| 10 | |
---|
| 11 | def format_number(value, high=False): |
---|
| 12 | """ |
---|
| 13 | Return a float in a standardized, human-readable formatted string |
---|
| 14 | """ |
---|
| 15 | try: |
---|
| 16 | value = float(value) |
---|
| 17 | except: |
---|
| 18 | print "returning 0" |
---|
| 19 | return "0" |
---|
| 20 | |
---|
| 21 | if high: |
---|
| 22 | return "%-6.4g" % value |
---|
| 23 | else: |
---|
| 24 | return "%-5.3g" % value |
---|
| 25 | |
---|
| 26 | |
---|
[f39511b] | 27 | class ModelPage(wx.ScrolledWindow): |
---|
[1b07935d] | 28 | """ |
---|
| 29 | FitPanel class contains fields allowing to display results when |
---|
| 30 | fitting a model and one data |
---|
| 31 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 32 | on fit Panel window. |
---|
| 33 | |
---|
| 34 | """ |
---|
| 35 | ## Internal name for the AUI manager |
---|
| 36 | window_name = "Fit page" |
---|
| 37 | ## Title to appear on top of the window |
---|
| 38 | window_caption = "Fit Page" |
---|
| 39 | |
---|
| 40 | |
---|
[86c1832] | 41 | def __init__(self, parent,model,name, *args, **kwargs): |
---|
[f39511b] | 42 | wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) |
---|
[1b07935d] | 43 | """ |
---|
| 44 | Initialization of the Panel |
---|
| 45 | """ |
---|
[f39511b] | 46 | #self.scroll = wx.ScrolledWindow(self) |
---|
[1b07935d] | 47 | self.manager = None |
---|
| 48 | self.parent = parent |
---|
| 49 | self.event_owner=None |
---|
| 50 | #panel interface |
---|
| 51 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 52 | self.sizer3 = wx.GridBagSizer(5,5) |
---|
[49b7efa] | 53 | self.sizer1 = wx.GridBagSizer(5,5) |
---|
[1b07935d] | 54 | self.sizer2 = wx.GridBagSizer(5,5) |
---|
[00561739] | 55 | self.sizer4 = wx.GridBagSizer(5,5) |
---|
[04edd0d] | 56 | self.sizer5 = wx.GridBagSizer(5,5) |
---|
| 57 | self.static_line_1 = wx.StaticLine(self, -1) |
---|
[1b07935d] | 58 | self.modelbox = wx.ComboBox(self, -1) |
---|
| 59 | id = wx.NewId() |
---|
| 60 | self.vbox.Add(self.sizer3) |
---|
[49b7efa] | 61 | self.vbox.Add(self.sizer1) |
---|
[1b07935d] | 62 | self.vbox.Add(self.sizer2) |
---|
[04edd0d] | 63 | self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) |
---|
| 64 | self.vbox.Add(self.sizer5) |
---|
[00561739] | 65 | self.vbox.Add(self.sizer4) |
---|
| 66 | |
---|
| 67 | id = wx.NewId() |
---|
| 68 | self.btClose =wx.Button(self,id,'Close') |
---|
| 69 | self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) |
---|
| 70 | self.btClose.SetToolTipString("Close page.") |
---|
[86c1832] | 71 | ix = 1 |
---|
[dc317d1] | 72 | iy = 1 |
---|
| 73 | self.sizer4.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ |
---|
| 74 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[d15c0202] | 75 | ix += 1 |
---|
[dc317d1] | 76 | self.sizer4.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ |
---|
| 77 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[d15c0202] | 78 | ix += 1 |
---|
| 79 | self.sizer4.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ |
---|
| 80 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[dc317d1] | 81 | ix = 0 |
---|
| 82 | iy += 1 |
---|
| 83 | self.sizer4.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ |
---|
| 84 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[24ea33c] | 85 | ## Q range |
---|
| 86 | self.qmin= 0.001 |
---|
| 87 | self.qmax= 0.1 |
---|
[d15c0202] | 88 | self.num_points= 100 |
---|
[24ea33c] | 89 | |
---|
[dc317d1] | 90 | ix += 1 |
---|
| 91 | self.xmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
[24ea33c] | 92 | self.xmin.SetValue(format_number(self.qmin)) |
---|
[dc317d1] | 93 | self.xmin.SetToolTipString("Minimun value of x in linear scale.") |
---|
| 94 | self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 95 | self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 96 | self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[00561739] | 97 | |
---|
[dc317d1] | 98 | |
---|
[d15c0202] | 99 | ix += 1 |
---|
[dc317d1] | 100 | self.xmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
[24ea33c] | 101 | self.xmax.SetValue(format_number(self.qmax)) |
---|
[dc317d1] | 102 | self.xmax.SetToolTipString("Maximum value of x in linear scale.") |
---|
| 103 | self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 104 | self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 105 | self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[d15c0202] | 106 | ix += 1 |
---|
| 107 | self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
| 108 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 109 | self.npts.SetToolTipString("Number of point to plot.") |
---|
| 110 | self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 111 | self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 112 | |
---|
| 113 | self.sizer4.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[dc317d1] | 114 | ix = 0 |
---|
| 115 | iy += 1 |
---|
| 116 | self.sizer4.Add((20,20),(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 117 | ix +=3 |
---|
[00561739] | 118 | self.sizer4.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[1b07935d] | 119 | ix = 0 |
---|
| 120 | iy = 1 |
---|
| 121 | self.sizer3.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ |
---|
| 122 | , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 123 | ix += 1 |
---|
| 124 | self.sizer3.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[86c1832] | 125 | #ix = 0 |
---|
| 126 | #iy += 1 |
---|
| 127 | ix += 1 |
---|
| 128 | id = wx.NewId() |
---|
| 129 | self.model_view =wx.Button(self,id,'View 2D') |
---|
| 130 | self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) |
---|
| 131 | self.model_view.SetToolTipString("View model in 2D") |
---|
[f39511b] | 132 | self.sizer3.Add(self.model_view,(iy,ix),(1,1),\ |
---|
| 133 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[1b07935d] | 134 | # contains link between model ,all its parameters, and panel organization |
---|
| 135 | self.parameters=[] |
---|
| 136 | #contains link between a model and selected parameters to fit |
---|
| 137 | self.param_toFit=[] |
---|
| 138 | # model on which the fit would be performed |
---|
| 139 | self.model=model |
---|
[2dbb681] | 140 | try: |
---|
[f39511b] | 141 | #print"init modelpage",model.name |
---|
[2dbb681] | 142 | self.set_panel(model) |
---|
| 143 | except: |
---|
| 144 | raise |
---|
[1b07935d] | 145 | # preview selected model name |
---|
[86c1832] | 146 | self.prevmodel_name=name |
---|
[d15c0202] | 147 | #print "model view prev_model",name |
---|
[1b07935d] | 148 | self.modelbox.SetValue(self.prevmodel_name) |
---|
| 149 | # flag to check if the user has selected a new model in the combox box |
---|
| 150 | self.model_hasChanged=False |
---|
| 151 | #dictionary of model name and model class |
---|
| 152 | self.model_list_box={} |
---|
[86c1832] | 153 | |
---|
| 154 | #enable model 2D draw |
---|
| 155 | self.enable2D= False |
---|
[1b07935d] | 156 | # Data1D to make a deep comparison between 2 Data1D for checking data |
---|
| 157 | #change |
---|
| 158 | self.vbox.Layout() |
---|
| 159 | self.vbox.Fit(self) |
---|
[f39511b] | 160 | |
---|
[1b07935d] | 161 | self.SetSizer(self.vbox) |
---|
[f39511b] | 162 | self.SetScrollbars(20,20,55,40) |
---|
[1b07935d] | 163 | self.Centre() |
---|
[2dbb681] | 164 | |
---|
[cfc68540] | 165 | def set_range(self, qmin, qmax, npts): |
---|
| 166 | """ |
---|
| 167 | Set the range for the plotted models |
---|
| 168 | @param qmin: minimum Q |
---|
| 169 | @param qmax: maximum Q |
---|
| 170 | @param npts: number of Q bins |
---|
| 171 | """ |
---|
| 172 | # Set the data members |
---|
| 173 | self.qmin = qmin |
---|
| 174 | self.qmax = qmax |
---|
| 175 | self.num_points = npts |
---|
| 176 | |
---|
| 177 | # Set the controls |
---|
| 178 | self.xmin.SetValue(format_number(self.qmin)) |
---|
| 179 | self.xmax.SetValue(format_number(self.qmax)) |
---|
| 180 | self.npts.SetValue(format_number(self.num_points)) |
---|
[1b07935d] | 181 | |
---|
[00561739] | 182 | def onClose(self,event): |
---|
| 183 | """ close the page associated with this panel""" |
---|
| 184 | self.GrandParent.onClose() |
---|
| 185 | |
---|
[1b07935d] | 186 | def set_owner(self,owner): |
---|
| 187 | """ |
---|
| 188 | set owner of fitpage |
---|
| 189 | @param owner: the class responsible of plotting |
---|
| 190 | """ |
---|
| 191 | self.event_owner=owner |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | def set_manager(self, manager): |
---|
| 195 | """ |
---|
| 196 | set panel manager |
---|
| 197 | @param manager: instance of plugin fitting |
---|
| 198 | """ |
---|
| 199 | self.manager = manager |
---|
[dc317d1] | 200 | |
---|
[f39511b] | 201 | def onModel2D(self, event): |
---|
[86c1832] | 202 | """ |
---|
| 203 | call manager to plot model in 2D |
---|
| 204 | """ |
---|
[24ea33c] | 205 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
| 206 | # and set the enable2D flag. |
---|
| 207 | if self.enable2D==False: |
---|
| 208 | self.enable2D=True |
---|
[cfc68540] | 209 | self._draw_model() |
---|
[89032bf] | 210 | |
---|
[32673ac] | 211 | else: |
---|
[89032bf] | 212 | print "enable is true:",self.enable2D |
---|
| 213 | #self.manager.parent. show_panel(147) |
---|
| 214 | self.manager.show_panel2D( id=None ) |
---|
| 215 | #self.manager.menu1.Append(event_id, new_panel.window_caption, |
---|
| 216 | # "Show %s plot panel" % new_panel.window_caption) |
---|
[24ea33c] | 217 | |
---|
[1b07935d] | 218 | def populate_box(self, dict): |
---|
| 219 | """ |
---|
| 220 | Populate each combox box of each page |
---|
| 221 | @param page: the page to populate |
---|
| 222 | """ |
---|
| 223 | id=0 |
---|
| 224 | self.model_list_box=dict |
---|
[2dbb681] | 225 | list_name=[] |
---|
| 226 | for item in self.model_list_box.itervalues(): |
---|
| 227 | name = item.__name__ |
---|
[86c1832] | 228 | if hasattr(item, "name"): |
---|
| 229 | name = item.name |
---|
[2dbb681] | 230 | list_name.append(name) |
---|
| 231 | list_name.sort() |
---|
| 232 | for name in list_name: |
---|
[1b07935d] | 233 | self.modelbox.Insert(name,int(id)) |
---|
| 234 | id+=1 |
---|
[2dbb681] | 235 | wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) |
---|
[1b07935d] | 236 | return 0 |
---|
[86c1832] | 237 | |
---|
[3dc83be] | 238 | def select_model(self, model): |
---|
| 239 | """ |
---|
| 240 | Select a new model |
---|
| 241 | @param model: model object |
---|
| 242 | """ |
---|
| 243 | self.model= model |
---|
| 244 | self.set_panel(model) |
---|
| 245 | self._draw_model() |
---|
| 246 | |
---|
| 247 | # Select the model from the combo box |
---|
| 248 | items = self.modelbox.GetItems() |
---|
| 249 | for i in range(len(items)): |
---|
| 250 | if items[i]==model.__class__.__name__: |
---|
| 251 | self.modelbox.SetSelection(i) |
---|
| 252 | |
---|
[1b07935d] | 253 | def _on_select_model(self,event): |
---|
| 254 | """ |
---|
| 255 | react when a model is selected from page's combo box |
---|
| 256 | post an event to its owner to draw an appropriate theory |
---|
| 257 | """ |
---|
[d23544dc] | 258 | self.model_view.SetFocus() |
---|
[1b07935d] | 259 | for item in self.model_list_box.itervalues(): |
---|
[2dbb681] | 260 | name = item.__name__ |
---|
[86c1832] | 261 | if hasattr(item, "name"): |
---|
| 262 | name = item.name |
---|
[2dbb681] | 263 | if name ==event.GetString(): |
---|
[86c1832] | 264 | model=item() |
---|
[b2c3225] | 265 | self.model= model |
---|
[2dbb681] | 266 | self.set_panel(model) |
---|
[86c1832] | 267 | self.name= name |
---|
[cfc68540] | 268 | #self.manager.draw_model(model, name) |
---|
[89032bf] | 269 | self.enable2D=False |
---|
[cfc68540] | 270 | self._draw_model() |
---|
[d23544dc] | 271 | |
---|
[1b07935d] | 272 | |
---|
| 273 | def get_model_box(self): |
---|
| 274 | """ return reference to combox box self.model""" |
---|
| 275 | return self.modelbox |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | def get_param_list(self): |
---|
| 279 | """ |
---|
| 280 | @return self.param_toFit: list containing references to TextCtrl |
---|
| 281 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
| 282 | @raise: if return an empty list of parameter fit will nnote work |
---|
| 283 | properly so raise ValueError,"missing parameter to fit" |
---|
| 284 | """ |
---|
| 285 | if self.param_toFit !=[]: |
---|
| 286 | return self.param_toFit |
---|
| 287 | else: |
---|
| 288 | raise ValueError,"missing parameter to fit" |
---|
| 289 | |
---|
| 290 | |
---|
[2dbb681] | 291 | def set_panel(self,model): |
---|
[1b07935d] | 292 | """ |
---|
| 293 | Build the panel from the model content |
---|
| 294 | @param model: the model selected in combo box for fitting purpose |
---|
| 295 | """ |
---|
[2dbb681] | 296 | |
---|
[1b07935d] | 297 | self.sizer2.Clear(True) |
---|
[49b7efa] | 298 | self.sizer1.Clear(True) |
---|
[04edd0d] | 299 | self.sizer5.Clear(True) |
---|
[1b07935d] | 300 | self.parameters = [] |
---|
| 301 | self.param_toFit=[] |
---|
| 302 | self.model = model |
---|
| 303 | keys = self.model.getParamList() |
---|
| 304 | keys.sort() |
---|
[5cab7d3] | 305 | description=None |
---|
| 306 | if hasattr(self.model,'description'): |
---|
| 307 | description =model.description |
---|
[04edd0d] | 308 | disp_list=self.model.getDispParamList() |
---|
| 309 | ip=0 |
---|
| 310 | iq=1 |
---|
| 311 | if len(disp_list)>0: |
---|
| 312 | disp = wx.StaticText(self, -1, 'Dispersion') |
---|
| 313 | self.sizer5.Add(disp,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 314 | ip += 1 |
---|
| 315 | values = wx.StaticText(self, -1, 'Values') |
---|
| 316 | self.sizer5.Add(values,( iq, ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 317 | |
---|
| 318 | disp_list.sort() |
---|
[f39511b] | 319 | #print "went here",self.model.name,model.description |
---|
[1b07935d] | 320 | iy = 1 |
---|
| 321 | ix = 0 |
---|
[49b7efa] | 322 | self.cb0 = wx.StaticText(self, -1,'Model Description:') |
---|
| 323 | self.sizer1.Add(self.cb0,(iy, ix),(1,1),\ |
---|
| 324 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[d171299] | 325 | iy += 1 |
---|
| 326 | |
---|
| 327 | self.cb01 = wx.StaticText(self, -1,str(description),style=wx.ALIGN_LEFT) |
---|
| 328 | self.cb01.Wrap(400) |
---|
| 329 | #self.cb01 = wx.StaticText(self, -1,str(description),(45, 25),style=wx.ALIGN_LEFT) |
---|
| 330 | |
---|
[49b7efa] | 331 | self.sizer1.Add(self.cb01,(iy, ix),(1,1),\ |
---|
| 332 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 333 | ix = 0 |
---|
| 334 | iy = 1 |
---|
[1b07935d] | 335 | self.cb1 = wx.StaticText(self, -1,'Parameters') |
---|
| 336 | self.sizer2.Add(self.cb1,(iy, ix),(1,1),\ |
---|
| 337 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 338 | ix +=1 |
---|
| 339 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 340 | self.sizer2.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 341 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 342 | ix +=1 |
---|
| 343 | self.text2_4 = wx.StaticText(self, -1, 'Units') |
---|
| 344 | self.sizer2.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 345 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 346 | self.text2_4.Hide() |
---|
| 347 | for item in keys: |
---|
[04edd0d] | 348 | if not item in disp_list: |
---|
| 349 | iy += 1 |
---|
| 350 | ix = 0 |
---|
| 351 | cb=wx.StaticText(self, -1, item) |
---|
| 352 | self.sizer2.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 353 | ix += 1 |
---|
| 354 | value= self.model.getParam(item) |
---|
| 355 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 356 | ctl1.SetValue(str (format_number(value))) |
---|
| 357 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 358 | ctl1.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 359 | self.sizer2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 360 | ix +=1 |
---|
| 361 | |
---|
| 362 | # Units |
---|
| 363 | try: |
---|
| 364 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 365 | except: |
---|
| 366 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 367 | self.sizer2.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 368 | else: |
---|
| 369 | ip = 0 |
---|
| 370 | iq += 1 |
---|
[2eb40c5] | 371 | cb=wx.StaticText(self, -1, item) |
---|
[04edd0d] | 372 | self.sizer5.Add( cb,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 373 | wx.EVT_CHECKBOX(self, cb.GetId(), self._on_select_model) |
---|
| 374 | |
---|
| 375 | ip += 1 |
---|
| 376 | value= self.model.getParam(item) |
---|
| 377 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 378 | ctl1.SetValue(str (format_number(value))) |
---|
| 379 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 380 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 381 | self.sizer5.Add(ctl1, (iq,ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[1b07935d] | 382 | #save data |
---|
| 383 | self.parameters.append([cb,ctl1]) |
---|
[04edd0d] | 384 | iy+=1 |
---|
| 385 | self.sizer2.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 386 | |
---|
[1b07935d] | 387 | #Display units text on panel |
---|
| 388 | for item in keys: |
---|
| 389 | if self.model.details[item][0]!='': |
---|
| 390 | self.text2_4.Show() |
---|
| 391 | break |
---|
| 392 | else: |
---|
| 393 | self.text2_4.Hide() |
---|
| 394 | self.vbox.Layout() |
---|
| 395 | self.GrandParent.GetSizer().Layout() |
---|
[04edd0d] | 396 | |
---|
[1b07935d] | 397 | |
---|
| 398 | def _onparamEnter(self,event): |
---|
| 399 | """ |
---|
| 400 | when enter value on panel redraw model according to changed |
---|
| 401 | """ |
---|
| 402 | self.set_model_parameter() |
---|
| 403 | |
---|
| 404 | def set_model_parameter(self): |
---|
| 405 | if len(self.parameters) !=0 and self.model !=None: |
---|
[24ea33c] | 406 | # Flag to register when a parameter has changed. |
---|
| 407 | is_modified = False |
---|
[db709e4] | 408 | for item in self.parameters: |
---|
[a5aaec9] | 409 | try: |
---|
| 410 | name=str(item[0].GetLabelText()) |
---|
| 411 | value= float(item[1].GetValue()) |
---|
| 412 | # If the value of the parameter has changed, |
---|
| 413 | # update the model and set the is_modified flag |
---|
| 414 | if value != self.model.getParam(name): |
---|
| 415 | self.model.setParam(name,value) |
---|
| 416 | is_modified = True |
---|
[db709e4] | 417 | except: |
---|
| 418 | wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ |
---|
| 419 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
| 420 | |
---|
| 421 | # Here we should check whether the boundaries have been modified. |
---|
| 422 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
| 423 | # set the is_modified flag to True |
---|
[a5aaec9] | 424 | if float(self.xmin.GetValue()) != self.qmin: |
---|
| 425 | self.qmin = float(self.xmin.GetValue()) |
---|
| 426 | is_modified = True |
---|
| 427 | if float(self.xmax.GetValue()) != self.qmax: |
---|
| 428 | self.qmax = float(self.xmax.GetValue()) |
---|
| 429 | is_modified = True |
---|
[e9b4cc4] | 430 | |
---|
[ea20505] | 431 | if float(self.npts.GetValue()) != self.num_points: |
---|
| 432 | self.num_points = float(self.npts.GetValue()) |
---|
| 433 | is_modified = True |
---|
[e9b4cc4] | 434 | |
---|
[a5aaec9] | 435 | if is_modified: |
---|
[cfc68540] | 436 | self._draw_model() |
---|
[2e10b70] | 437 | |
---|
[cfc68540] | 438 | def _draw_model(self): |
---|
| 439 | """ |
---|
| 440 | Method to draw or refresh a plotted model. |
---|
| 441 | The method will use the data member from the model page |
---|
| 442 | to build a call to the fitting perspective manager. |
---|
[2e10b70] | 443 | |
---|
[cfc68540] | 444 | [Note to coder: This way future changes will be done in only one place.] |
---|
| 445 | """ |
---|
| 446 | self.manager.draw_model(self.model, self.model.name, |
---|
| 447 | qmin=self.qmin, qmax=self.qmax, |
---|
| 448 | qstep= self.num_points, |
---|
| 449 | enable2D=self.enable2D) |
---|
| 450 | |
---|
[32673ac] | 451 | |
---|
[a5aaec9] | 452 | |
---|