[d89f09b] | 1 | |
---|
[2140e68] | 2 | import sys,re,string, wx |
---|
| 3 | import wx.lib.newevent |
---|
[d89f09b] | 4 | from sans.guicomm.events import StatusEvent |
---|
| 5 | |
---|
[8bd4dc0] | 6 | |
---|
| 7 | def get_fittableParam( model): |
---|
[2140e68] | 8 | """ |
---|
[8bd4dc0] | 9 | @return list of fittable parameters name of a model |
---|
| 10 | @param model: the model used |
---|
[2140e68] | 11 | """ |
---|
[8bd4dc0] | 12 | fittable_param=[] |
---|
| 13 | |
---|
| 14 | for item in model.getParamList(): |
---|
| 15 | if not item in model.getDispParamList(): |
---|
| 16 | fittable_param.append(item) |
---|
| 17 | |
---|
| 18 | for item in model.fixed: |
---|
| 19 | fittable_param.append(item) |
---|
[2140e68] | 20 | |
---|
[8bd4dc0] | 21 | return fittable_param |
---|
[2140e68] | 22 | |
---|
[3aae6b6] | 23 | class SimultaneousFitPage(wx.ScrolledWindow): |
---|
[d89f09b] | 24 | """ |
---|
| 25 | Simultaneous fitting panel |
---|
| 26 | All that needs to be defined are the |
---|
| 27 | two data members window_name and window_caption |
---|
| 28 | """ |
---|
[925a30e] | 29 | ## Internal name for the AUI manager |
---|
[d89f09b] | 30 | window_name = "simultaneous Fit page" |
---|
| 31 | ## Title to appear on top of the window |
---|
| 32 | window_caption = "Simultaneous Fit Page" |
---|
| 33 | |
---|
| 34 | |
---|
[2140e68] | 35 | def __init__(self, parent,page_finder ={}, *args, **kwargs): |
---|
[3aae6b6] | 36 | wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) |
---|
[d89f09b] | 37 | """ |
---|
| 38 | Simultaneous page display |
---|
| 39 | """ |
---|
| 40 | self.parent = parent |
---|
[2140e68] | 41 | ## store page_finder |
---|
[b28717b] | 42 | self.page_finder = page_finder |
---|
[2140e68] | 43 | ## list contaning info to set constraint |
---|
[8bd4dc0] | 44 | ## look like self.constraint_dict[page]= page |
---|
[2140e68] | 45 | self.constraint_dict={} |
---|
| 46 | ## item list self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] |
---|
| 47 | self.constraints_list=[] |
---|
| 48 | ## list of current model |
---|
| 49 | self.model_list=[] |
---|
| 50 | ## selected mdoel to fit |
---|
| 51 | self.model_toFit=[] |
---|
[b28717b] | 52 | ## number of constraint |
---|
| 53 | self.nb_constraint= 0 |
---|
| 54 | ## draw page |
---|
[2140e68] | 55 | self.define_page_structure() |
---|
[b28717b] | 56 | self.draw_page() |
---|
[2140e68] | 57 | self.set_layout() |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | def define_page_structure(self): |
---|
| 62 | """ |
---|
| 63 | Create empty sizer for a panel |
---|
| 64 | """ |
---|
[d89f09b] | 65 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[2140e68] | 66 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
| 67 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
[8bd4dc0] | 68 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
| 69 | self.sizer1.SetMinSize((375,-1)) |
---|
| 70 | self.sizer2.SetMinSize((375,-1)) |
---|
| 71 | self.sizer3.SetMinSize((375,-1)) |
---|
[d89f09b] | 72 | self.vbox.Add(self.sizer1) |
---|
| 73 | self.vbox.Add(self.sizer2) |
---|
[8bd4dc0] | 74 | self.vbox.Add(self.sizer3) |
---|
[51d47b5] | 75 | |
---|
[2140e68] | 76 | def set_scroll(self): |
---|
| 77 | self.SetScrollbars(20,20,200,100) |
---|
| 78 | self.Layout() |
---|
| 79 | |
---|
| 80 | def set_layout(self): |
---|
| 81 | """ |
---|
| 82 | layout |
---|
| 83 | """ |
---|
[d89f09b] | 84 | self.vbox.Layout() |
---|
| 85 | self.vbox.Fit(self) |
---|
| 86 | self.SetSizer(self.vbox) |
---|
[2140e68] | 87 | |
---|
| 88 | self.set_scroll() |
---|
[d89f09b] | 89 | self.Centre() |
---|
| 90 | |
---|
[8bd4dc0] | 91 | def onRemove(self, event): |
---|
| 92 | """ |
---|
| 93 | Remove constraint fields |
---|
| 94 | """ |
---|
[a911b48] | 95 | if len(self.constraints_list)==1: |
---|
| 96 | self.hide_constraint.SetValue(True) |
---|
| 97 | self._hide_constraint() |
---|
| 98 | return |
---|
| 99 | if len(self.constraints_list)==0: |
---|
[8bd4dc0] | 100 | return |
---|
| 101 | for item in self.constraints_list: |
---|
| 102 | length= len(item) |
---|
| 103 | if event.GetId()==item[length-2].GetId(): |
---|
| 104 | sizer= item[length-1] |
---|
[bb7d8a4] | 105 | sizer.Clear(True) |
---|
[8bd4dc0] | 106 | self.sizer_constraints.Remove(sizer) |
---|
[998b6b8] | 107 | |
---|
[8bd4dc0] | 108 | self.sizer2.Layout() |
---|
| 109 | self.SetScrollbars(20,20,200,100) |
---|
| 110 | self.constraints_list.remove(item) |
---|
| 111 | self.nb_constraint -= 1 |
---|
| 112 | break |
---|
| 113 | |
---|
| 114 | |
---|
[d89f09b] | 115 | def onFit(self,event): |
---|
[1b07935d] | 116 | """ signal for fitting""" |
---|
[2140e68] | 117 | ## making sure all parameters content a constraint |
---|
| 118 | ## validity of the constraint expression is own by fit engine |
---|
[ac11e40] | 119 | if self.show_constraint.GetValue(): |
---|
| 120 | self._set_constraint() |
---|
[2140e68] | 121 | ## get the fit range of very fit problem |
---|
| 122 | for page, value in self.page_finder.iteritems(): |
---|
| 123 | qmin, qmax= page.get_range() |
---|
| 124 | value.set_range(qmin, qmax) |
---|
| 125 | ## model was actually selected from this page to be fit |
---|
[3215d32] | 126 | if len(self.model_toFit) >= 1 : |
---|
[6f023e8] | 127 | self.manager._reset_schedule_problem( value=0) |
---|
| 128 | for item in self.model_list: |
---|
| 129 | if item[0].GetValue(): |
---|
| 130 | self.manager.schedule_for_fit( value=1,fitproblem =item[1]) |
---|
[ca7a626] | 131 | self.manager.onFit() |
---|
[1b07935d] | 132 | else: |
---|
[2140e68] | 133 | msg= "Select at least one model to fit " |
---|
| 134 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
[f343069] | 135 | |
---|
[00561739] | 136 | |
---|
| 137 | |
---|
[d89f09b] | 138 | def set_manager(self, manager): |
---|
| 139 | """ |
---|
| 140 | set panel manager |
---|
| 141 | @param manager: instance of plugin fitting |
---|
| 142 | """ |
---|
| 143 | self.manager = manager |
---|
[b28717b] | 144 | |
---|
[925a30e] | 145 | |
---|
[2140e68] | 146 | def check_all_model_name(self,event): |
---|
[d89f09b] | 147 | """ |
---|
| 148 | check all models names |
---|
| 149 | """ |
---|
| 150 | self.model_toFit=[] |
---|
| 151 | if self.cb1.GetValue()==True: |
---|
| 152 | for item in self.model_list: |
---|
| 153 | item[0].SetValue(True) |
---|
| 154 | self.model_toFit.append(item) |
---|
[2140e68] | 155 | |
---|
| 156 | ## constraint info |
---|
| 157 | self._store_model() |
---|
| 158 | ## display constraint fields |
---|
| 159 | if self.show_constraint.GetValue(): |
---|
| 160 | self._show_constraint() |
---|
| 161 | return |
---|
[d89f09b] | 162 | else: |
---|
| 163 | for item in self.model_list: |
---|
| 164 | item[0].SetValue(False) |
---|
[948add7] | 165 | |
---|
[d89f09b] | 166 | self.model_toFit=[] |
---|
[2140e68] | 167 | ##constraint info |
---|
| 168 | self._hide_constraint() |
---|
[925a30e] | 169 | |
---|
[2140e68] | 170 | |
---|
| 171 | def check_model_name(self,event): |
---|
[d89f09b] | 172 | """ |
---|
[2140e68] | 173 | Save information related to checkbox and their states |
---|
[d89f09b] | 174 | """ |
---|
| 175 | self.model_toFit=[] |
---|
| 176 | for item in self.model_list: |
---|
| 177 | if item[0].GetValue()==True: |
---|
| 178 | self.model_toFit.append(item) |
---|
| 179 | else: |
---|
| 180 | if item in self.model_toFit: |
---|
| 181 | self.model_toFit.remove(item) |
---|
| 182 | self.cb1.SetValue(False) |
---|
[b28717b] | 183 | |
---|
[2140e68] | 184 | ## display constraint fields |
---|
[b28717b] | 185 | if len(self.model_toFit)==2: |
---|
[2140e68] | 186 | self._store_model() |
---|
[b28717b] | 187 | if self.show_constraint.GetValue() and len(self.constraints_list)==0: |
---|
[2140e68] | 188 | self._show_constraint() |
---|
[b28717b] | 189 | elif len(self.model_toFit)< 2: |
---|
| 190 | ##constraint info |
---|
| 191 | self._hide_constraint() |
---|
[2140e68] | 192 | |
---|
| 193 | ## set the value of the main check button |
---|
[d89f09b] | 194 | if len(self.model_list)==len(self.model_toFit): |
---|
| 195 | self.cb1.SetValue(True) |
---|
[b28717b] | 196 | return |
---|
[d89f09b] | 197 | else: |
---|
| 198 | self.cb1.SetValue(False) |
---|
[b28717b] | 199 | |
---|
[948add7] | 200 | |
---|
[2140e68] | 201 | |
---|
[b28717b] | 202 | def draw_page(self): |
---|
[2140e68] | 203 | """ |
---|
| 204 | Draw a sizer containing couples of data and model |
---|
[b28717b] | 205 | """ |
---|
| 206 | |
---|
[2140e68] | 207 | self.model_list=[] |
---|
| 208 | self.model_toFit=[] |
---|
[8bd4dc0] | 209 | self.constraints_list=[] |
---|
[1d2782d] | 210 | self.constraint_dict={} |
---|
| 211 | self.nb_constraint= 0 |
---|
| 212 | |
---|
[2140e68] | 213 | if len(self.model_list)>0: |
---|
| 214 | for item in self.model_list: |
---|
| 215 | item[0].SetValue(False) |
---|
| 216 | self.manager.schedule_for_fit( value=0,fitproblem =item[1]) |
---|
| 217 | |
---|
| 218 | self.sizer1.Clear(True) |
---|
| 219 | |
---|
| 220 | |
---|
[8bd4dc0] | 221 | box_description= wx.StaticBox(self, -1,"Fit Combinations") |
---|
[2140e68] | 222 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 223 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 224 | sizer_couples = wx.GridBagSizer(5,5) |
---|
| 225 | |
---|
| 226 | #------------------------------------------------------ |
---|
| 227 | if len(self.page_finder)==0: |
---|
[8bd4dc0] | 228 | sizer_title.Add(wx.StaticText(self,-1," No fit combination available !")) |
---|
[2140e68] | 229 | else: |
---|
| 230 | ## store model |
---|
| 231 | self._store_model() |
---|
| 232 | |
---|
[8bd4dc0] | 233 | self.cb1 = wx.CheckBox(self, -1,'Select all') |
---|
[2140e68] | 234 | self.cb1.SetValue(False) |
---|
| 235 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) |
---|
| 236 | |
---|
[8bd4dc0] | 237 | sizer_title.Add((10,10),0, |
---|
| 238 | wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 239 | sizer_title.Add(self.cb1,0, |
---|
| 240 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 241 | |
---|
| 242 | ## draw list of model and data name |
---|
[2140e68] | 243 | self._fill_sizer_model_list(sizer_couples) |
---|
| 244 | ## draw the sizer containing constraint info |
---|
| 245 | self._fill_sizer_constraint() |
---|
[8bd4dc0] | 246 | ## draw fit button |
---|
| 247 | self._fill_sizer_fit() |
---|
| 248 | |
---|
[2140e68] | 249 | #-------------------------------------------------------- |
---|
[8bd4dc0] | 250 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
| 251 | boxsizer1.Add(sizer_couples, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
[2140e68] | 252 | |
---|
[8bd4dc0] | 253 | self.sizer1.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 10) |
---|
[2140e68] | 254 | self.sizer1.Layout() |
---|
| 255 | self.SetScrollbars(20,20,200,100) |
---|
| 256 | self.AdjustScrollbars() |
---|
| 257 | |
---|
| 258 | def _store_model(self): |
---|
[d89f09b] | 259 | """ |
---|
[2140e68] | 260 | Store selected model |
---|
[d89f09b] | 261 | """ |
---|
[2140e68] | 262 | if len(self.model_toFit) < 2: |
---|
| 263 | return |
---|
[1d2782d] | 264 | for item in self.model_toFit: |
---|
| 265 | model = item[3] |
---|
| 266 | page= item[2] |
---|
| 267 | self.constraint_dict[page] = model |
---|
[2140e68] | 268 | |
---|
| 269 | |
---|
| 270 | def _display_constraint(self, event): |
---|
| 271 | """ |
---|
| 272 | Show fields to add constraint |
---|
| 273 | """ |
---|
| 274 | if len(self.model_toFit)< 2: |
---|
| 275 | msg= "Select at least 2 models to add constraint " |
---|
| 276 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
| 277 | ## hide button |
---|
| 278 | self._hide_constraint() |
---|
| 279 | return |
---|
| 280 | if self.show_constraint.GetValue(): |
---|
| 281 | self._show_constraint() |
---|
| 282 | return |
---|
| 283 | else: |
---|
| 284 | self._hide_constraint() |
---|
| 285 | return |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | def _show_constraint(self): |
---|
| 289 | """ |
---|
| 290 | Show constraint fields |
---|
| 291 | """ |
---|
[77e23a2] | 292 | self.btAdd.Show(True) |
---|
[2140e68] | 293 | if len(self.constraints_list)!= 0: |
---|
| 294 | nb_fit_param = 0 |
---|
[1d2782d] | 295 | for model in self.constraint_dict.values(): |
---|
[8bd4dc0] | 296 | nb_fit_param += len(get_fittableParam(model)) |
---|
[2140e68] | 297 | ##Don't add anymore |
---|
| 298 | if len(self.constraints_list) == nb_fit_param: |
---|
[ac11e40] | 299 | msg= "Cannot add another constraint .Maximum of number " |
---|
| 300 | msg += "Parameters name reached %s"%str(nb_fit_param) |
---|
| 301 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
[b28717b] | 302 | self.sizer_constraints.Layout() |
---|
[ac11e40] | 303 | self.sizer2.Layout() |
---|
| 304 | self.SetScrollbars(20,20,200,100) |
---|
| 305 | return |
---|
| 306 | |
---|
| 307 | if len(self.model_toFit) < 2 : |
---|
[2140e68] | 308 | msg= "Select at least 2 model to add constraint " |
---|
| 309 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
[b28717b] | 310 | self.sizer_constraints.Layout() |
---|
[2140e68] | 311 | self.sizer2.Layout() |
---|
| 312 | self.SetScrollbars(20,20,200,100) |
---|
| 313 | return |
---|
| 314 | |
---|
| 315 | sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) |
---|
[8bd4dc0] | 316 | model_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
[2140e68] | 317 | model_cbox.Clear() |
---|
[8bd4dc0] | 318 | param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
[b28717b] | 319 | param_cbox.Hide() |
---|
[2140e68] | 320 | wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param) |
---|
| 321 | ctl2 = wx.TextCtrl(self, -1) |
---|
| 322 | egal_txt= wx.StaticText(self,-1," = ") |
---|
[8bd4dc0] | 323 | btRemove = wx.Button(self,wx.NewId(),'Remove') |
---|
| 324 | btRemove.Bind(wx.EVT_BUTTON, self.onRemove,id= btRemove.GetId()) |
---|
| 325 | btRemove.SetToolTipString("Remove constraint.") |
---|
[2140e68] | 326 | |
---|
| 327 | |
---|
[1d2782d] | 328 | for page,model in self.constraint_dict.iteritems(): |
---|
[2140e68] | 329 | ## check if all parameters have been selected for constraint |
---|
| 330 | ## then do not allow add constraint on parameters |
---|
[ac11e40] | 331 | model_cbox.Append( str(model.name), model) |
---|
[2140e68] | 332 | |
---|
| 333 | |
---|
| 334 | wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model) |
---|
| 335 | |
---|
[8bd4dc0] | 336 | |
---|
[b28717b] | 337 | sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
| 338 | sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
| 339 | sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
| 340 | sizer_constraint.Add(ctl2, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
[8bd4dc0] | 341 | sizer_constraint.Add(btRemove, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
[b28717b] | 342 | |
---|
| 343 | self.sizer_constraints.Insert(before=self.nb_constraint, |
---|
| 344 | item=sizer_constraint, flag= wx.TOP|wx.BOTTOM|wx.EXPAND, |
---|
[8bd4dc0] | 345 | border=5) |
---|
| 346 | ##[combobox1, combobox2,=,textcrtl, remove button ] |
---|
| 347 | self.constraints_list.append([model_cbox, param_cbox, egal_txt, ctl2,btRemove,sizer_constraint]) |
---|
| 348 | |
---|
[b28717b] | 349 | |
---|
| 350 | self.nb_constraint += 1 |
---|
| 351 | self.sizer_constraints.Layout() |
---|
[2140e68] | 352 | self.sizer2.Layout() |
---|
| 353 | self.SetScrollbars(20,20,200,100) |
---|
| 354 | |
---|
| 355 | def _hide_constraint(self): |
---|
| 356 | """ |
---|
| 357 | hide buttons related constraint |
---|
[ac11e40] | 358 | """ |
---|
[1f57dfd] | 359 | for page in self.page_finder.iterkeys(): |
---|
[1d2782d] | 360 | self.page_finder[page].clear_model_param() |
---|
[b28717b] | 361 | |
---|
| 362 | self.nb_constraint =0 |
---|
[ac11e40] | 363 | self.constraint_dict={} |
---|
[69bee6d] | 364 | if hasattr(self,"btAdd"): |
---|
| 365 | self.btAdd.Hide() |
---|
[ac11e40] | 366 | self._store_model() |
---|
[b28717b] | 367 | |
---|
[2140e68] | 368 | self.constraints_list=[] |
---|
[b28717b] | 369 | self.sizer_constraints.Clear(True) |
---|
| 370 | self.sizer_constraints.Layout() |
---|
[2140e68] | 371 | self.sizer2.Layout() |
---|
| 372 | self.SetScrollbars(20,20,200,100) |
---|
| 373 | self.AdjustScrollbars() |
---|
| 374 | |
---|
[ac11e40] | 375 | |
---|
[2140e68] | 376 | |
---|
| 377 | def _on_select_model(self, event): |
---|
| 378 | """ |
---|
| 379 | fill combox box with list of parameters |
---|
| 380 | """ |
---|
| 381 | model = event.GetClientData() |
---|
[8bd4dc0] | 382 | param_list= get_fittableParam(model) |
---|
[2140e68] | 383 | length = len(self.constraints_list) |
---|
| 384 | if length < 1: |
---|
| 385 | return |
---|
| 386 | |
---|
| 387 | param_cbox = self.constraints_list[length-1][1] |
---|
| 388 | param_cbox.Clear() |
---|
| 389 | ## insert only fittable paramaters |
---|
| 390 | for param in param_list: |
---|
[ac11e40] | 391 | param_cbox.Append( str(param), model) |
---|
| 392 | |
---|
[2140e68] | 393 | param_cbox.Show(True) |
---|
| 394 | |
---|
| 395 | |
---|
| 396 | self.sizer2.Layout() |
---|
| 397 | self.SetScrollbars(20,20,200,100) |
---|
| 398 | |
---|
| 399 | |
---|
| 400 | def _on_select_param(self, event): |
---|
| 401 | """ |
---|
| 402 | Store the appropriate constraint in the page_finder |
---|
| 403 | """ |
---|
| 404 | model = event.GetClientData() |
---|
| 405 | param = event.GetString() |
---|
[ac11e40] | 406 | |
---|
[2140e68] | 407 | length = len(self.constraints_list) |
---|
| 408 | if length < 1: |
---|
| 409 | return |
---|
| 410 | egal_txt = self.constraints_list[length-1][2] |
---|
| 411 | egal_txt.Show(True) |
---|
| 412 | |
---|
| 413 | ctl2 = self.constraints_list[length-1][3] |
---|
| 414 | ctl2.Show(True) |
---|
| 415 | |
---|
[b28717b] | 416 | |
---|
[2140e68] | 417 | self.sizer2.Layout() |
---|
| 418 | self.SetScrollbars(20,20,200,100) |
---|
| 419 | |
---|
| 420 | |
---|
| 421 | def _onAdd_constraint(self, event): |
---|
| 422 | """ |
---|
| 423 | Add another line for constraint |
---|
| 424 | """ |
---|
| 425 | |
---|
[8bd4dc0] | 426 | if not self.show_constraint.GetValue(): |
---|
| 427 | msg= " Select Yes to add Constraint " |
---|
| 428 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
| 429 | return |
---|
| 430 | |
---|
[2140e68] | 431 | ## check that a constraint is added before allow to add another cosntraint |
---|
| 432 | |
---|
| 433 | for item in self.constraints_list: |
---|
| 434 | model_cbox = item[0] |
---|
| 435 | if model_cbox.GetString(0)=="": |
---|
| 436 | msg= " Select a model Name! " |
---|
| 437 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
| 438 | return |
---|
| 439 | param_cbox = item[1] |
---|
| 440 | if param_cbox.GetString(0)=="": |
---|
| 441 | msg= " Select a parameter Name! " |
---|
| 442 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
| 443 | return |
---|
| 444 | ctl2 = item[3] |
---|
| 445 | if ctl2.GetValue().lstrip().rstrip()=="": |
---|
[b28717b] | 446 | model= param_cbox.GetClientData(param_cbox.GetCurrentSelection()) |
---|
| 447 | msg= " Enter a constraint for %s.%s! "%(model.name,param_cbox.GetString(0)) |
---|
| 448 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
| 449 | return |
---|
[2140e68] | 450 | |
---|
| 451 | ## some model or parameters can be constrained |
---|
| 452 | self._show_constraint() |
---|
| 453 | |
---|
[8bd4dc0] | 454 | def _fill_sizer_fit(self): |
---|
| 455 | """ |
---|
| 456 | Draw fit fit button |
---|
| 457 | """ |
---|
| 458 | self.sizer3.Clear(True) |
---|
| 459 | box_description= wx.StaticBox(self, -1,"Fit ") |
---|
| 460 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 461 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 462 | |
---|
| 463 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
| 464 | self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id= self.btFit.GetId()) |
---|
| 465 | self.btFit.SetToolTipString("Perform fit.") |
---|
[2140e68] | 466 | |
---|
[8bd4dc0] | 467 | text= "Hint: Park fitting engine will be selected \n" |
---|
| 468 | text+= "automatically for more than 2 combinations checked" |
---|
| 469 | text_hint = wx.StaticText(self,-1,text) |
---|
| 470 | |
---|
| 471 | sizer_button.Add(text_hint, wx.RIGHT|wx.EXPAND, 10) |
---|
| 472 | sizer_button.Add(self.btFit, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 473 | |
---|
| 474 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
| 475 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 476 | self.sizer3.Layout() |
---|
| 477 | self.SetScrollbars(20,20,200,100) |
---|
[2140e68] | 478 | |
---|
| 479 | def _fill_sizer_constraint(self): |
---|
| 480 | """ |
---|
| 481 | Fill sizer containing constraint info |
---|
| 482 | """ |
---|
| 483 | msg= "Select at least 2 model to add constraint " |
---|
| 484 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
| 485 | |
---|
| 486 | self.sizer2.Clear(True) |
---|
| 487 | |
---|
| 488 | box_description= wx.StaticBox(self, -1,"Fit Constraints") |
---|
| 489 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 490 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
[b28717b] | 491 | self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) |
---|
[2140e68] | 492 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 493 | |
---|
| 494 | self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) |
---|
| 495 | self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
| 496 | |
---|
| 497 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
| 498 | id= self.hide_constraint.GetId() ) |
---|
| 499 | |
---|
| 500 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
| 501 | id= self.show_constraint.GetId() ) |
---|
| 502 | |
---|
| 503 | sizer_title.Add( wx.StaticText(self,-1," Model") ) |
---|
| 504 | sizer_title.Add(( 10,10) ) |
---|
| 505 | sizer_title.Add( wx.StaticText(self,-1," Parameter") ) |
---|
| 506 | sizer_title.Add(( 10,10) ) |
---|
| 507 | sizer_title.Add( wx.StaticText(self,-1," Add Constraint?") ) |
---|
| 508 | sizer_title.Add(( 10,10) ) |
---|
| 509 | sizer_title.Add( self.show_constraint ) |
---|
| 510 | sizer_title.Add( self.hide_constraint ) |
---|
| 511 | sizer_title.Add(( 10,10) ) |
---|
| 512 | |
---|
| 513 | self.btAdd =wx.Button(self,wx.NewId(),'Add') |
---|
| 514 | self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint,id= self.btAdd.GetId()) |
---|
| 515 | self.btAdd.SetToolTipString("Add another constraint?") |
---|
[77e23a2] | 516 | self.btAdd.Hide() |
---|
[8bd4dc0] | 517 | |
---|
[2140e68] | 518 | |
---|
[d5fd5ce] | 519 | text_hint = wx.StaticText(self,-1,"Example: [M0][paramter] = M1.parameter") |
---|
[2140e68] | 520 | sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 521 | sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 522 | |
---|
[8bd4dc0] | 523 | |
---|
| 524 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
| 525 | boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
| 526 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
[2140e68] | 527 | |
---|
| 528 | self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 529 | self.sizer2.Layout() |
---|
| 530 | self.SetScrollbars(20,20,200,100) |
---|
| 531 | |
---|
| 532 | |
---|
| 533 | |
---|
| 534 | def _set_constraint(self): |
---|
[d89f09b] | 535 | """ |
---|
| 536 | get values from the constrainst textcrtl ,parses them into model name |
---|
| 537 | parameter name and parameters values. |
---|
[925a30e] | 538 | store them in a list self.params .when when params is not empty set_model |
---|
| 539 | uses it to reset the appropriate model and its appropriates parameters |
---|
[d89f09b] | 540 | """ |
---|
[2140e68] | 541 | for item in self.constraints_list: |
---|
[ac11e40] | 542 | |
---|
| 543 | model = item[0].GetClientData(item[0].GetCurrentSelection()) |
---|
| 544 | param = item[1].GetString(item[1].GetCurrentSelection()) |
---|
[2140e68] | 545 | constraint = item[3].GetValue().lstrip().rstrip() |
---|
[bb7d8a4] | 546 | if param.lstrip().rstrip()=="": |
---|
| 547 | param= None |
---|
| 548 | msg= " Constraint will be ignored!. missing parameters in combobox" |
---|
| 549 | msg+= " to set constraint! " |
---|
| 550 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
[1f57dfd] | 551 | for page , value in self.constraint_dict.iteritems(): |
---|
| 552 | if model == value: |
---|
| 553 | if constraint == "": |
---|
| 554 | msg= " Constraint will be ignored!. missing value in textcrtl" |
---|
| 555 | msg+= " to set constraint! " |
---|
| 556 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
| 557 | constraint = None |
---|
| 558 | self.page_finder[page].set_model_param(param,constraint) |
---|
| 559 | break |
---|
[d89f09b] | 560 | |
---|
[2140e68] | 561 | |
---|
| 562 | |
---|
| 563 | def _fill_sizer_model_list(self,sizer): |
---|
[d89f09b] | 564 | """ |
---|
[2140e68] | 565 | Receive a dictionary containing information to display model name |
---|
| 566 | @param page_finder: the dictionary containing models information |
---|
[d89f09b] | 567 | """ |
---|
[2140e68] | 568 | ix = 0 |
---|
| 569 | iy = 0 |
---|
| 570 | list=[] |
---|
| 571 | sizer.Clear(True) |
---|
| 572 | |
---|
| 573 | new_name = wx.StaticText(self, -1, 'New Model Name', style=wx.ALIGN_CENTER) |
---|
| 574 | new_name.SetBackgroundColour('orange') |
---|
| 575 | sizer.Add(new_name,(iy, ix),(1,1), |
---|
| 576 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 577 | |
---|
| 578 | ix +=2 |
---|
| 579 | model_type = wx.StaticText(self, -1, ' Model Type') |
---|
| 580 | model_type.SetBackgroundColour('grey') |
---|
| 581 | sizer.Add(model_type,(iy, ix),(1,1), |
---|
| 582 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 583 | ix +=1 |
---|
| 584 | data_used = wx.StaticText(self, -1, ' Used Data') |
---|
| 585 | data_used.SetBackgroundColour('grey') |
---|
| 586 | sizer.Add(data_used,(iy, ix),(1,1), |
---|
| 587 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 588 | |
---|
| 589 | for page, value in self.page_finder.iteritems(): |
---|
| 590 | try: |
---|
| 591 | ix = 0 |
---|
| 592 | iy += 1 |
---|
| 593 | model = value.get_model() |
---|
| 594 | cb = wx.CheckBox(self, -1, str(model.name)) |
---|
| 595 | cb.SetValue(False) |
---|
| 596 | sizer.Add( cb,( iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 597 | wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) |
---|
| 598 | |
---|
| 599 | ix +=2 |
---|
| 600 | type = model.__class__.__name__ |
---|
| 601 | model_type = wx.StaticText(self, -1, str(type)) |
---|
| 602 | sizer.Add(model_type,( iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 603 | |
---|
| 604 | ix +=1 |
---|
| 605 | data = value.get_fit_data() |
---|
| 606 | data_used= wx.StaticText(self, -1, str(data.name)) |
---|
| 607 | sizer.Add(data_used,( iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 608 | |
---|
| 609 | self.model_list.append([cb,value,page,model]) |
---|
| 610 | |
---|
| 611 | except: |
---|
| 612 | pass |
---|
| 613 | iy +=1 |
---|
| 614 | sizer.Add((20,20),( iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 615 | sizer.Layout() |
---|
| 616 | |
---|
| 617 | |
---|
| 618 | |
---|
| 619 | |
---|
| 620 | class HelpWindow(wx.Frame): |
---|
| 621 | def __init__(self, parent, id, title): |
---|
| 622 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
| 623 | |
---|
| 624 | page_finder ={} |
---|
| 625 | ## create random data |
---|
| 626 | from danse.common.plottools.plottables import Data1D |
---|
| 627 | data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) |
---|
| 628 | data.name="mydata.txt" |
---|
| 629 | ## create model |
---|
| 630 | from sans.models.CylinderModel import CylinderModel |
---|
| 631 | model = CylinderModel() |
---|
| 632 | model.name="M0" |
---|
| 633 | |
---|
| 634 | |
---|
| 635 | from fitproblem import FitProblem |
---|
| 636 | page_finder["page"]= FitProblem() |
---|
| 637 | ## fill the page_finder |
---|
| 638 | page_finder["page"].add_fit_data(data) |
---|
| 639 | page_finder["page"].set_model(model) |
---|
| 640 | self.page = SimultaneousFitPage(self, page_finder=page_finder) |
---|
| 641 | |
---|
| 642 | |
---|
| 643 | |
---|
| 644 | self.Centre() |
---|
| 645 | self.Show(True) |
---|
| 646 | |
---|
| 647 | |
---|
[d89f09b] | 648 | |
---|
[2140e68] | 649 | if __name__=="__main__": |
---|
| 650 | app = wx.App() |
---|
| 651 | HelpWindow(None, -1, 'HelpWindow') |
---|
| 652 | app.MainLoop() |
---|
[d89f09b] | 653 | |
---|