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