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