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