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