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 | |
---|
15 | from sans.guiframe.plugin_base import PluginBase |
---|
16 | from sans.perspectives.calculator.data_operator import DataOperatorWindow |
---|
17 | import logging |
---|
18 | |
---|
19 | class Plugin(PluginBase): |
---|
20 | """ |
---|
21 | This class defines the interface for a Plugin class |
---|
22 | for calculator perspective |
---|
23 | """ |
---|
24 | def __init__(self, standalone=True): |
---|
25 | PluginBase.__init__(self, name="Calculator", standalone=standalone) |
---|
26 | # Log startup |
---|
27 | logging.info("Calculator plug-in started") |
---|
28 | self.sub_menu = "Tool" |
---|
29 | # data operator use one frame all the time |
---|
30 | self.data_operator_frame = None |
---|
31 | |
---|
32 | def help(self, evt): |
---|
33 | """ |
---|
34 | Show a general help dialog. |
---|
35 | |
---|
36 | :TODO: replace the text with a nice image |
---|
37 | provide more hint on the SLD calculator |
---|
38 | """ |
---|
39 | from help_panel import HelpWindow |
---|
40 | frame = HelpWindow(None, -1) |
---|
41 | if hasattr(frame, "IsIconized"): |
---|
42 | if not frame.IsIconized(): |
---|
43 | try: |
---|
44 | icon = self.parent.GetIcon() |
---|
45 | frame.SetIcon(icon) |
---|
46 | except: |
---|
47 | pass |
---|
48 | frame.Show(True) |
---|
49 | |
---|
50 | def get_tools(self): |
---|
51 | """ |
---|
52 | Returns a set of menu entries for tools |
---|
53 | """ |
---|
54 | data_oper_help = "Perform arithmetic data operation (+...) " |
---|
55 | data_oper_help += "and combination (|)" |
---|
56 | kiessig_help = "Approximately computes the " |
---|
57 | kiessig_help += "thickness of a shell or the size of " |
---|
58 | kiessig_help += "particles \n from the width of a Kiessig fringe." |
---|
59 | sld_help = "Computes the Scattering Length Density." |
---|
60 | slit_length_help = "Computes the slit length from the beam profile." |
---|
61 | resolution_help = "Approximately estimates the " |
---|
62 | resolution_help += "resolution of Q in 2D based on the SANS " |
---|
63 | resolution_help += "instrumental parameter values." |
---|
64 | mass_volume_help = "Based on the chemical formular, " |
---|
65 | mass_volume_help += "compute the mass density or the molar volume." |
---|
66 | gensans_help = "Genneric SANS" |
---|
67 | pyconsole_help = "Python Console." |
---|
68 | #data_editor_help = "Meta Data Editor" |
---|
69 | return [("Data Operation", |
---|
70 | data_oper_help, self.on_data_operation), |
---|
71 | ("SLD Calculator", sld_help, self.on_calculate_sld), |
---|
72 | ("Density/Volume Calculator", mass_volume_help, |
---|
73 | self.on_calculate_dv), |
---|
74 | ("Slit Size Calculator", slit_length_help, |
---|
75 | self.on_calculate_slit_size), |
---|
76 | ("Kiessig Thickness Calculator", |
---|
77 | kiessig_help, self.on_calculate_kiessig), |
---|
78 | ("SANS Resolution Estimator", |
---|
79 | resolution_help, self.on_calculate_resoltuion), |
---|
80 | ("Generic Scattering Calculator", |
---|
81 | gensans_help, self.on_gen_model), |
---|
82 | ("Python Shell/Editor", pyconsole_help, self.on_python_console)] |
---|
83 | |
---|
84 | def on_edit_data(self, event): |
---|
85 | """ |
---|
86 | Edit meta data |
---|
87 | """ |
---|
88 | from sans.perspectives.calculator.data_editor import DataEditorWindow |
---|
89 | frame = DataEditorWindow(parent=self.parent, data=[], |
---|
90 | title="Data Editor") |
---|
91 | self.put_icon(frame) |
---|
92 | frame.Show(True) |
---|
93 | |
---|
94 | def on_data_operation(self, event): |
---|
95 | """ |
---|
96 | Data operation |
---|
97 | """ |
---|
98 | if self.data_operator_frame == None: |
---|
99 | # Use one frame all the time |
---|
100 | self.data_operator_frame = DataOperatorWindow(parent=self.parent, |
---|
101 | title="Data Operation") |
---|
102 | self.put_icon(self.data_operator_frame) |
---|
103 | self.data_operator_frame.Show(False) |
---|
104 | self.data_operator_frame.panel.set_panel_on_focus(None) |
---|
105 | self.data_operator_frame.Show(True) |
---|
106 | |
---|
107 | def on_calculate_kiessig(self, event): |
---|
108 | """ |
---|
109 | Compute the Kiessig thickness |
---|
110 | """ |
---|
111 | from sans.perspectives.calculator.kiessig_calculator_panel \ |
---|
112 | import KiessigWindow |
---|
113 | frame = KiessigWindow() |
---|
114 | self.put_icon(frame) |
---|
115 | frame.Show(True) |
---|
116 | |
---|
117 | def on_calculate_sld(self, event): |
---|
118 | """ |
---|
119 | Compute the scattering length density of molecula |
---|
120 | """ |
---|
121 | from sans.perspectives.calculator.sld_panel import SldWindow |
---|
122 | frame = SldWindow(base=self.parent) |
---|
123 | self.put_icon(frame) |
---|
124 | frame.Show(True) |
---|
125 | |
---|
126 | def on_calculate_dv(self, event): |
---|
127 | """ |
---|
128 | Compute the mass density or molar voulme |
---|
129 | """ |
---|
130 | from sans.perspectives.calculator.density_panel import DensityWindow |
---|
131 | frame = DensityWindow(base=self.parent) |
---|
132 | self.put_icon(frame) |
---|
133 | frame.Show(True) |
---|
134 | |
---|
135 | def on_calculate_slit_size(self, event): |
---|
136 | """ |
---|
137 | Compute the slit size a given data |
---|
138 | """ |
---|
139 | from sans.perspectives.calculator.slit_length_calculator_panel \ |
---|
140 | import SlitLengthCalculatorWindow |
---|
141 | frame = SlitLengthCalculatorWindow(parent=self.parent) |
---|
142 | self.put_icon(frame) |
---|
143 | frame.Show(True) |
---|
144 | |
---|
145 | def on_calculate_resoltuion(self, event): |
---|
146 | """ |
---|
147 | Estimate the instrumental resolution |
---|
148 | """ |
---|
149 | from sans.perspectives.calculator.resolution_calculator_panel \ |
---|
150 | import ResolutionWindow |
---|
151 | frame = ResolutionWindow(parent=self.parent) |
---|
152 | self.put_icon(frame) |
---|
153 | frame.Show(True) |
---|
154 | |
---|
155 | #def on_perspective(self, event): |
---|
156 | """ |
---|
157 | Call back function for the perspective menu item. |
---|
158 | We notify the parent window that the perspective |
---|
159 | has changed. |
---|
160 | |
---|
161 | :param event: menu event |
---|
162 | |
---|
163 | """ |
---|
164 | #self.parent.set_perspective(self.perspective) |
---|
165 | #if event != None: |
---|
166 | # event.Skip() |
---|
167 | |
---|
168 | def on_gen_model(self, event): |
---|
169 | from sans.perspectives.calculator.gen_scatter_panel \ |
---|
170 | import SasGenWindow |
---|
171 | frame = SasGenWindow(parent=self.parent) |
---|
172 | self.put_icon(frame) |
---|
173 | frame.Show(True) |
---|
174 | |
---|
175 | def on_python_console(self, event): |
---|
176 | """ |
---|
177 | Open Python Console |
---|
178 | |
---|
179 | :param event: menu event |
---|
180 | """ |
---|
181 | self.get_python_panel(filename=None) |
---|
182 | |
---|
183 | def get_python_panel(self, filename=None): |
---|
184 | """ |
---|
185 | Get the python shell panel |
---|
186 | |
---|
187 | :param filename: file name to open in editor |
---|
188 | """ |
---|
189 | from sans.perspectives.calculator.pyconsole import PyConsole |
---|
190 | frame = PyConsole(parent=self.parent, filename=filename) |
---|
191 | self.put_icon(frame) |
---|
192 | frame.Show(True) |
---|
193 | |
---|
194 | def put_icon(self, frame): |
---|
195 | """ |
---|
196 | Put icon in the frame title bar |
---|
197 | """ |
---|
198 | if hasattr(frame, "IsIconized"): |
---|
199 | if not frame.IsIconized(): |
---|
200 | try: |
---|
201 | icon = self.parent.GetIcon() |
---|
202 | frame.SetIcon(icon) |
---|
203 | except: |
---|
204 | pass |
---|
205 | |
---|
206 | |
---|