[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 |
---|
[6bcdad1] | 49 | # increment number for model name |
---|
| 50 | self.count=0 |
---|
[f39511b] | 51 | #updating the panel |
---|
[d89f09b] | 52 | self.nb.Update() |
---|
| 53 | self.SetSizer(self.sizer) |
---|
| 54 | self.sizer.Fit(self) |
---|
| 55 | self.Center() |
---|
| 56 | |
---|
[7691125] | 57 | |
---|
[d89f09b] | 58 | |
---|
| 59 | def set_manager(self, manager): |
---|
| 60 | """ |
---|
| 61 | set panel manager |
---|
| 62 | @param manager: instance of plugin fitting |
---|
| 63 | """ |
---|
| 64 | self.manager = manager |
---|
| 65 | self.sim_page.set_manager(manager) |
---|
| 66 | |
---|
| 67 | def set_owner(self,owner): |
---|
| 68 | """ |
---|
| 69 | set and owner for fitpanel |
---|
| 70 | @param owner: the class responsible of plotting |
---|
| 71 | """ |
---|
| 72 | self.event_owner=owner |
---|
| 73 | |
---|
| 74 | |
---|
[bcd6d51] | 75 | def add_fit_page( self,data ): |
---|
[d89f09b] | 76 | """ |
---|
| 77 | Add a fitting page on the notebook contained by fitpanel |
---|
| 78 | @param panel: contains in the page to add |
---|
| 79 | @param name: title of the page tab |
---|
| 80 | @return panel : page just added for futher used. is used by fitting module |
---|
| 81 | """ |
---|
[bcd6d51] | 82 | try: |
---|
[55e13ab] | 83 | name = data.name # item in Data1D |
---|
[bcd6d51] | 84 | except: |
---|
| 85 | name = 'Fit' |
---|
| 86 | if self.fit_page_name != name: |
---|
[6bcdad1] | 87 | self.count +=1 |
---|
[693ab78] | 88 | if data.__class__.__name__=='Data2D': |
---|
[bcd6d51] | 89 | from fitpage2D import FitPage2D |
---|
[9d31a8b] | 90 | panel = FitPage2D(self.nb,data, -1) |
---|
[6bcdad1] | 91 | |
---|
[bcd6d51] | 92 | else: |
---|
[b5847bd8] | 93 | |
---|
[bcd6d51] | 94 | from fitpage1D import FitPage1D |
---|
[9d31a8b] | 95 | panel = FitPage1D(self.nb,data, -1) |
---|
[6bcdad1] | 96 | m_name= "M"+str(self.count) |
---|
[d89f09b] | 97 | panel.set_manager(self.manager) |
---|
| 98 | panel.set_owner(self.event_owner) |
---|
[9d31a8b] | 99 | |
---|
[bcd6d51] | 100 | self.nb.AddPage(page=panel,text=name,select=True) |
---|
[d89f09b] | 101 | panel.populate_box( self.model_list_box) |
---|
[bcd6d51] | 102 | self.fit_page_name = name |
---|
[6bcdad1] | 103 | return panel,m_name |
---|
[1c66bc5] | 104 | |
---|
[f39511b] | 105 | def _help_add_model_page(self,model,description,page_title): |
---|
| 106 | from modelpage import ModelPage |
---|
[86c1832] | 107 | panel = ModelPage(self.nb,model,page_title, -1) |
---|
[f39511b] | 108 | panel.set_manager(self.manager) |
---|
| 109 | panel.set_owner(self.event_owner) |
---|
| 110 | self.nb.AddPage(page=panel,text=page_title,select=True) |
---|
| 111 | panel.populate_box( self.model_list_box) |
---|
| 112 | self.draw_model_name=page_title |
---|
| 113 | self.model_page_number=self.nb.GetSelection() |
---|
| 114 | self.model_page=self.nb.GetPage(self.nb.GetSelection()) |
---|
| 115 | |
---|
[1c66bc5] | 116 | |
---|
[49b7efa] | 117 | def add_model_page(self,model,description,page_title): |
---|
[1c66bc5] | 118 | """ |
---|
| 119 | Add a model page only one to display any model selected from the menu or the page combo box. |
---|
| 120 | when this page is closed than the user will be able to open a new one |
---|
| 121 | @param model: the model for which paramters will be changed |
---|
| 122 | @param page_title: the name of the page |
---|
| 123 | """ |
---|
[d15c0202] | 124 | #print "page_title fitpanel", page_title |
---|
[f39511b] | 125 | if self.draw_model_name ==None: |
---|
[6bcdad1] | 126 | |
---|
[f39511b] | 127 | self._help_add_model_page(model,description,page_title) |
---|
| 128 | else: |
---|
| 129 | if self.draw_model_name !=page_title: |
---|
| 130 | self.onClose(self.model_page, self.model_page_number) |
---|
| 131 | self._help_add_model_page(model,description,page_title) |
---|
[6bcdad1] | 132 | |
---|
[1b07935d] | 133 | |
---|
[d89f09b] | 134 | def get_notebook(self): |
---|
| 135 | """ |
---|
| 136 | @return self.nb: return its own notebook mostly used by fitting module |
---|
| 137 | """ |
---|
| 138 | return self.nb |
---|
| 139 | |
---|
| 140 | def get_page(self, n): |
---|
| 141 | """ |
---|
| 142 | @return page at position n |
---|
| 143 | @param n: page number |
---|
| 144 | """ |
---|
| 145 | return self.nb.GetPage(n) |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | def get_page_count(self): |
---|
| 149 | """ @return number total of pages contained in notebook""" |
---|
| 150 | return self.nb.GetPageCount() |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | def get_current_page(self): |
---|
| 154 | """ |
---|
| 155 | @return the current page selected |
---|
| 156 | """ |
---|
| 157 | return self.nb.GetCurrentPage() |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | def get_selected_page(self): |
---|
| 161 | """ @return the page just selected by the user """ |
---|
| 162 | return self.nb.GetPage(self.nb.GetSelection()) |
---|
| 163 | |
---|
[6bcdad1] | 164 | |
---|
| 165 | def get_page_number(self): |
---|
| 166 | return self.nb.GetSelection() |
---|
| 167 | |
---|
[f39511b] | 168 | def onClose(self, page=None,page_number=None): |
---|
[d89f09b] | 169 | """ |
---|
| 170 | close the current page except the simpage. remove each check box link to the model |
---|
| 171 | selected on that page. remove its reference into page_finder (fitting module) |
---|
| 172 | """ |
---|
[f39511b] | 173 | if page!=None and page_number!=None: |
---|
| 174 | page.Destroy() |
---|
| 175 | self.nb.RemovePage(page_number) |
---|
| 176 | self.model_page_number=None |
---|
| 177 | self.model_page=None |
---|
| 178 | return |
---|
[2dbb681] | 179 | try: |
---|
| 180 | sim_page = self.nb.GetPage(0) |
---|
| 181 | selected_page = self.nb.GetPage(self.nb.GetSelection()) |
---|
[d89f09b] | 182 | |
---|
[2dbb681] | 183 | if sim_page != selected_page: |
---|
| 184 | # remove the check box link to the model name of this page (selected_page) |
---|
| 185 | sim_page.remove_model(selected_page) |
---|
| 186 | #remove that page from page_finder of fitting module |
---|
| 187 | page_finder=self.manager.get_page_finder() |
---|
| 188 | for page, value in page_finder.iteritems(): |
---|
| 189 | if page==selected_page: |
---|
| 190 | del page_finder[page] |
---|
| 191 | break |
---|
| 192 | #Delete the page from notebook |
---|
| 193 | page_number = self.nb.GetSelection() |
---|
| 194 | if self.nb.GetPageText(page_number)== self.page_name: |
---|
| 195 | self.draw_model_name=None |
---|
[6bcdad1] | 196 | |
---|
[2dbb681] | 197 | selected_page.Destroy() |
---|
| 198 | self.nb.RemovePage(page_number) |
---|
[6bcdad1] | 199 | #self.count =self.count -1 |
---|
[2dbb681] | 200 | self.fit_page_name=None |
---|
| 201 | except: |
---|
| 202 | raise |
---|
[f39511b] | 203 | #print "fitpanel", self.draw_model_name |
---|
[55e13ab] | 204 | |
---|
[d89f09b] | 205 | def set_model_list(self,dict): |
---|
| 206 | """ |
---|
| 207 | copy a dictionary of model into its own dictionary |
---|
| 208 | @param dict: dictionnary made of model name as key and model class |
---|
| 209 | as value |
---|
| 210 | """ |
---|
| 211 | self.model_list_box = dict |
---|
| 212 | |
---|