[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 | |
---|
[0b92f4f4] | 9 | (FitPageEvent, EVT_FIT_PAGE) = wx.lib.newevent.NewEvent() |
---|
[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 | |
---|
[0b92f4f4] | 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 ) |
---|
[94999eb] | 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 |
---|
[2a8fac1] | 42 | self.sim_page = SimultaneousFitPage(self, id=-1) |
---|
[26bf293] | 43 | self.AddPage(self.sim_page,"Simultaneous Fit") |
---|
[d89f09b] | 44 | |
---|
[2a8fac1] | 45 | self._mgr = self.GetAuiManager() |
---|
[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 |
---|
[1fc7411] | 51 | self.fit_page_name=[] |
---|
[060b857] | 52 | self.draw_model_name=None |
---|
[f39511b] | 53 | #model page info |
---|
| 54 | self.model_page_number=None |
---|
[10c43a5] | 55 | |
---|
[f39511b] | 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() |
---|
[2a8fac1] | 62 | |
---|
| 63 | |
---|
[26bf293] | 64 | def onClosePage(self, event): |
---|
| 65 | self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) |
---|
[888e62c] | 66 | #print "went here",self.get_current_page(), self.GetPage(0) |
---|
[26bf293] | 67 | #event.Skip() |
---|
| 68 | if self.GetPageCount() <= 2: |
---|
[888e62c] | 69 | #print "wente here" |
---|
[26bf293] | 70 | |
---|
| 71 | # Prevent last tab from being closed |
---|
| 72 | self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|
[7691125] | 77 | |
---|
[d89f09b] | 78 | |
---|
| 79 | def set_manager(self, manager): |
---|
| 80 | """ |
---|
| 81 | set panel manager |
---|
| 82 | @param manager: instance of plugin fitting |
---|
| 83 | """ |
---|
| 84 | self.manager = manager |
---|
| 85 | self.sim_page.set_manager(manager) |
---|
| 86 | |
---|
| 87 | def set_owner(self,owner): |
---|
| 88 | """ |
---|
| 89 | set and owner for fitpanel |
---|
| 90 | @param owner: the class responsible of plotting |
---|
| 91 | """ |
---|
| 92 | self.event_owner=owner |
---|
| 93 | |
---|
| 94 | |
---|
[bcd6d51] | 95 | def add_fit_page( self,data ): |
---|
[d89f09b] | 96 | """ |
---|
| 97 | Add a fitting page on the notebook contained by fitpanel |
---|
| 98 | @param panel: contains in the page to add |
---|
| 99 | @param name: title of the page tab |
---|
| 100 | @return panel : page just added for futher used. is used by fitting module |
---|
| 101 | """ |
---|
[bcd6d51] | 102 | try: |
---|
[55e13ab] | 103 | name = data.name # item in Data1D |
---|
[bcd6d51] | 104 | except: |
---|
| 105 | name = 'Fit' |
---|
[6e659ae8] | 106 | |
---|
[3e1a859] | 107 | #if self.fit_page_name != name and self.draw_model_name !=name: |
---|
[6e659ae8] | 108 | if not name in self.fit_page_name : |
---|
[94999eb] | 109 | #self.about_page.Disable() |
---|
[6b44403] | 110 | from fitpage1D import FitPage1D |
---|
| 111 | panel = FitPage1D(self,data, -1) |
---|
[10c43a5] | 112 | panel.name=name |
---|
[ef8b580] | 113 | #m_name= "M"+str(self.count) |
---|
[d89f09b] | 114 | panel.set_manager(self.manager) |
---|
| 115 | panel.set_owner(self.event_owner) |
---|
[9d31a8b] | 116 | |
---|
[26bf293] | 117 | self.AddPage(page=panel,caption=name,select=True) |
---|
[d89f09b] | 118 | panel.populate_box( self.model_list_box) |
---|
[1fc7411] | 119 | self.fit_page_name.append(name) |
---|
| 120 | |
---|
[ef8b580] | 121 | return panel #,m_name |
---|
[fee6059] | 122 | else: |
---|
[ef8b580] | 123 | return None #, None |
---|
[1c66bc5] | 124 | |
---|
[3f1af74] | 125 | def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50): |
---|
| 126 | """ |
---|
| 127 | #TODO: fill in description |
---|
| 128 | |
---|
| 129 | @param qmin: mimimum Q |
---|
| 130 | @param qmax: maximum Q |
---|
| 131 | @param npts: number of Q points |
---|
| 132 | """ |
---|
[f39511b] | 133 | from modelpage import ModelPage |
---|
[888e62c] | 134 | #print "fitpanel model", model |
---|
[26bf293] | 135 | panel = ModelPage(self,model,page_title, -1) |
---|
[f39511b] | 136 | panel.set_manager(self.manager) |
---|
| 137 | panel.set_owner(self.event_owner) |
---|
[26bf293] | 138 | self.AddPage(page=panel,caption="Model",select=True) |
---|
[f39511b] | 139 | panel.populate_box( self.model_list_box) |
---|
[ef8b580] | 140 | panel.name = page_title |
---|
[f39511b] | 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 | """ |
---|
[10c43a5] | 168 | print "self.draw_model_name none",self.draw_model_name |
---|
[ef8b580] | 169 | if topmenu==True: |
---|
| 170 | if self.draw_model_name ==None: |
---|
| 171 | print "self.draw_model_name none" |
---|
| 172 | self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts) |
---|
| 173 | else: |
---|
| 174 | #self.model_page.name=page_title |
---|
| 175 | #self.draw_model_name=page_title |
---|
| 176 | #print "wnent here self.draw_model_name ",self.draw_model_name,self.model_page.name,self.model_page |
---|
| 177 | |
---|
| 178 | self.model_page.select_model(model, page_title) |
---|
[10c43a5] | 179 | |
---|
[d89f09b] | 180 | def get_current_page(self): |
---|
| 181 | """ |
---|
| 182 | @return the current page selected |
---|
| 183 | """ |
---|
[26bf293] | 184 | #return self.nb.GetCurrentPage() |
---|
| 185 | return self.GetPage(self.GetSelection() ) |
---|
| 186 | |
---|
[6bcdad1] | 187 | |
---|
[10c43a5] | 188 | def onClose(self, page=None,page_number=None): |
---|
[d89f09b] | 189 | """ |
---|
| 190 | close the current page except the simpage. remove each check box link to the model |
---|
| 191 | selected on that page. remove its reference into page_finder (fitting module) |
---|
| 192 | """ |
---|
[10c43a5] | 193 | print "model page", page_number, page, self.draw_model_name |
---|
[f39511b] | 194 | if page!=None and page_number!=None: |
---|
[10c43a5] | 195 | i=self.DeletePage(page_number) |
---|
| 196 | #self.nb.RemovePage(page_number) |
---|
| 197 | #page.Destroy() |
---|
[f39511b] | 198 | self.model_page_number=None |
---|
| 199 | self.model_page=None |
---|
[47d10a2] | 200 | self.draw_model_name=None |
---|
[10c43a5] | 201 | print"self.draw_model_name",self.draw_model_name |
---|
[f39511b] | 202 | return |
---|
[2dbb681] | 203 | try: |
---|
[10c43a5] | 204 | sim_page = self.GetPage(1) |
---|
| 205 | selected_page = self.GetPage(self.GetSelection()) |
---|
[1fc7411] | 206 | #print "sim_page ",sim_page ,selected_page |
---|
[2dbb681] | 207 | if sim_page != selected_page: |
---|
[1fc7411] | 208 | #print "sim_page ",sim_page ,selected_page |
---|
[2dbb681] | 209 | # remove the check box link to the model name of this page (selected_page) |
---|
| 210 | sim_page.remove_model(selected_page) |
---|
| 211 | #remove that page from page_finder of fitting module |
---|
| 212 | page_finder=self.manager.get_page_finder() |
---|
| 213 | for page, value in page_finder.iteritems(): |
---|
| 214 | if page==selected_page: |
---|
| 215 | del page_finder[page] |
---|
| 216 | break |
---|
| 217 | #Delete the page from notebook |
---|
[10c43a5] | 218 | page_number = self.GetSelection() |
---|
[1fc7411] | 219 | #print "on close",selected_page.name,self.GetPageText(page_number),self.draw_model_name |
---|
| 220 | |
---|
| 221 | if selected_page.name in self.fit_page_name: |
---|
| 222 | self.fit_page_name.remove(selected_page.name) |
---|
| 223 | |
---|
[10c43a5] | 224 | if selected_page.name== self.draw_model_name: |
---|
[1fc7411] | 225 | #print "went here" |
---|
[2dbb681] | 226 | self.draw_model_name=None |
---|
[10c43a5] | 227 | self.model_page=None |
---|
[47d10a2] | 228 | if page_number == 1: |
---|
| 229 | self.model_page=None |
---|
| 230 | self.draw_model_name=None |
---|
[10c43a5] | 231 | #selected_page.Destroy() |
---|
| 232 | #self.RemovePage(page_number) |
---|
| 233 | i=self.DeletePage(page_number) |
---|
[6bcdad1] | 234 | #self.count =self.count -1 |
---|
[1fc7411] | 235 | |
---|
[2dbb681] | 236 | except: |
---|
| 237 | raise |
---|
[f39511b] | 238 | #print "fitpanel", self.draw_model_name |
---|
[55e13ab] | 239 | |
---|
[d89f09b] | 240 | def set_model_list(self,dict): |
---|
| 241 | """ |
---|
| 242 | copy a dictionary of model into its own dictionary |
---|
| 243 | @param dict: dictionnary made of model name as key and model class |
---|
| 244 | as value |
---|
| 245 | """ |
---|
| 246 | self.model_list_box = dict |
---|
| 247 | |
---|