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