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