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