1 | """ |
---|
2 | Calculator Module |
---|
3 | """ |
---|
4 | ################################################################################ |
---|
5 | #This software was developed by the University of Tennessee as part of the |
---|
6 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
7 | #project funded by the US National Science Foundation. |
---|
8 | # |
---|
9 | #See the license text in license.txt |
---|
10 | # |
---|
11 | #copyright 2010, University of Tennessee |
---|
12 | ################################################################################ |
---|
13 | |
---|
14 | import wx |
---|
15 | from sas.sasgui.guiframe.plugin_base import PluginBase |
---|
16 | from sas.sasgui.perspectives.calculator.data_operator import DataOperatorWindow |
---|
17 | from sas.sasgui.perspectives.calculator.data_editor import DataEditorWindow |
---|
18 | from sas.sasgui.perspectives.calculator.kiessig_calculator_panel import KiessigWindow |
---|
19 | from sas.sasgui.perspectives.calculator.sld_panel import SldWindow |
---|
20 | from sas.sasgui.perspectives.calculator.density_panel import DensityWindow |
---|
21 | from sas.sasgui.perspectives.calculator.slit_length_calculator_panel \ |
---|
22 | import SlitLengthCalculatorWindow |
---|
23 | from sas.sasgui.perspectives.calculator.resolution_calculator_panel \ |
---|
24 | import ResolutionWindow |
---|
25 | from sas.sasgui.perspectives.calculator.gen_scatter_panel import SasGenWindow |
---|
26 | from sas.sasgui.perspectives.calculator.image_viewer import ImageView |
---|
27 | from sas.sasgui.perspectives.calculator.pyconsole import PyConsole |
---|
28 | import logging |
---|
29 | |
---|
30 | logger = logging.getLogger(__name__) |
---|
31 | |
---|
32 | class Plugin(PluginBase): |
---|
33 | """ |
---|
34 | This class defines the interface for a Plugin class |
---|
35 | for calculator perspective |
---|
36 | """ |
---|
37 | def __init__(self): |
---|
38 | PluginBase.__init__(self, name="Calculator") |
---|
39 | # Log startup |
---|
40 | logger.info("Calculator plug-in started") |
---|
41 | self.sub_menu = "Tool" |
---|
42 | self.data_edit_frame = None |
---|
43 | # data operator use one frame all the time |
---|
44 | self.data_operator_frame = None |
---|
45 | self.kiessig_frame = None |
---|
46 | self.sld_frame = None |
---|
47 | self.cal_md_frame = None |
---|
48 | self.cal_slit_frame = None |
---|
49 | self.cal_res_frame = None |
---|
50 | self.gen_frame = None |
---|
51 | self.image_view = None |
---|
52 | self.py_frame = None |
---|
53 | |
---|
54 | |
---|
55 | def get_tools(self): |
---|
56 | """ |
---|
57 | Returns a set of menu entries for tools |
---|
58 | """ |
---|
59 | data_oper_help = "Perform arithmetic data operation (+...) " |
---|
60 | data_oper_help += "and combination (|)" |
---|
61 | kiessig_help = "Approximately computes the " |
---|
62 | kiessig_help += "thickness of a shell or the size of " |
---|
63 | kiessig_help += "particles \n from the width of a Kiessig fringe." |
---|
64 | sld_help = "Computes the Scattering Length Density." |
---|
65 | slit_length_help = "Computes the slit length from the beam profile." |
---|
66 | resolution_help = "Approximately estimates the " |
---|
67 | resolution_help += "resolution of Q in 2D based on the SAS " |
---|
68 | resolution_help += "instrumental parameter values." |
---|
69 | mass_volume_help = "Based on the chemical formula, " |
---|
70 | mass_volume_help += "compute the mass density or the molar volume." |
---|
71 | gensas_help = "Generic SAS" |
---|
72 | pyconsole_help = "Python Console." |
---|
73 | imageviewer_help = "Load an image file and display the image." |
---|
74 | #data_editor_help = "Meta Data Editor" |
---|
75 | return [("Data Operation", |
---|
76 | data_oper_help, self.on_data_operation), |
---|
77 | ("SLD Calculator", sld_help, self.on_calculate_sld), |
---|
78 | ("Density/Volume Calculator", mass_volume_help, |
---|
79 | self.on_calculate_dv), |
---|
80 | ("Slit Size Calculator", slit_length_help, |
---|
81 | self.on_calculate_slit_size), |
---|
82 | ("Kiessig Thickness Calculator", |
---|
83 | kiessig_help, self.on_calculate_kiessig), |
---|
84 | ("Q Resolution Estimator", |
---|
85 | resolution_help, self.on_calculate_resoltuion), |
---|
86 | ("Generic Scattering Calculator", |
---|
87 | gensas_help, self.on_gen_model), |
---|
88 | ("Orientation Viewer", "Show 3-D view of oriented shape", self.on_show_orientation), |
---|
89 | ("Python Shell/Editor", pyconsole_help, self.on_python_console), |
---|
90 | ("Image Viewer", imageviewer_help, self.on_image_viewer), ] |
---|
91 | |
---|
92 | def on_edit_data(self, event): |
---|
93 | """ |
---|
94 | Edit meta data |
---|
95 | """ |
---|
96 | if self.data_edit_frame is None: |
---|
97 | self.data_edit_frame = DataEditorWindow(parent=self.parent, |
---|
98 | manager=self, data=[], |
---|
99 | title="Data Editor") |
---|
100 | self.put_icon(self.data_edit_frame) |
---|
101 | else: |
---|
102 | self.data_edit_frame.Show(False) |
---|
103 | self.data_edit_frame.Show(True) |
---|
104 | |
---|
105 | def on_data_operation(self, event): |
---|
106 | """ |
---|
107 | Data operation |
---|
108 | """ |
---|
109 | if self.data_operator_frame is None: |
---|
110 | # Use one frame all the time |
---|
111 | self.data_operator_frame = DataOperatorWindow(parent=self.parent, |
---|
112 | manager=self, |
---|
113 | title="Data Operation") |
---|
114 | self.put_icon(self.data_operator_frame) |
---|
115 | else: |
---|
116 | self.data_operator_frame.Show(False) |
---|
117 | self.data_operator_frame.panel.set_panel_on_focus(None) |
---|
118 | self.data_operator_frame.Show(True) |
---|
119 | |
---|
120 | def on_calculate_kiessig(self, event): |
---|
121 | """ |
---|
122 | Compute the Kiessig thickness |
---|
123 | """ |
---|
124 | if self.kiessig_frame is None: |
---|
125 | frame = KiessigWindow(parent=self.parent, manager=self) |
---|
126 | self.put_icon(frame) |
---|
127 | self.kiessig_frame = frame |
---|
128 | else: |
---|
129 | self.kiessig_frame.Show(False) |
---|
130 | self.kiessig_frame.Show(True) |
---|
131 | |
---|
132 | def on_calculate_sld(self, event): |
---|
133 | """ |
---|
134 | Compute the scattering length density of molecula |
---|
135 | """ |
---|
136 | if self.sld_frame is None: |
---|
137 | frame = SldWindow(parent=self.parent, |
---|
138 | base=self.parent, manager=self) |
---|
139 | self.put_icon(frame) |
---|
140 | self.sld_frame = frame |
---|
141 | else: |
---|
142 | self.sld_frame.Show(False) |
---|
143 | self.sld_frame.Show(True) |
---|
144 | |
---|
145 | def on_calculate_dv(self, event): |
---|
146 | """ |
---|
147 | Compute the mass density or molar voulme |
---|
148 | """ |
---|
149 | if self.cal_md_frame is None: |
---|
150 | frame = DensityWindow(parent=self.parent, |
---|
151 | base=self.parent, manager=self) |
---|
152 | self.put_icon(frame) |
---|
153 | self.cal_md_frame = frame |
---|
154 | else: |
---|
155 | self.cal_md_frame.Show(False) |
---|
156 | self.cal_md_frame.Show(True) |
---|
157 | |
---|
158 | def on_calculate_slit_size(self, event): |
---|
159 | """ |
---|
160 | Compute the slit size a given data |
---|
161 | """ |
---|
162 | if self.cal_slit_frame is None: |
---|
163 | frame = SlitLengthCalculatorWindow(parent=self.parent, manager=self) |
---|
164 | self.put_icon(frame) |
---|
165 | self.cal_slit_frame = frame |
---|
166 | else: |
---|
167 | self.cal_slit_frame.Show(False) |
---|
168 | self.cal_slit_frame.Show(True) |
---|
169 | |
---|
170 | def on_calculate_resoltuion(self, event): |
---|
171 | """ |
---|
172 | Estimate the instrumental resolution |
---|
173 | """ |
---|
174 | if self.cal_res_frame is None: |
---|
175 | frame = ResolutionWindow(parent=self.parent, manager=self) |
---|
176 | self.put_icon(frame) |
---|
177 | self.cal_res_frame = frame |
---|
178 | else: |
---|
179 | self.cal_res_frame.Show(False) |
---|
180 | self.cal_res_frame.Show(True) |
---|
181 | |
---|
182 | def on_gen_model(self, event): |
---|
183 | """ |
---|
184 | On Generic model menu event |
---|
185 | """ |
---|
186 | if self.gen_frame is None: |
---|
187 | frame = SasGenWindow(parent=self.parent, manager=self) |
---|
188 | self.put_icon(frame) |
---|
189 | self.gen_frame = frame |
---|
190 | else: |
---|
191 | self.gen_frame.Show(False) |
---|
192 | self.gen_frame.Show(True) |
---|
193 | |
---|
194 | def on_show_orientation(self, event): |
---|
195 | """ |
---|
196 | Make sasmodels orientation & jitter viewer available |
---|
197 | """ |
---|
198 | from sasmodels.jitter import run |
---|
199 | run() |
---|
200 | |
---|
201 | def on_image_viewer(self, event): |
---|
202 | """ |
---|
203 | Get choose an image file dialog |
---|
204 | |
---|
205 | :param event: menu event |
---|
206 | """ |
---|
207 | self.image_view = ImageView(parent=self.parent) |
---|
208 | self.image_view.load() |
---|
209 | |
---|
210 | def on_python_console(self, event): |
---|
211 | """ |
---|
212 | Open Python Console |
---|
213 | |
---|
214 | :param event: menu event |
---|
215 | """ |
---|
216 | self.get_python_panel(filename=None) |
---|
217 | |
---|
218 | def get_python_panel(self, filename=None): |
---|
219 | """ |
---|
220 | Get the python shell panel |
---|
221 | |
---|
222 | :param filename: file name to open in editor |
---|
223 | """ |
---|
224 | if self.py_frame is None: |
---|
225 | frame = PyConsole(parent=self.parent, base=self, |
---|
226 | filename=filename) |
---|
227 | self.put_icon(frame) |
---|
228 | self.py_frame = frame |
---|
229 | else: |
---|
230 | self.py_frame.Show(False) |
---|
231 | self.py_frame.Show(True) |
---|
232 | |
---|
233 | def put_icon(self, frame): |
---|
234 | """ |
---|
235 | Put icon in the frame title bar |
---|
236 | """ |
---|
237 | if hasattr(frame, "IsIconized"): |
---|
238 | if not frame.IsIconized(): |
---|
239 | try: |
---|
240 | icon = self.parent.GetIcon() |
---|
241 | frame.SetIcon(icon) |
---|
242 | except: |
---|
243 | pass |
---|