[d89f09b] | 1 | import wx |
---|
[26bf293] | 2 | import wx.aui |
---|
[d89f09b] | 3 | import wx.lib |
---|
| 4 | import numpy |
---|
| 5 | import string ,re |
---|
| 6 | #import models |
---|
| 7 | _BOX_WIDTH = 80 |
---|
[cfc0913] | 8 | import basepage |
---|
[00c3aac] | 9 | |
---|
[cfc0913] | 10 | class PageInfo(object): |
---|
| 11 | """ |
---|
| 12 | this class contains the minimum numbers of data members |
---|
| 13 | a fitpage or model page need to be initialized. |
---|
| 14 | """ |
---|
| 15 | data = None |
---|
| 16 | model= None |
---|
| 17 | manager= None |
---|
| 18 | event_owner= None |
---|
| 19 | model_list_box = None |
---|
| 20 | name=None |
---|
| 21 | ## Internal name for the AUI manager |
---|
| 22 | window_name = "Page" |
---|
| 23 | ## Title to appear on top of the window |
---|
| 24 | window_caption = "Page" |
---|
| 25 | |
---|
| 26 | def __init__(self, model=None,data=None, manager=None, |
---|
| 27 | event_owner=None,model_list_box=None , name=None): |
---|
| 28 | """ |
---|
| 29 | Initialize data members |
---|
| 30 | """ |
---|
| 31 | self.data = data |
---|
| 32 | self.model= model |
---|
| 33 | self.manager= manager |
---|
| 34 | self.event_owner= event_owner |
---|
| 35 | self.model_list_box = model_list_box |
---|
| 36 | self.name=None |
---|
| 37 | self.window_name = "Page" |
---|
| 38 | self.window_caption = "Page" |
---|
| 39 | |
---|
[26bf293] | 40 | class FitPanel(wx.aui.AuiNotebook): |
---|
[925a30e] | 41 | |
---|
[d89f09b] | 42 | """ |
---|
| 43 | FitPanel class contains fields allowing to fit models and data |
---|
| 44 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 45 | on fit Panel window. |
---|
| 46 | |
---|
| 47 | """ |
---|
| 48 | ## Internal name for the AUI manager |
---|
| 49 | window_name = "Fit panel" |
---|
| 50 | ## Title to appear on top of the window |
---|
| 51 | window_caption = "Fit Panel " |
---|
[2139c3f] | 52 | CENTER_PANE = True |
---|
[7437880] | 53 | |
---|
[d89f09b] | 54 | def __init__(self, parent, *args, **kwargs): |
---|
[e814734] | 55 | wx.aui.AuiNotebook.__init__(self,parent,-1, |
---|
[848a2ef] | 56 | style= wx.aui.AUI_NB_WINDOWLIST_BUTTON|wx.aui.AUI_NB_DEFAULT_STYLE|wx.CLIP_CHILDREN ) |
---|
| 57 | |
---|
[d89f09b] | 58 | self.manager=None |
---|
| 59 | self.parent=parent |
---|
| 60 | self.event_owner=None |
---|
[26bf293] | 61 | |
---|
| 62 | pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE |
---|
| 63 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage) |
---|
[e814734] | 64 | ##Creating the default page --welcomed page |
---|
[51d47b5] | 65 | self.about_page=None |
---|
[1328e03] | 66 | from welcome_panel import PanelAbout |
---|
[94999eb] | 67 | self.about_page = PanelAbout(self, -1) |
---|
[280a14b] | 68 | self.AddPage(self.about_page,"Welcome!") |
---|
[925a30e] | 69 | |
---|
[51d47b5] | 70 | |
---|
[d89f09b] | 71 | #dictionary of miodel {model class name, model class} |
---|
| 72 | self.model_list_box={} |
---|
[00c3aac] | 73 | ##dictionary of page info |
---|
| 74 | self.page_info_dict={} |
---|
[cfc0913] | 75 | ## save the title of the last page tab added |
---|
| 76 | self.fit_page_name={} |
---|
| 77 | ## list of existing fit page |
---|
| 78 | self.list_fitpage_name=[] |
---|
[6999659] | 79 | |
---|
[f39511b] | 80 | #model page info |
---|
| 81 | self.model_page_number=None |
---|
[882a912] | 82 | ## fit page number for model plot |
---|
| 83 | self.fit_page1D_number=None |
---|
| 84 | self.fit_page2D_number=None |
---|
[f39511b] | 85 | self.model_page=None |
---|
[51d47b5] | 86 | self.sim_page=None |
---|
[cfc0913] | 87 | ## get the state of a page |
---|
| 88 | self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate) |
---|
[6bcdad1] | 89 | # increment number for model name |
---|
| 90 | self.count=0 |
---|
[f39511b] | 91 | #updating the panel |
---|
[26bf293] | 92 | self.Update() |
---|
[d89f09b] | 93 | self.Center() |
---|
[2a8fac1] | 94 | |
---|
| 95 | |
---|
[26bf293] | 96 | def onClosePage(self, event): |
---|
[51d47b5] | 97 | """ |
---|
[925a30e] | 98 | close page and remove all references to the closed page |
---|
[51d47b5] | 99 | """ |
---|
| 100 | selected_page = self.GetPage(self.GetSelection()) |
---|
[7c845cb] | 101 | ## removing about page |
---|
| 102 | if selected_page==self.about_page: |
---|
| 103 | self.about_page=None |
---|
| 104 | return |
---|
| 105 | ## removing sim_page |
---|
| 106 | if selected_page == self.sim_page: |
---|
| 107 | self.manager.sim_page=None |
---|
| 108 | return |
---|
[9853ad0] | 109 | |
---|
[7c845cb] | 110 | ## closing other pages |
---|
| 111 | state = selected_page.createMemento() |
---|
| 112 | page_name = selected_page.window_name |
---|
| 113 | page_finder = self.manager.get_page_finder() |
---|
| 114 | fitproblem = None |
---|
| 115 | ## removing model page |
---|
| 116 | if selected_page == self.model_page: |
---|
| 117 | fitproblem = selected_page.model.clone() |
---|
| 118 | self.model_page = None |
---|
[ff36f31] | 119 | self.count =0 |
---|
[7c845cb] | 120 | ## page on menu |
---|
[848a2ef] | 121 | self.manager._add_page_onmenu(page_name, fitproblem) |
---|
[7c845cb] | 122 | else: |
---|
| 123 | if selected_page in page_finder: |
---|
| 124 | |
---|
| 125 | fitproblem= page_finder[selected_page].clone() |
---|
[882a912] | 126 | if self.GetPageIndex(selected_page)==self.fit_page1D_number: |
---|
| 127 | self.fit_page1D_number=None |
---|
| 128 | if self.GetPageIndex(selected_page)==self.fit_page2D_number: |
---|
| 129 | self.fit_page2D_number=None |
---|
[7c845cb] | 130 | ## page on menu |
---|
[848a2ef] | 131 | self.manager._add_page_onmenu(page_name, fitproblem) |
---|
[7c845cb] | 132 | del page_finder[selected_page] |
---|
| 133 | ##remove the check box link to the model name of this page (selected_page) |
---|
| 134 | try: |
---|
[1d2782d] | 135 | self.sim_page.draw_page() |
---|
[7c845cb] | 136 | except: |
---|
| 137 | ## that page is already deleted no need to remove check box on |
---|
| 138 | ##non existing page |
---|
| 139 | pass |
---|
[9853ad0] | 140 | |
---|
[7c845cb] | 141 | #Delete the name of the page into the list of open page |
---|
| 142 | if selected_page.window_name in self.list_fitpage_name: |
---|
| 143 | self.list_fitpage_name.remove(selected_page.window_name) |
---|
[a074145] | 144 | |
---|
[d89f09b] | 145 | |
---|
| 146 | def set_manager(self, manager): |
---|
| 147 | """ |
---|
| 148 | set panel manager |
---|
| 149 | @param manager: instance of plugin fitting |
---|
| 150 | """ |
---|
| 151 | self.manager = manager |
---|
[925a30e] | 152 | |
---|
[d89f09b] | 153 | |
---|
| 154 | def set_owner(self,owner): |
---|
| 155 | """ |
---|
| 156 | set and owner for fitpanel |
---|
| 157 | @param owner: the class responsible of plotting |
---|
| 158 | """ |
---|
[c77d859] | 159 | self.event_owner = owner |
---|
| 160 | |
---|
| 161 | def set_model_list(self,dict): |
---|
| 162 | """ |
---|
| 163 | copy a dictionary of model into its own dictionary |
---|
| 164 | @param dict: dictionnary made of model name as key and model class |
---|
| 165 | as value |
---|
| 166 | """ |
---|
| 167 | self.model_list_box = dict |
---|
[51d47b5] | 168 | |
---|
[c77d859] | 169 | |
---|
| 170 | def get_current_page(self): |
---|
| 171 | """ |
---|
| 172 | @return the current page selected |
---|
| 173 | """ |
---|
| 174 | return self.GetPage(self.GetSelection() ) |
---|
| 175 | |
---|
[51d47b5] | 176 | def add_sim_page(self): |
---|
[925a30e] | 177 | """ |
---|
| 178 | Add the simultaneous fit page |
---|
| 179 | """ |
---|
[51d47b5] | 180 | from simfitpage import SimultaneousFitPage |
---|
[b28717b] | 181 | page_finder= self.manager.get_page_finder() |
---|
| 182 | self.sim_page = SimultaneousFitPage(self,page_finder=page_finder, id=-1) |
---|
| 183 | |
---|
[51d47b5] | 184 | self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True) |
---|
| 185 | self.sim_page.set_manager(self.manager) |
---|
| 186 | return self.sim_page |
---|
[d89f09b] | 187 | |
---|
[cfc0913] | 188 | def add_fit_page( self,data, reset=False ): |
---|
[d89f09b] | 189 | """ |
---|
| 190 | Add a fitting page on the notebook contained by fitpanel |
---|
[925a30e] | 191 | @param data: data to fit |
---|
[b787e68c] | 192 | @return panel : page just added for further used. is used by fitting module |
---|
[d89f09b] | 193 | """ |
---|
[882a912] | 194 | if data.is_data: |
---|
[925a30e] | 195 | name = data.name |
---|
[882a912] | 196 | else: |
---|
| 197 | if data.__class__.__name__=="Data2D": |
---|
| 198 | name = 'Model 2D Fit' |
---|
| 199 | else: |
---|
| 200 | name = 'Model 1D Fit' |
---|
[cfc0913] | 201 | if not name in self.list_fitpage_name: |
---|
| 202 | myinfo = PageInfo( data=data, name=name ) |
---|
[dcf29d7] | 203 | myinfo.model_list_box = self.model_list_box.get_list() |
---|
| 204 | myinfo.event_owner = self.event_owner |
---|
| 205 | myinfo.manager = self.manager |
---|
[b787e68c] | 206 | myinfo.window_name = name |
---|
| 207 | myinfo.window_caption = name |
---|
[6e659ae8] | 208 | |
---|
[cfc0913] | 209 | #if not name in self.fit_page_name : |
---|
[c77d859] | 210 | from fitpage import FitPage |
---|
[cfc0913] | 211 | panel = FitPage(parent= self, page_info=myinfo) |
---|
[b787e68c] | 212 | |
---|
| 213 | self.AddPage(page=panel, caption=name, select=True) |
---|
[882a912] | 214 | if name == 'Model 1D Fit': |
---|
| 215 | self.fit_page1D_number= self.GetPageIndex(panel) |
---|
| 216 | if name =='Model 2D Fit': |
---|
| 217 | self.fit_page2D_number= self.GetPageIndex(panel) |
---|
| 218 | |
---|
[cfc0913] | 219 | self.list_fitpage_name.append(name) |
---|
| 220 | if reset: |
---|
| 221 | if name in self.fit_page_name.keys(): |
---|
| 222 | memento= self.fit_page_name[name][0] |
---|
| 223 | panel.reset_page(memento) |
---|
| 224 | else: |
---|
| 225 | self.fit_page_name[name]=[] |
---|
| 226 | self.fit_page_name[name].insert(0,panel.createMemento()) |
---|
[882a912] | 227 | #GetPage(self, page_idx) |
---|
[925a30e] | 228 | return panel |
---|
[882a912] | 229 | elif name =='Model 1D Fit': |
---|
| 230 | if self.fit_page1D_number!=None: |
---|
| 231 | panel =self.GetPage(self.fit_page1D_number) |
---|
| 232 | self.fit_page_name[name]=[] |
---|
| 233 | self.fit_page_name[name].insert(0,panel.createMemento()) |
---|
| 234 | return panel |
---|
| 235 | return None |
---|
| 236 | elif name =='Model 2D Fit': |
---|
| 237 | if self.fit_page2D_number!=None: |
---|
| 238 | panel =self.GetPage(self.fit_page2D_number) |
---|
| 239 | self.fit_page_name[name]=[] |
---|
| 240 | self.fit_page_name[name].insert(0,panel.createMemento()) |
---|
| 241 | return panel |
---|
| 242 | return None |
---|
| 243 | return None |
---|
[1c66bc5] | 244 | |
---|
[9853ad0] | 245 | |
---|
[cd793b9] | 246 | def add_model_page(self,model,page_title="Model", qmin=0.0001, qmax=0.13, |
---|
[b787e68c] | 247 | npts=50, topmenu=False, reset=False): |
---|
[9853ad0] | 248 | """ |
---|
| 249 | Add a model page only one to display any model selected from the menu or the page combo box. |
---|
| 250 | when this page is closed than the user will be able to open a new one |
---|
| 251 | |
---|
| 252 | @param model: the model for which paramters will be changed |
---|
| 253 | @param page_title: the name of the page |
---|
[dcf29d7] | 254 | @param page_info: contains info about the state of the page |
---|
[9853ad0] | 255 | @param qmin: mimimum Q |
---|
| 256 | @param qmax: maximum Q |
---|
| 257 | @param npts: number of Q points |
---|
| 258 | """ |
---|
| 259 | if topmenu==True: |
---|
[ff36f31] | 260 | ##first time to open model page |
---|
| 261 | if self.count==0 : |
---|
| 262 | #if not page_title in self.list_fitpage_name : |
---|
[6999659] | 263 | self._help_add_model_page(model=model, page_title=page_title, |
---|
[b787e68c] | 264 | qmin=qmin, qmax=qmax, npts=npts, reset=reset) |
---|
[ff36f31] | 265 | self.count +=1 |
---|
[9853ad0] | 266 | else: |
---|
[fbf4bf8] | 267 | self.model_page.select_model(model) |
---|
[6999659] | 268 | self.fit_page_name[page_title].insert(0,self.model_page.createMemento()) |
---|
[b787e68c] | 269 | |
---|
[848a2ef] | 270 | |
---|
| 271 | |
---|
| 272 | def _close_fitpage(self,data): |
---|
| 273 | """ |
---|
| 274 | close a fit page when its data is completely remove from the graph |
---|
| 275 | """ |
---|
| 276 | name = data.name |
---|
| 277 | for index in range(self.GetPageCount()): |
---|
| 278 | if self.GetPageText(index)== name: |
---|
| 279 | selected_page = self.GetPage(index) |
---|
| 280 | |
---|
| 281 | if index ==self.fit_page1D_number: |
---|
| 282 | self.fit_page1D_number=None |
---|
| 283 | if index ==self.fit_page2D_number: |
---|
| 284 | self.fit_page2D_number=None |
---|
| 285 | if selected_page in self.manager.page_finder: |
---|
| 286 | del self.manager.page_finder[selected_page] |
---|
| 287 | ##remove the check box link to the model name of this page (selected_page) |
---|
| 288 | try: |
---|
| 289 | self.sim_page.draw_page() |
---|
| 290 | except: |
---|
| 291 | ## that page is already deleted no need to remove check box on |
---|
| 292 | ##non existing page |
---|
| 293 | pass |
---|
| 294 | |
---|
| 295 | #Delete the name of the page into the list of open page |
---|
| 296 | if selected_page.window_name in self.list_fitpage_name: |
---|
| 297 | self.list_fitpage_name.remove(selected_page.window_name) |
---|
| 298 | self.DeletePage(index) |
---|
| 299 | break |
---|
| 300 | |
---|
| 301 | |
---|
[cfc0913] | 302 | def _onGetstate(self, event): |
---|
| 303 | """ |
---|
| 304 | copy the state of a page |
---|
| 305 | """ |
---|
| 306 | page= event.page |
---|
[b787e68c] | 307 | if page.window_name in self.fit_page_name: |
---|
| 308 | self.fit_page_name[page.window_name].insert(0,page.createMemento()) |
---|
[cfc0913] | 309 | |
---|
[dcf29d7] | 310 | |
---|
[cd793b9] | 311 | def _help_add_model_page(self,model,page_title="Model", qmin=0.0001, |
---|
| 312 | qmax=0.13, npts=50,reset= False): |
---|
[3f1af74] | 313 | """ |
---|
| 314 | #TODO: fill in description |
---|
| 315 | |
---|
| 316 | @param qmin: mimimum Q |
---|
| 317 | @param qmax: maximum Q |
---|
| 318 | @param npts: number of Q points |
---|
| 319 | """ |
---|
[dcf29d7] | 320 | ## creating object that contaning info about model |
---|
[b787e68c] | 321 | myinfo = PageInfo(model= model ,name= page_title) |
---|
| 322 | myinfo.model_list_box = self.model_list_box.get_list() |
---|
| 323 | myinfo.event_owner = self.event_owner |
---|
| 324 | myinfo.manager = self.manager |
---|
| 325 | myinfo.window_name = page_title |
---|
| 326 | myinfo.window_caption = page_title |
---|
| 327 | |
---|
[c77d859] | 328 | from modelpage import ModelPage |
---|
[cfc0913] | 329 | panel = ModelPage(self,myinfo) |
---|
[b787e68c] | 330 | |
---|
[848a2ef] | 331 | self.AddPage(page=panel, caption=page_title, select=True) |
---|
[77e23a2] | 332 | |
---|
[bb18ef1] | 333 | self.model_page_number=self.GetSelection() |
---|
| 334 | self.model_page=self.GetPage(self.GetSelection()) |
---|
[0aeabc6] | 335 | |
---|
[b787e68c] | 336 | ## resetting page |
---|
| 337 | if reset: |
---|
| 338 | if page_title in self.fit_page_name.keys(): |
---|
[848a2ef] | 339 | |
---|
[b787e68c] | 340 | memento= self.fit_page_name[page_title][0] |
---|
| 341 | panel.reset_page(memento) |
---|
| 342 | else: |
---|
| 343 | self.fit_page_name[page_title]=[] |
---|
| 344 | self.fit_page_name[page_title].insert(0,panel.createMemento()) |
---|
[0aeabc6] | 345 | |
---|
[b787e68c] | 346 | |
---|