[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 |
---|
| 8 | |
---|
| 9 | |
---|
[26bf293] | 10 | class FitPanel(wx.aui.AuiNotebook): |
---|
| 11 | #class FitPanel(wx.aui.AuiNotebook,wx.panel): |
---|
[d89f09b] | 12 | """ |
---|
| 13 | FitPanel class contains fields allowing to fit models and data |
---|
| 14 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 15 | on fit Panel window. |
---|
| 16 | |
---|
| 17 | """ |
---|
| 18 | ## Internal name for the AUI manager |
---|
| 19 | window_name = "Fit panel" |
---|
| 20 | ## Title to appear on top of the window |
---|
| 21 | window_caption = "Fit Panel " |
---|
[2139c3f] | 22 | CENTER_PANE = True |
---|
[d89f09b] | 23 | def __init__(self, parent, *args, **kwargs): |
---|
[26bf293] | 24 | |
---|
[94999eb] | 25 | #wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS ) |
---|
| 26 | wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE ) |
---|
| 27 | |
---|
[26bf293] | 28 | |
---|
[d89f09b] | 29 | self.manager=None |
---|
| 30 | self.parent=parent |
---|
| 31 | self.event_owner=None |
---|
[26bf293] | 32 | |
---|
| 33 | pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE |
---|
| 34 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage) |
---|
[94999eb] | 35 | #Creating the default page --welcomed page |
---|
| 36 | from sans.guiframe.welcome_panel import PanelAbout |
---|
| 37 | self.about_page = PanelAbout(self, -1) |
---|
| 38 | self.AddPage(self.about_page,"welcome!") |
---|
| 39 | #self.about_page.Disable() |
---|
| 40 | #Creating a page for simultaneous fitting |
---|
[d89f09b] | 41 | from simfitpage import SimultaneousFitPage |
---|
[26bf293] | 42 | self.sim_page = SimultaneousFitPage(self, -1) |
---|
| 43 | self.AddPage(self.sim_page,"Simultaneous Fit") |
---|
[d89f09b] | 44 | |
---|
[94999eb] | 45 | |
---|
[26bf293] | 46 | |
---|
[d89f09b] | 47 | |
---|
| 48 | #dictionary of miodel {model class name, model class} |
---|
| 49 | self.model_list_box={} |
---|
| 50 | # save the title of the last page tab added |
---|
[1b07935d] | 51 | self.fit_page_name=None |
---|
[060b857] | 52 | self.draw_model_name=None |
---|
[f39511b] | 53 | #model page info |
---|
| 54 | self.model_page_number=None |
---|
| 55 | self.page_name=None |
---|
| 56 | self.model_page=None |
---|
[6bcdad1] | 57 | # increment number for model name |
---|
| 58 | self.count=0 |
---|
[f39511b] | 59 | #updating the panel |
---|
[26bf293] | 60 | self.Update() |
---|
[d89f09b] | 61 | self.Center() |
---|
[26bf293] | 62 | def onClosePage(self, event): |
---|
| 63 | self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) |
---|
| 64 | print "went here",self.get_current_page(), self.GetPage(0) |
---|
| 65 | #event.Skip() |
---|
| 66 | if self.GetPageCount() <= 2: |
---|
| 67 | print "wente here" |
---|
| 68 | |
---|
| 69 | # Prevent last tab from being closed |
---|
| 70 | self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
[7691125] | 75 | |
---|
[d89f09b] | 76 | |
---|
| 77 | def set_manager(self, manager): |
---|
| 78 | """ |
---|
| 79 | set panel manager |
---|
| 80 | @param manager: instance of plugin fitting |
---|
| 81 | """ |
---|
| 82 | self.manager = manager |
---|
| 83 | self.sim_page.set_manager(manager) |
---|
| 84 | |
---|
| 85 | def set_owner(self,owner): |
---|
| 86 | """ |
---|
| 87 | set and owner for fitpanel |
---|
| 88 | @param owner: the class responsible of plotting |
---|
| 89 | """ |
---|
| 90 | self.event_owner=owner |
---|
| 91 | |
---|
| 92 | |
---|
[bcd6d51] | 93 | def add_fit_page( self,data ): |
---|
[d89f09b] | 94 | """ |
---|
| 95 | Add a fitting page on the notebook contained by fitpanel |
---|
| 96 | @param panel: contains in the page to add |
---|
| 97 | @param name: title of the page tab |
---|
| 98 | @return panel : page just added for futher used. is used by fitting module |
---|
| 99 | """ |
---|
[bcd6d51] | 100 | try: |
---|
[55e13ab] | 101 | name = data.name # item in Data1D |
---|
[bcd6d51] | 102 | except: |
---|
| 103 | name = 'Fit' |
---|
| 104 | if self.fit_page_name != name: |
---|
[6bcdad1] | 105 | self.count +=1 |
---|
[26bf293] | 106 | |
---|
[6b44403] | 107 | """ |
---|
[693ab78] | 108 | if data.__class__.__name__=='Data2D': |
---|
[bcd6d51] | 109 | from fitpage2D import FitPage2D |
---|
[26bf293] | 110 | panel = FitPage2D(self,data, -1) |
---|
[6bcdad1] | 111 | |
---|
[bcd6d51] | 112 | else: |
---|
[6b44403] | 113 | """ |
---|
[94999eb] | 114 | #self.about_page.Disable() |
---|
[6b44403] | 115 | from fitpage1D import FitPage1D |
---|
| 116 | panel = FitPage1D(self,data, -1) |
---|
[6bcdad1] | 117 | m_name= "M"+str(self.count) |
---|
[d89f09b] | 118 | panel.set_manager(self.manager) |
---|
| 119 | panel.set_owner(self.event_owner) |
---|
[9d31a8b] | 120 | |
---|
[26bf293] | 121 | self.AddPage(page=panel,caption=name,select=True) |
---|
[d89f09b] | 122 | panel.populate_box( self.model_list_box) |
---|
[bcd6d51] | 123 | self.fit_page_name = name |
---|
[6bcdad1] | 124 | return panel,m_name |
---|
[1c66bc5] | 125 | |
---|
[3f1af74] | 126 | def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50): |
---|
| 127 | """ |
---|
| 128 | #TODO: fill in description |
---|
| 129 | |
---|
| 130 | @param qmin: mimimum Q |
---|
| 131 | @param qmax: maximum Q |
---|
| 132 | @param npts: number of Q points |
---|
| 133 | """ |
---|
[f39511b] | 134 | from modelpage import ModelPage |
---|
[26bf293] | 135 | print "fitpanel model", model |
---|
| 136 | panel = ModelPage(self,model,page_title, -1) |
---|
[f39511b] | 137 | panel.set_manager(self.manager) |
---|
| 138 | panel.set_owner(self.event_owner) |
---|
[26bf293] | 139 | self.AddPage(page=panel,caption="Model",select=True) |
---|
[f39511b] | 140 | panel.populate_box( self.model_list_box) |
---|
| 141 | self.draw_model_name=page_title |
---|
[26bf293] | 142 | self.model_page_number=self.GetSelection() |
---|
| 143 | self.model_page=self.GetPage(self.GetSelection()) |
---|
[f39511b] | 144 | |
---|
[1c66bc5] | 145 | |
---|
[3f1af74] | 146 | # Set the range used to plot models |
---|
| 147 | self.model_page.set_range(qmin, qmax, npts) |
---|
| 148 | |
---|
[3dc83be] | 149 | # We just created a model page, we are ready to plot the model |
---|
[32d802f] | 150 | #self.manager.draw_model(model, model.name) |
---|
| 151 | #FOR PLUGIN for somereason model.name is = BASEcomponent |
---|
| 152 | self.manager.draw_model(model, page_title) |
---|
[3f1af74] | 153 | |
---|
[3dc83be] | 154 | |
---|
| 155 | def add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False): |
---|
[1c66bc5] | 156 | """ |
---|
| 157 | Add a model page only one to display any model selected from the menu or the page combo box. |
---|
| 158 | when this page is closed than the user will be able to open a new one |
---|
[3f1af74] | 159 | |
---|
[1c66bc5] | 160 | @param model: the model for which paramters will be changed |
---|
| 161 | @param page_title: the name of the page |
---|
[3f1af74] | 162 | @param description: [Coder: fill your description!] |
---|
| 163 | @param page_title: [Coder: fill your description!] |
---|
| 164 | @param qmin: mimimum Q |
---|
| 165 | @param qmax: maximum Q |
---|
| 166 | @param npts: number of Q points |
---|
[1c66bc5] | 167 | """ |
---|
[f39511b] | 168 | if self.draw_model_name ==None: |
---|
[3f1af74] | 169 | self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts) |
---|
[3dc83be] | 170 | elif topmenu==True: |
---|
[32d802f] | 171 | self.model_page.select_model(model, page_title) |
---|
[1b07935d] | 172 | |
---|
[d89f09b] | 173 | def get_current_page(self): |
---|
| 174 | """ |
---|
| 175 | @return the current page selected |
---|
| 176 | """ |
---|
[26bf293] | 177 | #return self.nb.GetCurrentPage() |
---|
| 178 | return self.GetPage(self.GetSelection() ) |
---|
| 179 | |
---|
[6bcdad1] | 180 | |
---|
[26bf293] | 181 | def old_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 | """ |
---|
[47d10a2] | 186 | print "model page", page_number, page |
---|
[f39511b] | 187 | if page!=None and page_number!=None: |
---|
[47d10a2] | 188 | |
---|
[f39511b] | 189 | self.nb.RemovePage(page_number) |
---|
[47d10a2] | 190 | page.Destroy() |
---|
[f39511b] | 191 | self.model_page_number=None |
---|
| 192 | self.model_page=None |
---|
[47d10a2] | 193 | self.draw_model_name=None |
---|
[f39511b] | 194 | return |
---|
[2dbb681] | 195 | try: |
---|
| 196 | sim_page = self.nb.GetPage(0) |
---|
| 197 | selected_page = self.nb.GetPage(self.nb.GetSelection()) |
---|
[d89f09b] | 198 | |
---|
[2dbb681] | 199 | if sim_page != selected_page: |
---|
| 200 | # remove the check box link to the model name of this page (selected_page) |
---|
| 201 | sim_page.remove_model(selected_page) |
---|
| 202 | #remove that page from page_finder of fitting module |
---|
| 203 | page_finder=self.manager.get_page_finder() |
---|
| 204 | for page, value in page_finder.iteritems(): |
---|
| 205 | if page==selected_page: |
---|
| 206 | del page_finder[page] |
---|
| 207 | break |
---|
| 208 | #Delete the page from notebook |
---|
| 209 | page_number = self.nb.GetSelection() |
---|
| 210 | if self.nb.GetPageText(page_number)== self.page_name: |
---|
| 211 | self.draw_model_name=None |
---|
[47d10a2] | 212 | if page_number == 1: |
---|
| 213 | self.model_page=None |
---|
| 214 | self.draw_model_name=None |
---|
[2dbb681] | 215 | selected_page.Destroy() |
---|
| 216 | self.nb.RemovePage(page_number) |
---|
[6bcdad1] | 217 | #self.count =self.count -1 |
---|
[2dbb681] | 218 | self.fit_page_name=None |
---|
| 219 | except: |
---|
| 220 | raise |
---|
[f39511b] | 221 | #print "fitpanel", self.draw_model_name |
---|
[55e13ab] | 222 | |
---|
[d89f09b] | 223 | def set_model_list(self,dict): |
---|
| 224 | """ |
---|
| 225 | copy a dictionary of model into its own dictionary |
---|
| 226 | @param dict: dictionnary made of model name as key and model class |
---|
| 227 | as value |
---|
| 228 | """ |
---|
| 229 | self.model_list_box = dict |
---|
| 230 | |
---|