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