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