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