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