[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 |
---|
[1976004] | 7 | from sans.guiframe.events import PanelOnFocusEvent |
---|
[c99a6c5] | 8 | #Control panel width |
---|
[6e9976b] | 9 | if sys.platform.count("darwin")==0: |
---|
[c99a6c5] | 10 | PANEL_WID = 420 |
---|
[f1aa385] | 11 | FONT_VARIANT = 0 |
---|
[c99a6c5] | 12 | else: |
---|
| 13 | PANEL_WID = 490 |
---|
[f1aa385] | 14 | FONT_VARIANT = 1 |
---|
[8bd4dc0] | 15 | |
---|
| 16 | def get_fittableParam( model): |
---|
[2140e68] | 17 | """ |
---|
[5062bbf] | 18 | return list of fittable parameters name of a model |
---|
| 19 | |
---|
| 20 | :param model: the model used |
---|
| 21 | |
---|
[2140e68] | 22 | """ |
---|
[8bd4dc0] | 23 | fittable_param=[] |
---|
| 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 | """ |
---|
[00daba9] | 52 | self.SetupScrolling() |
---|
[f1aa385] | 53 | ##Font size |
---|
| 54 | self.SetWindowVariant(variant = FONT_VARIANT) |
---|
[922497f] | 55 | self.uid = wx.NewId() |
---|
[d89f09b] | 56 | self.parent = parent |
---|
[2140e68] | 57 | ## store page_finder |
---|
[b28717b] | 58 | self.page_finder = page_finder |
---|
[2140e68] | 59 | ## list contaning info to set constraint |
---|
[6bbeacd4] | 60 | ## look like self.constraint_dict[page_id]= page |
---|
[2140e68] | 61 | self.constraint_dict={} |
---|
[1b14795] | 62 | ## item list |
---|
| 63 | # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] |
---|
[2140e68] | 64 | self.constraints_list=[] |
---|
| 65 | ## list of current model |
---|
| 66 | self.model_list=[] |
---|
| 67 | ## selected mdoel to fit |
---|
| 68 | self.model_toFit=[] |
---|
[b28717b] | 69 | ## number of constraint |
---|
| 70 | self.nb_constraint= 0 |
---|
[53fc5ad9] | 71 | self.model_cbox_left = None |
---|
| 72 | self.model_cbox_right = None |
---|
[dc613d6] | 73 | self.uid = wx.NewId() |
---|
[b28717b] | 74 | ## draw page |
---|
[2140e68] | 75 | self.define_page_structure() |
---|
[b28717b] | 76 | self.draw_page() |
---|
[2140e68] | 77 | self.set_layout() |
---|
| 78 | |
---|
| 79 | def define_page_structure(self): |
---|
| 80 | """ |
---|
[5062bbf] | 81 | Create empty sizer for a panel |
---|
[2140e68] | 82 | """ |
---|
[d89f09b] | 83 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[2140e68] | 84 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
| 85 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
[8bd4dc0] | 86 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
[c99a6c5] | 87 | |
---|
| 88 | self.sizer1.SetMinSize((PANEL_WID,-1)) |
---|
| 89 | self.sizer2.SetMinSize((PANEL_WID,-1)) |
---|
| 90 | self.sizer3.SetMinSize((PANEL_WID,-1)) |
---|
[d89f09b] | 91 | self.vbox.Add(self.sizer1) |
---|
| 92 | self.vbox.Add(self.sizer2) |
---|
[8bd4dc0] | 93 | self.vbox.Add(self.sizer3) |
---|
[51d47b5] | 94 | |
---|
[2140e68] | 95 | def set_scroll(self): |
---|
[5062bbf] | 96 | """ |
---|
| 97 | """ |
---|
[e1a97f8] | 98 | #self.SetScrollbars(20,20,25,65) |
---|
[2140e68] | 99 | self.Layout() |
---|
| 100 | |
---|
| 101 | def set_layout(self): |
---|
| 102 | """ |
---|
[5062bbf] | 103 | layout |
---|
[2140e68] | 104 | """ |
---|
[d89f09b] | 105 | self.vbox.Layout() |
---|
| 106 | self.vbox.Fit(self) |
---|
| 107 | self.SetSizer(self.vbox) |
---|
[2140e68] | 108 | self.set_scroll() |
---|
[d89f09b] | 109 | self.Centre() |
---|
| 110 | |
---|
[8bd4dc0] | 111 | def onRemove(self, event): |
---|
| 112 | """ |
---|
[5062bbf] | 113 | Remove constraint fields |
---|
[8bd4dc0] | 114 | """ |
---|
[a911b48] | 115 | if len(self.constraints_list)==1: |
---|
| 116 | self.hide_constraint.SetValue(True) |
---|
| 117 | self._hide_constraint() |
---|
| 118 | return |
---|
| 119 | if len(self.constraints_list)==0: |
---|
[8bd4dc0] | 120 | return |
---|
| 121 | for item in self.constraints_list: |
---|
| 122 | length= len(item) |
---|
| 123 | if event.GetId()==item[length-2].GetId(): |
---|
| 124 | sizer= item[length-1] |
---|
[bb7d8a4] | 125 | sizer.Clear(True) |
---|
[8bd4dc0] | 126 | self.sizer_constraints.Remove(sizer) |
---|
[1b14795] | 127 | #self.SetScrollbars(20,20,25,65) |
---|
[8bd4dc0] | 128 | self.constraints_list.remove(item) |
---|
| 129 | self.nb_constraint -= 1 |
---|
[1b14795] | 130 | self.sizer2.Layout() |
---|
| 131 | self.Layout() |
---|
[8bd4dc0] | 132 | break |
---|
[1b14795] | 133 | self._onAdd_constraint(None) |
---|
| 134 | |
---|
[922497f] | 135 | def onFit(self, event): |
---|
[5062bbf] | 136 | """ |
---|
| 137 | signal for fitting |
---|
| 138 | |
---|
| 139 | """ |
---|
[2140e68] | 140 | ## making sure all parameters content a constraint |
---|
| 141 | ## validity of the constraint expression is own by fit engine |
---|
[1153d0e] | 142 | if self.parent._manager._fit_engine != "park" and\ |
---|
| 143 | self._manager.sim_page.uid == self.uid: |
---|
| 144 | msg = "The FitEnging will be set to 'Park' fit engine\n" |
---|
| 145 | msg += " for the simultaneous fit..." |
---|
| 146 | #wx.MessageBox(msg, 'Info') |
---|
| 147 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
| 148 | "Fitting: %s"%msg, info="info")) |
---|
[ac11e40] | 149 | if self.show_constraint.GetValue(): |
---|
[00daba9] | 150 | if not self._set_constraint(): |
---|
| 151 | return |
---|
[2140e68] | 152 | ## model was actually selected from this page to be fit |
---|
[3215d32] | 153 | if len(self.model_toFit) >= 1 : |
---|
[66ff250] | 154 | self.manager._reset_schedule_problem(value=0) |
---|
[6f023e8] | 155 | for item in self.model_list: |
---|
| 156 | if item[0].GetValue(): |
---|
[c647377] | 157 | self.manager.schedule_for_fit(value=1, uid=item[2]) |
---|
[1b14795] | 158 | try: |
---|
[31469d50] | 159 | if not self.manager.onFit(uid=self.uid): |
---|
| 160 | return |
---|
[1b14795] | 161 | except: |
---|
| 162 | msg= "Select at least one parameter to fit in the FitPages." |
---|
| 163 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[1b07935d] | 164 | else: |
---|
[31469d50] | 165 | msg= "Select at least one model check box to fit " |
---|
[1b14795] | 166 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[f343069] | 167 | |
---|
[d89f09b] | 168 | def set_manager(self, manager): |
---|
| 169 | """ |
---|
[5062bbf] | 170 | set panel manager |
---|
| 171 | |
---|
| 172 | :param manager: instance of plugin fitting |
---|
| 173 | |
---|
[d89f09b] | 174 | """ |
---|
| 175 | self.manager = manager |
---|
[b28717b] | 176 | |
---|
[2140e68] | 177 | def check_all_model_name(self,event): |
---|
[d89f09b] | 178 | """ |
---|
[5062bbf] | 179 | check all models names |
---|
[d89f09b] | 180 | """ |
---|
[6bbeacd4] | 181 | self.model_toFit = [] |
---|
| 182 | if self.cb1.GetValue()== True: |
---|
[d89f09b] | 183 | for item in self.model_list: |
---|
[6c08ba5] | 184 | if item[0].IsEnabled(): |
---|
| 185 | item[0].SetValue(True) |
---|
| 186 | self.model_toFit.append(item) |
---|
[2140e68] | 187 | |
---|
| 188 | ## constraint info |
---|
| 189 | self._store_model() |
---|
| 190 | ## display constraint fields |
---|
[53fc5ad9] | 191 | if self.show_constraint.GetValue() and\ |
---|
| 192 | len(self.constraints_list)==0: |
---|
[77a43fb] | 193 | self._show_all_constraint() |
---|
[2140e68] | 194 | self._show_constraint() |
---|
[d89f09b] | 195 | else: |
---|
| 196 | for item in self.model_list: |
---|
| 197 | item[0].SetValue(False) |
---|
[948add7] | 198 | |
---|
[d89f09b] | 199 | self.model_toFit=[] |
---|
[2140e68] | 200 | ##constraint info |
---|
| 201 | self._hide_constraint() |
---|
[53fc5ad9] | 202 | |
---|
| 203 | self._update_easy_setup_cb() |
---|
[925a30e] | 204 | |
---|
[2140e68] | 205 | def check_model_name(self,event): |
---|
[d89f09b] | 206 | """ |
---|
[5062bbf] | 207 | Save information related to checkbox and their states |
---|
[d89f09b] | 208 | """ |
---|
| 209 | self.model_toFit=[] |
---|
[53fc5ad9] | 210 | cbox = event.GetEventObject() |
---|
[d89f09b] | 211 | for item in self.model_list: |
---|
| 212 | if item[0].GetValue()==True: |
---|
| 213 | self.model_toFit.append(item) |
---|
| 214 | else: |
---|
| 215 | if item in self.model_toFit: |
---|
| 216 | self.model_toFit.remove(item) |
---|
| 217 | self.cb1.SetValue(False) |
---|
[b28717b] | 218 | |
---|
[2140e68] | 219 | ## display constraint fields |
---|
[53fc5ad9] | 220 | if len(self.model_toFit)>=1: |
---|
[2140e68] | 221 | self._store_model() |
---|
[1b14795] | 222 | if self.show_constraint.GetValue() and\ |
---|
| 223 | len(self.constraints_list)==0: |
---|
[77a43fb] | 224 | self._show_all_constraint() |
---|
[2140e68] | 225 | self._show_constraint() |
---|
[53fc5ad9] | 226 | |
---|
[284f6fe] | 227 | elif len(self.model_toFit)< 1: |
---|
[b28717b] | 228 | ##constraint info |
---|
[53fc5ad9] | 229 | self._hide_constraint() |
---|
| 230 | |
---|
| 231 | self._update_easy_setup_cb() |
---|
[2140e68] | 232 | ## set the value of the main check button |
---|
[d89f09b] | 233 | if len(self.model_list)==len(self.model_toFit): |
---|
| 234 | self.cb1.SetValue(True) |
---|
[b28717b] | 235 | return |
---|
[d89f09b] | 236 | else: |
---|
| 237 | self.cb1.SetValue(False) |
---|
[53fc5ad9] | 238 | |
---|
| 239 | def _update_easy_setup_cb(self): |
---|
| 240 | """ |
---|
| 241 | Update easy setup combobox on selecting a model |
---|
| 242 | """ |
---|
| 243 | if self.model_cbox_left != None and self.model_cbox_right != None: |
---|
| 244 | self.model_cbox_left.Clear() |
---|
| 245 | self.model_cbox_right.Clear() |
---|
| 246 | #for id, model in self.constraint_dict.iteritems(): |
---|
| 247 | for item in self.model_toFit: |
---|
| 248 | model = item[3] |
---|
| 249 | ## check if all parameters have been selected for constraint |
---|
| 250 | ## then do not allow add constraint on parameters |
---|
| 251 | if str(model.name) not in self.model_cbox_left.GetItems(): |
---|
| 252 | self.model_cbox_left.Append(str(model.name), model) |
---|
| 253 | if str(model.name) not in self.model_cbox_right.GetItems(): |
---|
| 254 | self.model_cbox_right.Append(str(model.name), model) |
---|
| 255 | self.model_cbox_left.SetSelection(0) |
---|
| 256 | self.sizer2.Layout() |
---|
| 257 | self.sizer3.Layout() |
---|
[948add7] | 258 | |
---|
[b28717b] | 259 | def draw_page(self): |
---|
[2140e68] | 260 | """ |
---|
[5062bbf] | 261 | Draw a sizer containing couples of data and model |
---|
[b28717b] | 262 | """ |
---|
[2140e68] | 263 | self.model_list=[] |
---|
| 264 | self.model_toFit=[] |
---|
[8bd4dc0] | 265 | self.constraints_list=[] |
---|
[1d2782d] | 266 | self.constraint_dict={} |
---|
| 267 | self.nb_constraint= 0 |
---|
| 268 | |
---|
[2140e68] | 269 | if len(self.model_list)>0: |
---|
| 270 | for item in self.model_list: |
---|
| 271 | item[0].SetValue(False) |
---|
[c647377] | 272 | self.manager.schedule_for_fit(value=0, uid=item[2]) |
---|
[2140e68] | 273 | |
---|
[5062bbf] | 274 | self.sizer1.Clear(True) |
---|
[8bd4dc0] | 275 | box_description= wx.StaticBox(self, -1,"Fit Combinations") |
---|
[2140e68] | 276 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 277 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 278 | sizer_couples = wx.GridBagSizer(5,5) |
---|
| 279 | #------------------------------------------------------ |
---|
| 280 | if len(self.page_finder)==0: |
---|
[2296316] | 281 | msg = " No fit combinations are found! \n\n" |
---|
[1b14795] | 282 | msg += " Please load data and set up " |
---|
| 283 | msg += "at least two fit panels first..." |
---|
[2296316] | 284 | sizer_title.Add(wx.StaticText(self, -1, msg)) |
---|
[2140e68] | 285 | else: |
---|
| 286 | ## store model |
---|
| 287 | self._store_model() |
---|
| 288 | |
---|
[8bd4dc0] | 289 | self.cb1 = wx.CheckBox(self, -1,'Select all') |
---|
[2140e68] | 290 | self.cb1.SetValue(False) |
---|
| 291 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) |
---|
| 292 | |
---|
[8bd4dc0] | 293 | sizer_title.Add((10,10),0, |
---|
| 294 | wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 295 | sizer_title.Add(self.cb1,0, |
---|
| 296 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 297 | |
---|
| 298 | ## draw list of model and data name |
---|
[2140e68] | 299 | self._fill_sizer_model_list(sizer_couples) |
---|
| 300 | ## draw the sizer containing constraint info |
---|
| 301 | self._fill_sizer_constraint() |
---|
[8bd4dc0] | 302 | ## draw fit button |
---|
| 303 | self._fill_sizer_fit() |
---|
[2140e68] | 304 | #-------------------------------------------------------- |
---|
[8bd4dc0] | 305 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
[0a9871c] | 306 | boxsizer1.Add(sizer_couples, 1, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
[2140e68] | 307 | |
---|
[0a9871c] | 308 | self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) |
---|
[2140e68] | 309 | self.sizer1.Layout() |
---|
[e1a97f8] | 310 | #self.SetScrollbars(20,20,25,65) |
---|
[2140e68] | 311 | self.AdjustScrollbars() |
---|
[0a9871c] | 312 | self.Layout() |
---|
[2140e68] | 313 | |
---|
| 314 | def _store_model(self): |
---|
[d89f09b] | 315 | """ |
---|
[5062bbf] | 316 | Store selected model |
---|
[d89f09b] | 317 | """ |
---|
[284f6fe] | 318 | if len(self.model_toFit) < 1: |
---|
[2140e68] | 319 | return |
---|
[1d2782d] | 320 | for item in self.model_toFit: |
---|
| 321 | model = item[3] |
---|
[6bbeacd4] | 322 | page_id= item[2] |
---|
| 323 | self.constraint_dict[page_id] = model |
---|
[2140e68] | 324 | |
---|
| 325 | def _display_constraint(self, event): |
---|
| 326 | """ |
---|
[5062bbf] | 327 | Show fields to add constraint |
---|
[2140e68] | 328 | """ |
---|
[284f6fe] | 329 | if len(self.model_toFit)< 1: |
---|
[1aa6145] | 330 | msg= "Select at least 1 model to add constraint " |
---|
[1b14795] | 331 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[2140e68] | 332 | ## hide button |
---|
| 333 | self._hide_constraint() |
---|
| 334 | return |
---|
| 335 | if self.show_constraint.GetValue(): |
---|
[1b14795] | 336 | self._show_all_constraint() |
---|
[2140e68] | 337 | self._show_constraint() |
---|
[e1a97f8] | 338 | self.Layout() |
---|
[2140e68] | 339 | return |
---|
| 340 | else: |
---|
| 341 | self._hide_constraint() |
---|
[e1a97f8] | 342 | self.Layout() |
---|
[2140e68] | 343 | return |
---|
[1b14795] | 344 | |
---|
| 345 | def _show_all_constraint(self): |
---|
| 346 | """ |
---|
| 347 | Show constraint fields |
---|
| 348 | """ |
---|
| 349 | #for id, model in self.constraint_dict.iteritems(): |
---|
| 350 | box_description= wx.StaticBox(self, -1,"Easy Setup ") |
---|
| 351 | boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) |
---|
| 352 | sizer_constraint = wx.BoxSizer(wx.HORIZONTAL|wx.LEFT|wx.RIGHT|wx.EXPAND) |
---|
| 353 | self.model_cbox_left = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 354 | self.model_cbox_left.Clear() |
---|
| 355 | self.model_cbox_right = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 356 | self.model_cbox_right.Clear() |
---|
| 357 | wx.EVT_COMBOBOX(self.model_cbox_left, -1, self._on_select_modelcb) |
---|
| 358 | wx.EVT_COMBOBOX(self.model_cbox_right, -1, self._on_select_modelcb) |
---|
| 359 | egal_txt= wx.StaticText(self,-1," = ") |
---|
| 360 | self.set_button =wx.Button(self, wx.NewId(),'Set All') |
---|
| 361 | self.set_button.Bind(wx.EVT_BUTTON, self._on_set_all_equal, |
---|
| 362 | id=self.set_button.GetId()) |
---|
| 363 | set_tip = "Add constraints for all the adjustable parameters " |
---|
| 364 | set_tip += "(checked in FitPages) if exist." |
---|
| 365 | self.set_button.SetToolTipString(set_tip) |
---|
| 366 | self.set_button.Disable() |
---|
| 367 | |
---|
| 368 | for id, model in self.constraint_dict.iteritems(): |
---|
| 369 | ## check if all parameters have been selected for constraint |
---|
| 370 | ## then do not allow add constraint on parameters |
---|
| 371 | self.model_cbox_left.Append( str(model.name), model) |
---|
| 372 | self.model_cbox_left.Select(0) |
---|
| 373 | for id, model in self.constraint_dict.iteritems(): |
---|
| 374 | ## check if all parameters have been selected for constraint |
---|
| 375 | ## then do not allow add constraint on parameters |
---|
| 376 | self.model_cbox_right.Append( str(model.name), model) |
---|
| 377 | boxsizer.Add(self.model_cbox_left, |
---|
| 378 | flag= wx.RIGHT|wx.EXPAND, border=10) |
---|
| 379 | boxsizer.Add(wx.StaticText(self, -1,".parameters"), |
---|
| 380 | flag= wx.RIGHT|wx.EXPAND, border=5) |
---|
| 381 | boxsizer.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND, border=5) |
---|
| 382 | boxsizer.Add(self.model_cbox_right, |
---|
| 383 | flag= wx.RIGHT|wx.EXPAND, border=10) |
---|
| 384 | boxsizer.Add(wx.StaticText(self, -1,".parameters"), |
---|
| 385 | flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
| 386 | boxsizer.Add((20,-1)) |
---|
| 387 | boxsizer.Add(self.set_button, flag= wx.RIGHT|wx.EXPAND, border=5) |
---|
| 388 | sizer_constraint.Add(boxsizer, flag= wx.RIGHT|wx.EXPAND, border=5) |
---|
| 389 | self.sizer_all_constraints.Insert(before=0, |
---|
| 390 | item=sizer_constraint, |
---|
| 391 | flag= wx.TOP|wx.BOTTOM|wx.EXPAND, border=5) |
---|
| 392 | |
---|
| 393 | self.sizer_all_constraints.Layout() |
---|
| 394 | self.sizer2.Layout() |
---|
[e1a97f8] | 395 | #self.SetScrollbars(20,20,25,65) |
---|
[1b14795] | 396 | |
---|
| 397 | def _on_select_modelcb(self, event): |
---|
| 398 | """ |
---|
| 399 | On select model left or right combobox |
---|
| 400 | """ |
---|
| 401 | event.Skip() |
---|
| 402 | flag = True |
---|
| 403 | if self.model_cbox_left.GetValue().strip() == '': |
---|
| 404 | flag = False |
---|
| 405 | if self.model_cbox_right.GetValue().strip() == '': |
---|
| 406 | flag = False |
---|
| 407 | if self.model_cbox_left.GetValue() ==\ |
---|
| 408 | self.model_cbox_right.GetValue(): |
---|
| 409 | flag = False |
---|
| 410 | self.set_button.Enable(flag) |
---|
| 411 | |
---|
| 412 | def _on_set_all_equal(self, event): |
---|
| 413 | """ |
---|
| 414 | On set button |
---|
| 415 | """ |
---|
| 416 | event.Skip() |
---|
| 417 | length = len(self.constraints_list) |
---|
| 418 | if length < 1: |
---|
| 419 | return |
---|
| 420 | param_list = [] |
---|
| 421 | param_listB = [] |
---|
| 422 | selection = self.model_cbox_left.GetCurrentSelection() |
---|
| 423 | model_left = self.model_cbox_left.GetValue() |
---|
| 424 | model = self.model_cbox_left.GetClientData(selection) |
---|
| 425 | selectionB = self.model_cbox_right.GetCurrentSelection() |
---|
| 426 | model_right = self.model_cbox_right.GetValue() |
---|
| 427 | modelB = self.model_cbox_right.GetClientData(selectionB) |
---|
| 428 | for id, dic_model in self.constraint_dict.iteritems(): |
---|
| 429 | if model == dic_model: |
---|
| 430 | param_list = self.page_finder[id].get_param2fit() |
---|
| 431 | if modelB == dic_model: |
---|
| 432 | param_listB = self.page_finder[id].get_param2fit() |
---|
| 433 | if len(param_list) > 0 and len(param_listB) > 0: |
---|
| 434 | break |
---|
| 435 | #param_list= get_fittableParam(model) |
---|
| 436 | #param_listB= get_fittableParam(modelB) |
---|
| 437 | num_cbox = 0 |
---|
| 438 | has_param = False |
---|
| 439 | for param in param_list: |
---|
| 440 | num_cbox += 1 |
---|
| 441 | if param in param_listB: |
---|
| 442 | self.model_cbox.SetStringSelection(model_left) |
---|
| 443 | self._on_select_model(None) |
---|
| 444 | self.param_cbox.Clear() |
---|
| 445 | self.param_cbox.Append( str(param), model) |
---|
| 446 | self.param_cbox.SetStringSelection( str(param)) |
---|
| 447 | self.ctl2.SetValue(str(model_right + "." + str(param))) |
---|
| 448 | has_param = True |
---|
[00daba9] | 449 | if num_cbox == (len(param_list) + 1): |
---|
[1b14795] | 450 | break |
---|
| 451 | self._show_constraint() |
---|
| 452 | |
---|
| 453 | self.sizer_constraints.Layout() |
---|
| 454 | self.sizer2.Layout() |
---|
[e1a97f8] | 455 | self.SetScrollbars(20,20,25,65) |
---|
| 456 | self.Layout() |
---|
[1b14795] | 457 | if not has_param: |
---|
| 458 | msg= " There is no adjustable parameter (checked to fit)" |
---|
| 459 | msg += " either one of the models." |
---|
| 460 | wx.PostEvent(self.parent.parent, StatusEvent(info="warning", |
---|
| 461 | status= msg )) |
---|
| 462 | else: |
---|
| 463 | msg= " The constraints are added." |
---|
| 464 | wx.PostEvent(self.parent.parent, StatusEvent(info="info", |
---|
| 465 | status= msg )) |
---|
[2140e68] | 466 | def _show_constraint(self): |
---|
| 467 | """ |
---|
[5062bbf] | 468 | Show constraint fields |
---|
[2140e68] | 469 | """ |
---|
[77e23a2] | 470 | self.btAdd.Show(True) |
---|
[2140e68] | 471 | if len(self.constraints_list)!= 0: |
---|
| 472 | nb_fit_param = 0 |
---|
[1b14795] | 473 | for id, model in self.constraint_dict.iteritems(): |
---|
[00daba9] | 474 | nb_fit_param += len(self.page_finder[id].get_param2fit()) |
---|
[2140e68] | 475 | ##Don't add anymore |
---|
| 476 | if len(self.constraints_list) == nb_fit_param: |
---|
[ac11e40] | 477 | msg= "Cannot add another constraint .Maximum of number " |
---|
| 478 | msg += "Parameters name reached %s"%str(nb_fit_param) |
---|
[1b14795] | 479 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[b28717b] | 480 | self.sizer_constraints.Layout() |
---|
[ac11e40] | 481 | self.sizer2.Layout() |
---|
[00daba9] | 482 | #self.SetScrollbars(20,20,25,65) |
---|
[ac11e40] | 483 | return |
---|
[284f6fe] | 484 | if len(self.model_toFit) < 1 : |
---|
| 485 | msg= "Select at least 1 model to add constraint " |
---|
[1b14795] | 486 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[b28717b] | 487 | self.sizer_constraints.Layout() |
---|
[2140e68] | 488 | self.sizer2.Layout() |
---|
[00daba9] | 489 | #self.SetScrollbars(20,20,25,65) |
---|
[2140e68] | 490 | return |
---|
| 491 | |
---|
| 492 | sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) |
---|
[8bd4dc0] | 493 | model_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
[2140e68] | 494 | model_cbox.Clear() |
---|
[1b14795] | 495 | param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY, size=(100,-1),) |
---|
[b28717b] | 496 | param_cbox.Hide() |
---|
[8dfe0fd] | 497 | |
---|
| 498 | #This is for GetCLientData() _on_select_param: Was None return on MAC. |
---|
| 499 | self.param_cbox = param_cbox |
---|
| 500 | |
---|
[2140e68] | 501 | wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param) |
---|
[1b14795] | 502 | self.ctl2 = wx.TextCtrl(self, -1) |
---|
[77a43fb] | 503 | egal_txt= wx.StaticText(self,-1, " = ") |
---|
| 504 | self.btRemove = wx.Button(self,wx.NewId(),'Remove') |
---|
| 505 | self.btRemove.Bind(wx.EVT_BUTTON, self.onRemove, |
---|
| 506 | id=self.btRemove.GetId()) |
---|
| 507 | self.btRemove.SetToolTipString("Remove constraint.") |
---|
| 508 | self.btRemove.Hide() |
---|
| 509 | if hasattr(self,"btAdd"): |
---|
| 510 | self.btAdd.Hide() |
---|
[1b14795] | 511 | for id, model in self.constraint_dict.iteritems(): |
---|
[2140e68] | 512 | ## check if all parameters have been selected for constraint |
---|
| 513 | ## then do not allow add constraint on parameters |
---|
[ac11e40] | 514 | model_cbox.Append( str(model.name), model) |
---|
[2140e68] | 515 | |
---|
[8dfe0fd] | 516 | #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC. |
---|
| 517 | self.model_cbox = model_cbox |
---|
[2140e68] | 518 | |
---|
| 519 | wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model) |
---|
[1b14795] | 520 | sizer_constraint.Add((5,-1)) |
---|
[b28717b] | 521 | sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
| 522 | sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
| 523 | sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
[1b14795] | 524 | sizer_constraint.Add(self.ctl2, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
[77a43fb] | 525 | sizer_constraint.Add(self.btRemove, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
[b28717b] | 526 | |
---|
| 527 | self.sizer_constraints.Insert(before=self.nb_constraint, |
---|
[77a43fb] | 528 | item=sizer_constraint, flag= wx.TOP|wx.BOTTOM|wx.EXPAND, |
---|
| 529 | border=5) |
---|
[8bd4dc0] | 530 | ##[combobox1, combobox2,=,textcrtl, remove button ] |
---|
[77a43fb] | 531 | self.constraints_list.append([model_cbox, param_cbox, egal_txt, |
---|
| 532 | self.ctl2,self.btRemove,sizer_constraint]) |
---|
[5062bbf] | 533 | |
---|
[b28717b] | 534 | self.nb_constraint += 1 |
---|
| 535 | self.sizer_constraints.Layout() |
---|
[2140e68] | 536 | self.sizer2.Layout() |
---|
[00daba9] | 537 | #self.SetScrollbars(20,20,25,65) |
---|
[2140e68] | 538 | |
---|
| 539 | def _hide_constraint(self): |
---|
| 540 | """ |
---|
[5062bbf] | 541 | hide buttons related constraint |
---|
[ac11e40] | 542 | """ |
---|
[6bbeacd4] | 543 | for id in self.page_finder.iterkeys(): |
---|
| 544 | self.page_finder[id].clear_model_param() |
---|
[b28717b] | 545 | |
---|
[1b14795] | 546 | self.nb_constraint = 0 |
---|
| 547 | self.constraint_dict = {} |
---|
[69bee6d] | 548 | if hasattr(self,"btAdd"): |
---|
| 549 | self.btAdd.Hide() |
---|
[ac11e40] | 550 | self._store_model() |
---|
[53fc5ad9] | 551 | if self.model_cbox_left != None: |
---|
| 552 | self.model_cbox_left.Clear() |
---|
| 553 | self.model_cbox_left = None |
---|
| 554 | if self.model_cbox_right != None: |
---|
| 555 | self.model_cbox_right.Clear() |
---|
| 556 | self.model_cbox_right = None |
---|
[1b14795] | 557 | self.constraints_list = [] |
---|
| 558 | self.sizer_all_constraints.Clear(True) |
---|
| 559 | self.sizer_all_constraints.Layout() |
---|
[b28717b] | 560 | self.sizer_constraints.Clear(True) |
---|
| 561 | self.sizer_constraints.Layout() |
---|
[2140e68] | 562 | self.sizer2.Layout() |
---|
[e1a97f8] | 563 | #self.SetScrollbars(20,20,25,65) |
---|
| 564 | #self.AdjustScrollbars() |
---|
[5062bbf] | 565 | |
---|
[2140e68] | 566 | def _on_select_model(self, event): |
---|
| 567 | """ |
---|
[5062bbf] | 568 | fill combox box with list of parameters |
---|
[2140e68] | 569 | """ |
---|
[53fc5ad9] | 570 | param_list = [] |
---|
[8dfe0fd] | 571 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
| 572 | n = self.model_cbox.GetCurrentSelection() |
---|
| 573 | model = self.model_cbox.GetClientData(n) |
---|
[1b14795] | 574 | for id, dic_model in self.constraint_dict.iteritems(): |
---|
| 575 | if model == dic_model: |
---|
| 576 | param_list = self.page_finder[id].get_param2fit() |
---|
[53fc5ad9] | 577 | #break |
---|
[1b14795] | 578 | #param_list= get_fittableParam(model) |
---|
[2140e68] | 579 | length = len(self.constraints_list) |
---|
| 580 | if length < 1: |
---|
| 581 | return |
---|
| 582 | param_cbox = self.constraints_list[length-1][1] |
---|
| 583 | param_cbox.Clear() |
---|
| 584 | ## insert only fittable paramaters |
---|
| 585 | for param in param_list: |
---|
[ac11e40] | 586 | param_cbox.Append( str(param), model) |
---|
[53fc5ad9] | 587 | |
---|
[2140e68] | 588 | param_cbox.Show(True) |
---|
[77a43fb] | 589 | self.btRemove.Show(True) |
---|
| 590 | self.btAdd.Show(True) |
---|
[2140e68] | 591 | self.sizer2.Layout() |
---|
[e1a97f8] | 592 | #self.SetScrollbars(20,20,25,65) |
---|
[2140e68] | 593 | |
---|
| 594 | def _on_select_param(self, event): |
---|
| 595 | """ |
---|
[5062bbf] | 596 | Store the appropriate constraint in the page_finder |
---|
[2140e68] | 597 | """ |
---|
[8dfe0fd] | 598 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
| 599 | n = self.param_cbox.GetCurrentSelection() |
---|
| 600 | model = self.param_cbox.GetClientData(n) |
---|
[2140e68] | 601 | param = event.GetString() |
---|
[ac11e40] | 602 | |
---|
[2140e68] | 603 | length = len(self.constraints_list) |
---|
| 604 | if length < 1: |
---|
| 605 | return |
---|
| 606 | egal_txt = self.constraints_list[length-1][2] |
---|
| 607 | egal_txt.Show(True) |
---|
| 608 | |
---|
| 609 | ctl2 = self.constraints_list[length-1][3] |
---|
| 610 | ctl2.Show(True) |
---|
[6e9976b] | 611 | #self.sizer2.Layout() |
---|
[e1a97f8] | 612 | #self.SetScrollbars(20,20,25,65) |
---|
[2140e68] | 613 | |
---|
| 614 | def _onAdd_constraint(self, event): |
---|
| 615 | """ |
---|
[5062bbf] | 616 | Add another line for constraint |
---|
[2140e68] | 617 | """ |
---|
[8bd4dc0] | 618 | if not self.show_constraint.GetValue(): |
---|
| 619 | msg= " Select Yes to add Constraint " |
---|
[1b14795] | 620 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[8bd4dc0] | 621 | return |
---|
[1b14795] | 622 | ## check that a constraint is added |
---|
| 623 | # before allow to add another constraint |
---|
[2140e68] | 624 | for item in self.constraints_list: |
---|
| 625 | model_cbox = item[0] |
---|
| 626 | if model_cbox.GetString(0)=="": |
---|
| 627 | msg= " Select a model Name! " |
---|
[1b14795] | 628 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[2140e68] | 629 | return |
---|
| 630 | param_cbox = item[1] |
---|
| 631 | if param_cbox.GetString(0)=="": |
---|
| 632 | msg= " Select a parameter Name! " |
---|
[1b14795] | 633 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[2140e68] | 634 | return |
---|
| 635 | ctl2 = item[3] |
---|
| 636 | if ctl2.GetValue().lstrip().rstrip()=="": |
---|
[b28717b] | 637 | model= param_cbox.GetClientData(param_cbox.GetCurrentSelection()) |
---|
[1b14795] | 638 | msg= " Enter a constraint for %s.%s! "%(model.name, |
---|
| 639 | param_cbox.GetString(0)) |
---|
| 640 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[b28717b] | 641 | return |
---|
[2140e68] | 642 | ## some model or parameters can be constrained |
---|
| 643 | self._show_constraint() |
---|
| 644 | |
---|
[8bd4dc0] | 645 | def _fill_sizer_fit(self): |
---|
| 646 | """ |
---|
[5062bbf] | 647 | Draw fit button |
---|
[8bd4dc0] | 648 | """ |
---|
| 649 | self.sizer3.Clear(True) |
---|
| 650 | box_description= wx.StaticBox(self, -1,"Fit ") |
---|
| 651 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 652 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 653 | |
---|
| 654 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
| 655 | self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id= self.btFit.GetId()) |
---|
| 656 | self.btFit.SetToolTipString("Perform fit.") |
---|
[1aa6145] | 657 | text = " Note: Park fitting engine will be used automatically. \n" |
---|
| 658 | text += " This page requires at least one FitPage with a data \n" |
---|
| 659 | text += " and a model set for fitting." |
---|
[284f6fe] | 660 | #text+= "automatically for more than 2 combinations checked" |
---|
[8bd4dc0] | 661 | text_hint = wx.StaticText(self,-1,text) |
---|
| 662 | |
---|
| 663 | sizer_button.Add(text_hint, wx.RIGHT|wx.EXPAND, 10) |
---|
| 664 | sizer_button.Add(self.btFit, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 665 | |
---|
| 666 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
| 667 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 668 | self.sizer3.Layout() |
---|
[e1a97f8] | 669 | #self.SetScrollbars(20,20,25,65) |
---|
[2140e68] | 670 | |
---|
| 671 | def _fill_sizer_constraint(self): |
---|
| 672 | """ |
---|
[5062bbf] | 673 | Fill sizer containing constraint info |
---|
[2140e68] | 674 | """ |
---|
[5062bbf] | 675 | msg = "Select at least 2 model to add constraint " |
---|
[1b14795] | 676 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[2140e68] | 677 | |
---|
| 678 | self.sizer2.Clear(True) |
---|
| 679 | box_description= wx.StaticBox(self, -1,"Fit Constraints") |
---|
| 680 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 681 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
[1b14795] | 682 | self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) |
---|
[b28717b] | 683 | self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) |
---|
[2140e68] | 684 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 685 | |
---|
[1b14795] | 686 | self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), |
---|
| 687 | style=wx.RB_GROUP) |
---|
[2140e68] | 688 | self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
| 689 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
| 690 | id= self.hide_constraint.GetId() ) |
---|
| 691 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
| 692 | id= self.show_constraint.GetId() ) |
---|
[17c5868] | 693 | self.hide_constraint.SetValue(True) |
---|
[2140e68] | 694 | sizer_title.Add( wx.StaticText(self,-1," Model") ) |
---|
| 695 | sizer_title.Add(( 10,10) ) |
---|
| 696 | sizer_title.Add( wx.StaticText(self,-1," Parameter") ) |
---|
| 697 | sizer_title.Add(( 10,10) ) |
---|
| 698 | sizer_title.Add( wx.StaticText(self,-1," Add Constraint?") ) |
---|
| 699 | sizer_title.Add(( 10,10) ) |
---|
| 700 | sizer_title.Add( self.show_constraint ) |
---|
| 701 | sizer_title.Add( self.hide_constraint ) |
---|
| 702 | sizer_title.Add(( 10,10) ) |
---|
[1b14795] | 703 | |
---|
[2140e68] | 704 | self.btAdd =wx.Button(self,wx.NewId(),'Add') |
---|
[1b14795] | 705 | self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, |
---|
| 706 | id=self.btAdd.GetId()) |
---|
[2140e68] | 707 | self.btAdd.SetToolTipString("Add another constraint?") |
---|
[77e23a2] | 708 | self.btAdd.Hide() |
---|
[8bd4dc0] | 709 | |
---|
[1b14795] | 710 | text_hint = wx.StaticText(self, -1, |
---|
| 711 | "Example: [M0][paramter] = M1.parameter") |
---|
[2140e68] | 712 | sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 713 | sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 714 | |
---|
[8bd4dc0] | 715 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
[1b14795] | 716 | boxsizer1.Add(self.sizer_all_constraints, flag= wx.TOP|wx.BOTTOM, |
---|
| 717 | border=10) |
---|
| 718 | boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM, |
---|
| 719 | border=10) |
---|
| 720 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM, border=10) |
---|
[2140e68] | 721 | |
---|
| 722 | self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 723 | self.sizer2.Layout() |
---|
[e1a97f8] | 724 | #self.SetScrollbars(20,20,25,65) |
---|
[5062bbf] | 725 | |
---|
[2140e68] | 726 | def _set_constraint(self): |
---|
[d89f09b] | 727 | """ |
---|
[5062bbf] | 728 | get values from the constrainst textcrtl ,parses them into model name |
---|
| 729 | parameter name and parameters values. |
---|
[1b14795] | 730 | store them in a list self.params .when when params is not empty |
---|
| 731 | set_model uses it to reset the appropriate model |
---|
| 732 | and its appropriates parameters |
---|
[d89f09b] | 733 | """ |
---|
[2140e68] | 734 | for item in self.constraints_list: |
---|
[ac11e40] | 735 | model = item[0].GetClientData(item[0].GetCurrentSelection()) |
---|
| 736 | param = item[1].GetString(item[1].GetCurrentSelection()) |
---|
[2140e68] | 737 | constraint = item[3].GetValue().lstrip().rstrip() |
---|
[bb7d8a4] | 738 | if param.lstrip().rstrip()=="": |
---|
| 739 | param= None |
---|
[1b14795] | 740 | msg= " Constraint will be ignored!. missing parameters" |
---|
| 741 | msg+= " in combobox to set constraint! " |
---|
| 742 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
[6bbeacd4] | 743 | for id, value in self.constraint_dict.iteritems(): |
---|
[1f57dfd] | 744 | if model == value: |
---|
| 745 | if constraint == "": |
---|
[1b14795] | 746 | msg= " Constraint will be ignored!. missing value" |
---|
| 747 | msg+= " in textcrtl to set constraint! " |
---|
| 748 | wx.PostEvent(self.parent.parent, |
---|
| 749 | StatusEvent(status= msg )) |
---|
[1f57dfd] | 750 | constraint = None |
---|
[00daba9] | 751 | if str(param) in self.page_finder[id].get_param2fit(): |
---|
| 752 | msg = " Checking constraint for parameter: %s ", param |
---|
| 753 | wx.PostEvent(self.parent.parent, |
---|
| 754 | StatusEvent(info="info", status= msg )) |
---|
| 755 | else: |
---|
| 756 | model_name = item[0].GetLabel() |
---|
| 757 | fitpage = self.page_finder[id].get_fit_tab_caption() |
---|
| 758 | msg = "All constrainted parameters must be set " |
---|
| 759 | msg += " adjustable: '%s.%s' "% (model_name, param) |
---|
| 760 | msg += "is NOT checked in '%s'. "% fitpage |
---|
| 761 | msg += " Please check it to fit or" |
---|
| 762 | msg += " remove the line of the constraint." |
---|
| 763 | wx.PostEvent(self.parent.parent, |
---|
| 764 | StatusEvent(info="error", status= msg )) |
---|
| 765 | return False |
---|
| 766 | |
---|
[c647377] | 767 | for fid in self.page_finder[id].iterkeys(): |
---|
| 768 | self.page_finder[id].set_model_param(param, |
---|
| 769 | constraint, fid=fid) |
---|
[1f57dfd] | 770 | break |
---|
[00daba9] | 771 | return True |
---|
[5062bbf] | 772 | |
---|
[2140e68] | 773 | def _fill_sizer_model_list(self,sizer): |
---|
[d89f09b] | 774 | """ |
---|
[5062bbf] | 775 | Receive a dictionary containing information to display model name |
---|
| 776 | |
---|
| 777 | :param page_finder: the dictionary containing models information |
---|
| 778 | |
---|
[d89f09b] | 779 | """ |
---|
[2140e68] | 780 | ix = 0 |
---|
| 781 | iy = 0 |
---|
| 782 | list=[] |
---|
| 783 | sizer.Clear(True) |
---|
| 784 | |
---|
[1b14795] | 785 | new_name = wx.StaticText(self, -1, 'New Model Name', |
---|
| 786 | style=wx.ALIGN_CENTER) |
---|
[2140e68] | 787 | new_name.SetBackgroundColour('orange') |
---|
| 788 | sizer.Add(new_name,(iy, ix),(1,1), |
---|
| 789 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[5062bbf] | 790 | ix += 2 |
---|
[2140e68] | 791 | model_type = wx.StaticText(self, -1, ' Model Type') |
---|
| 792 | model_type.SetBackgroundColour('grey') |
---|
| 793 | sizer.Add(model_type,(iy, ix),(1,1), |
---|
| 794 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[5062bbf] | 795 | ix += 1 |
---|
[2140e68] | 796 | data_used = wx.StaticText(self, -1, ' Used Data') |
---|
| 797 | data_used.SetBackgroundColour('grey') |
---|
| 798 | sizer.Add(data_used,(iy, ix),(1,1), |
---|
| 799 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[6bbeacd4] | 800 | ix += 1 |
---|
| 801 | tab_used = wx.StaticText(self, -1, ' Fit Tab') |
---|
| 802 | tab_used.SetBackgroundColour('grey') |
---|
| 803 | sizer.Add(tab_used,(iy, ix),(1,1), |
---|
| 804 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 805 | for id, value in self.page_finder.iteritems(): |
---|
[53fc5ad9] | 806 | if id not in self.parent.opened_pages: |
---|
| 807 | continue |
---|
[2140e68] | 808 | try: |
---|
| 809 | ix = 0 |
---|
[c647377] | 810 | for fitproblem in value.get_fit_problem(): |
---|
[0a9871c] | 811 | if not self.parent.get_page_by_id(id).batch_on: |
---|
| 812 | iy += 1 |
---|
| 813 | data = fitproblem.get_fit_data() |
---|
| 814 | model = fitproblem.get_model() |
---|
| 815 | name = '_' |
---|
| 816 | if model is not None: |
---|
| 817 | name = str(model.name) |
---|
| 818 | cb = wx.CheckBox(self, -1, name) |
---|
| 819 | cb.SetValue(False) |
---|
| 820 | cb.Enable(model is not None and data.is_data) |
---|
| 821 | sizer.Add(cb, (iy, ix), (1, 1), |
---|
| 822 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 823 | wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) |
---|
| 824 | ix += 2 |
---|
| 825 | type = model.__class__.__name__ |
---|
| 826 | model_type = wx.StaticText(self, -1, str(type)) |
---|
| 827 | sizer.Add(model_type, (iy, ix), (1, 1), |
---|
| 828 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 829 | name = '-' |
---|
| 830 | if data is not None and data.is_data: |
---|
| 831 | name = str(data.name) |
---|
| 832 | data_used = wx.StaticText(self, -1, name) |
---|
| 833 | ix += 1 |
---|
| 834 | sizer.Add(data_used, (iy, ix), (1, 1), |
---|
| 835 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 836 | ix += 1 |
---|
| 837 | caption = value.get_fit_tab_caption() |
---|
| 838 | tab_caption_used= wx.StaticText(self, -1, str(caption)) |
---|
| 839 | sizer.Add(tab_caption_used, (iy, ix), (1, 1), |
---|
| 840 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[6bbeacd4] | 841 | |
---|
[0a9871c] | 842 | self.model_list.append([cb,value,id,model]) |
---|
[2140e68] | 843 | |
---|
| 844 | except: |
---|
[6bbeacd4] | 845 | raise |
---|
| 846 | #pass |
---|
[5062bbf] | 847 | iy += 1 |
---|
[c647377] | 848 | sizer.Add((20, 20), (iy, ix), (1, 1), |
---|
| 849 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[2140e68] | 850 | sizer.Layout() |
---|
[0a9871c] | 851 | |
---|
[c647377] | 852 | |
---|
[4133316] | 853 | def on_set_focus(self, event=None): |
---|
| 854 | """ |
---|
| 855 | The derivative class is on focus if implemented |
---|
| 856 | """ |
---|
| 857 | if self.parent is not None: |
---|
[1976004] | 858 | if self.parent.parent is not None: |
---|
| 859 | wx.PostEvent(self.parent.parent, PanelOnFocusEvent(panel=self)) |
---|
| 860 | self.page_finder = self.parent._manager.get_page_finder() |
---|
[4133316] | 861 | |
---|