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