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