[d89f09b] | 1 | import wx |
---|
| 2 | import wx.lib |
---|
| 3 | import numpy |
---|
| 4 | import string ,re |
---|
| 5 | #import models |
---|
| 6 | _BOX_WIDTH = 80 |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | class FitPanel(wx.Panel): |
---|
| 11 | """ |
---|
| 12 | FitPanel class contains fields allowing to fit models and data |
---|
| 13 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 14 | on fit Panel window. |
---|
| 15 | |
---|
| 16 | """ |
---|
| 17 | ## Internal name for the AUI manager |
---|
| 18 | window_name = "Fit panel" |
---|
| 19 | ## Title to appear on top of the window |
---|
| 20 | window_caption = "Fit Panel " |
---|
[2139c3f] | 21 | CENTER_PANE = True |
---|
[d89f09b] | 22 | |
---|
| 23 | |
---|
| 24 | def __init__(self, parent, *args, **kwargs): |
---|
| 25 | wx.Panel.__init__(self, parent, *args, **kwargs) |
---|
| 26 | self.manager=None |
---|
| 27 | self.parent=parent |
---|
| 28 | self.event_owner=None |
---|
| 29 | #self.menu_mng = models.ModelManager() |
---|
| 30 | self.nb = wx.Notebook(self) |
---|
[7691125] | 31 | self.sizer = wx.BoxSizer() |
---|
| 32 | self.sizer.Add(self.nb, 1, wx.EXPAND) |
---|
[d89f09b] | 33 | #Creating an initial page for simultaneous fitting |
---|
| 34 | from simfitpage import SimultaneousFitPage |
---|
| 35 | self.sim_page = SimultaneousFitPage(self.nb, -1) |
---|
| 36 | |
---|
| 37 | #self.fit_panel.add_page(self.sim_page,"Simultaneous Fit") |
---|
| 38 | self.nb.AddPage(self.sim_page,"Simultaneous Fit") |
---|
| 39 | |
---|
| 40 | #dictionary of miodel {model class name, model class} |
---|
| 41 | self.model_list_box={} |
---|
| 42 | # save the title of the last page tab added |
---|
[1b07935d] | 43 | self.fit_page_name=None |
---|
[060b857] | 44 | self.draw_model_name=None |
---|
[f39511b] | 45 | #model page info |
---|
| 46 | self.model_page_number=None |
---|
| 47 | self.page_name=None |
---|
| 48 | self.model_page=None |
---|
| 49 | #updating the panel |
---|
[d89f09b] | 50 | self.nb.Update() |
---|
| 51 | self.SetSizer(self.sizer) |
---|
| 52 | self.sizer.Fit(self) |
---|
| 53 | self.Center() |
---|
| 54 | |
---|
[7691125] | 55 | |
---|
[d89f09b] | 56 | |
---|
| 57 | def set_manager(self, manager): |
---|
| 58 | """ |
---|
| 59 | set panel manager |
---|
| 60 | @param manager: instance of plugin fitting |
---|
| 61 | """ |
---|
| 62 | self.manager = manager |
---|
| 63 | self.sim_page.set_manager(manager) |
---|
| 64 | |
---|
| 65 | def set_owner(self,owner): |
---|
| 66 | """ |
---|
| 67 | set and owner for fitpanel |
---|
| 68 | @param owner: the class responsible of plotting |
---|
| 69 | """ |
---|
| 70 | self.event_owner=owner |
---|
| 71 | |
---|
| 72 | |
---|
[bcd6d51] | 73 | def add_fit_page( self,data ): |
---|
[d89f09b] | 74 | """ |
---|
| 75 | Add a fitting page on the notebook contained by fitpanel |
---|
| 76 | @param panel: contains in the page to add |
---|
| 77 | @param name: title of the page tab |
---|
| 78 | @return panel : page just added for futher used. is used by fitting module |
---|
| 79 | """ |
---|
[bcd6d51] | 80 | try: |
---|
[55e13ab] | 81 | name = data.name # item in Data1D |
---|
[bcd6d51] | 82 | except: |
---|
| 83 | name = 'Fit' |
---|
| 84 | if self.fit_page_name != name: |
---|
[693ab78] | 85 | if data.__class__.__name__=='Data2D': |
---|
[bcd6d51] | 86 | from fitpage2D import FitPage2D |
---|
[9d31a8b] | 87 | panel = FitPage2D(self.nb,data, -1) |
---|
[bcd6d51] | 88 | else: |
---|
[b5847bd8] | 89 | |
---|
[bcd6d51] | 90 | from fitpage1D import FitPage1D |
---|
[9d31a8b] | 91 | panel = FitPage1D(self.nb,data, -1) |
---|
[b5847bd8] | 92 | |
---|
[d89f09b] | 93 | panel.set_manager(self.manager) |
---|
| 94 | panel.set_owner(self.event_owner) |
---|
[9d31a8b] | 95 | |
---|
[bcd6d51] | 96 | self.nb.AddPage(page=panel,text=name,select=True) |
---|
[d89f09b] | 97 | panel.populate_box( self.model_list_box) |
---|
[bcd6d51] | 98 | self.fit_page_name = name |
---|
[d89f09b] | 99 | return panel |
---|
[1c66bc5] | 100 | |
---|
[f39511b] | 101 | def _help_add_model_page(self,model,description,page_title): |
---|
| 102 | from modelpage import ModelPage |
---|
| 103 | panel = ModelPage(self.nb,model, -1) |
---|
| 104 | panel.set_manager(self.manager) |
---|
| 105 | panel.set_owner(self.event_owner) |
---|
| 106 | self.nb.AddPage(page=panel,text=page_title,select=True) |
---|
| 107 | panel.populate_box( self.model_list_box) |
---|
| 108 | self.draw_model_name=page_title |
---|
| 109 | self.model_page_number=self.nb.GetSelection() |
---|
| 110 | self.model_page=self.nb.GetPage(self.nb.GetSelection()) |
---|
| 111 | |
---|
[1c66bc5] | 112 | |
---|
[49b7efa] | 113 | def add_model_page(self,model,description,page_title): |
---|
[1c66bc5] | 114 | """ |
---|
| 115 | Add a model page only one to display any model selected from the menu or the page combo box. |
---|
| 116 | when this page is closed than the user will be able to open a new one |
---|
| 117 | @param model: the model for which paramters will be changed |
---|
| 118 | @param page_title: the name of the page |
---|
| 119 | """ |
---|
[f39511b] | 120 | if self.draw_model_name ==None: |
---|
| 121 | # or self.draw_model_name !=page_title: |
---|
| 122 | #print "removing the prevois model page ",self.model_page, self.model_page_number |
---|
| 123 | #self.onClose(self.model_page, self.model_page_number) |
---|
| 124 | self._help_add_model_page(model,description,page_title) |
---|
| 125 | else: |
---|
| 126 | if self.draw_model_name !=page_title: |
---|
| 127 | self.onClose(self.model_page, self.model_page_number) |
---|
| 128 | #print "removing the prevois model page ",self.model_page, self.model_page_number |
---|
| 129 | self._help_add_model_page(model,description,page_title) |
---|
| 130 | """ |
---|
| 131 | if self.draw_model_name ==None : |
---|
| 132 | |
---|
[1b07935d] | 133 | from modelpage import ModelPage |
---|
[2dbb681] | 134 | panel = ModelPage(self.nb,model, -1) |
---|
[1b07935d] | 135 | panel.set_manager(self.manager) |
---|
| 136 | panel.set_owner(self.event_owner) |
---|
| 137 | self.nb.AddPage(page=panel,text=page_title,select=True) |
---|
| 138 | panel.populate_box( self.model_list_box) |
---|
[060b857] | 139 | self.draw_model_name=page_title |
---|
[f39511b] | 140 | self.model_page_number = self.nb.GetPage(self.nb.GetSelection()) |
---|
| 141 | print "model page",self.model_page_number,self.nb.GetSelection() |
---|
[060b857] | 142 | else: |
---|
| 143 | for i in range(self.nb.GetPageCount()): |
---|
| 144 | if self.nb.GetPageText(i)==self.page_name: |
---|
| 145 | page=self.nb.GetPage(i) |
---|
[49b7efa] | 146 | page.set_page(model,description) |
---|
[060b857] | 147 | break |
---|
[f39511b] | 148 | """ |
---|
[060b857] | 149 | |
---|
[1b07935d] | 150 | |
---|
[d89f09b] | 151 | def get_notebook(self): |
---|
| 152 | """ |
---|
| 153 | @return self.nb: return its own notebook mostly used by fitting module |
---|
| 154 | """ |
---|
| 155 | return self.nb |
---|
| 156 | |
---|
| 157 | def get_page(self, n): |
---|
| 158 | """ |
---|
| 159 | @return page at position n |
---|
| 160 | @param n: page number |
---|
| 161 | """ |
---|
| 162 | return self.nb.GetPage(n) |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | def get_page_count(self): |
---|
| 166 | """ @return number total of pages contained in notebook""" |
---|
| 167 | return self.nb.GetPageCount() |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | def get_current_page(self): |
---|
| 171 | """ |
---|
| 172 | @return the current page selected |
---|
| 173 | """ |
---|
| 174 | return self.nb.GetCurrentPage() |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | def get_selected_page(self): |
---|
| 178 | """ @return the page just selected by the user """ |
---|
| 179 | return self.nb.GetPage(self.nb.GetSelection()) |
---|
| 180 | |
---|
[f39511b] | 181 | def onClose(self, page=None,page_number=None): |
---|
[d89f09b] | 182 | """ |
---|
| 183 | close the current page except the simpage. remove each check box link to the model |
---|
| 184 | selected on that page. remove its reference into page_finder (fitting module) |
---|
| 185 | """ |
---|
[f39511b] | 186 | if page!=None and page_number!=None: |
---|
| 187 | page.Destroy() |
---|
| 188 | self.nb.RemovePage(page_number) |
---|
| 189 | self.model_page_number=None |
---|
| 190 | self.model_page=None |
---|
| 191 | return |
---|
[2dbb681] | 192 | try: |
---|
| 193 | sim_page = self.nb.GetPage(0) |
---|
| 194 | selected_page = self.nb.GetPage(self.nb.GetSelection()) |
---|
[d89f09b] | 195 | |
---|
[2dbb681] | 196 | if sim_page != selected_page: |
---|
| 197 | # remove the check box link to the model name of this page (selected_page) |
---|
| 198 | sim_page.remove_model(selected_page) |
---|
| 199 | #remove that page from page_finder of fitting module |
---|
| 200 | page_finder=self.manager.get_page_finder() |
---|
| 201 | for page, value in page_finder.iteritems(): |
---|
| 202 | if page==selected_page: |
---|
| 203 | del page_finder[page] |
---|
| 204 | break |
---|
| 205 | #Delete the page from notebook |
---|
| 206 | page_number = self.nb.GetSelection() |
---|
| 207 | if self.nb.GetPageText(page_number)== self.page_name: |
---|
| 208 | self.draw_model_name=None |
---|
| 209 | |
---|
| 210 | selected_page.Destroy() |
---|
| 211 | self.nb.RemovePage(page_number) |
---|
| 212 | #self.name=None |
---|
| 213 | self.fit_page_name=None |
---|
| 214 | except: |
---|
| 215 | raise |
---|
[f39511b] | 216 | #print "fitpanel", self.draw_model_name |
---|
[55e13ab] | 217 | |
---|
[d89f09b] | 218 | def set_model_list(self,dict): |
---|
| 219 | """ |
---|
| 220 | copy a dictionary of model into its own dictionary |
---|
| 221 | @param dict: dictionnary made of model name as key and model class |
---|
| 222 | as value |
---|
| 223 | """ |
---|
| 224 | self.model_list_box = dict |
---|
| 225 | |
---|