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 formula, " |
---|
65 | mass_volume_help += "compute the mass density or the molar volume." |
---|
66 | gensans_help = "Generic SANS" |
---|
67 | pyconsole_help = "Python Console." |
---|
68 | imageviewer_help = "Load an image file and display the image." |
---|
69 | #data_editor_help = "Meta Data Editor" |
---|
70 | return [("Data Operation", |
---|
71 | data_oper_help, self.on_data_operation), |
---|
72 | ("SLD Calculator", sld_help, self.on_calculate_sld), |
---|
73 | ("Density/Volume Calculator", mass_volume_help, |
---|
74 | self.on_calculate_dv), |
---|
75 | ("Slit Size Calculator", slit_length_help, |
---|
76 | self.on_calculate_slit_size), |
---|
77 | ("Kiessig Thickness Calculator", |
---|
78 | kiessig_help, self.on_calculate_kiessig), |
---|
79 | ("SANS Resolution Estimator", |
---|
80 | resolution_help, self.on_calculate_resoltuion), |
---|
81 | ("Generic Scattering Calculator", |
---|
82 | gensans_help, self.on_gen_model), |
---|
83 | ("Python Shell/Editor", pyconsole_help, self.on_python_console), |
---|
84 | ("Image Viewer", imageviewer_help, self.on_image_viewer),] |
---|
85 | |
---|
86 | def on_edit_data(self, event): |
---|
87 | """ |
---|
88 | Edit meta data |
---|
89 | """ |
---|
90 | from sans.perspectives.calculator.data_editor import DataEditorWindow |
---|
91 | frame = DataEditorWindow(parent=self.parent, data=[], |
---|
92 | title="Data Editor") |
---|
93 | self.put_icon(frame) |
---|
94 | frame.Show(True) |
---|
95 | |
---|
96 | def on_data_operation(self, event): |
---|
97 | """ |
---|
98 | Data operation |
---|
99 | """ |
---|
100 | if self.data_operator_frame == None: |
---|
101 | # Use one frame all the time |
---|
102 | self.data_operator_frame = DataOperatorWindow(parent=self.parent, |
---|
103 | title="Data Operation") |
---|
104 | self.put_icon(self.data_operator_frame) |
---|
105 | self.data_operator_frame.Show(False) |
---|
106 | self.data_operator_frame.panel.set_panel_on_focus(None) |
---|
107 | self.data_operator_frame.Show(True) |
---|
108 | |
---|
109 | def on_calculate_kiessig(self, event): |
---|
110 | """ |
---|
111 | Compute the Kiessig thickness |
---|
112 | """ |
---|
113 | from sans.perspectives.calculator.kiessig_calculator_panel \ |
---|
114 | import KiessigWindow |
---|
115 | frame = KiessigWindow() |
---|
116 | self.put_icon(frame) |
---|
117 | frame.Show(True) |
---|
118 | |
---|
119 | def on_calculate_sld(self, event): |
---|
120 | """ |
---|
121 | Compute the scattering length density of molecula |
---|
122 | """ |
---|
123 | from sans.perspectives.calculator.sld_panel import SldWindow |
---|
124 | frame = SldWindow(base=self.parent) |
---|
125 | self.put_icon(frame) |
---|
126 | frame.Show(True) |
---|
127 | |
---|
128 | def on_calculate_dv(self, event): |
---|
129 | """ |
---|
130 | Compute the mass density or molar voulme |
---|
131 | """ |
---|
132 | from sans.perspectives.calculator.density_panel import DensityWindow |
---|
133 | frame = DensityWindow(base=self.parent) |
---|
134 | self.put_icon(frame) |
---|
135 | frame.Show(True) |
---|
136 | |
---|
137 | def on_calculate_slit_size(self, event): |
---|
138 | """ |
---|
139 | Compute the slit size a given data |
---|
140 | """ |
---|
141 | from sans.perspectives.calculator.slit_length_calculator_panel \ |
---|
142 | import SlitLengthCalculatorWindow |
---|
143 | frame = SlitLengthCalculatorWindow(parent=self.parent) |
---|
144 | self.put_icon(frame) |
---|
145 | frame.Show(True) |
---|
146 | |
---|
147 | def on_calculate_resoltuion(self, event): |
---|
148 | """ |
---|
149 | Estimate the instrumental resolution |
---|
150 | """ |
---|
151 | from sans.perspectives.calculator.resolution_calculator_panel \ |
---|
152 | import ResolutionWindow |
---|
153 | frame = ResolutionWindow(parent=self.parent) |
---|
154 | self.put_icon(frame) |
---|
155 | frame.Show(True) |
---|
156 | |
---|
157 | def on_gen_model(self, event): |
---|
158 | """ |
---|
159 | On Generic model menu event |
---|
160 | """ |
---|
161 | from sans.perspectives.calculator.gen_scatter_panel \ |
---|
162 | import SasGenWindow |
---|
163 | frame = SasGenWindow(parent=self.parent) |
---|
164 | self.put_icon(frame) |
---|
165 | frame.Show(True) |
---|
166 | |
---|
167 | def on_image_viewer(self, event): |
---|
168 | """ |
---|
169 | Get choose an image file dialog |
---|
170 | |
---|
171 | :param event: menu event |
---|
172 | """ |
---|
173 | from sans.perspectives.calculator.image_viewer import ImageView |
---|
174 | image_view = ImageView(parent=self.parent) |
---|
175 | image_view.load() |
---|
176 | |
---|
177 | def on_python_console(self, event): |
---|
178 | """ |
---|
179 | Open Python Console |
---|
180 | |
---|
181 | :param event: menu event |
---|
182 | """ |
---|
183 | self.get_python_panel(filename=None) |
---|
184 | |
---|
185 | def get_python_panel(self, filename=None): |
---|
186 | """ |
---|
187 | Get the python shell panel |
---|
188 | |
---|
189 | :param filename: file name to open in editor |
---|
190 | """ |
---|
191 | from sans.perspectives.calculator.pyconsole import PyConsole |
---|
192 | frame = PyConsole(parent=self.parent, filename=filename) |
---|
193 | self.put_icon(frame) |
---|
194 | frame.Show(True) |
---|
195 | |
---|
196 | def put_icon(self, frame): |
---|
197 | """ |
---|
198 | Put icon in the frame title bar |
---|
199 | """ |
---|
200 | if hasattr(frame, "IsIconized"): |
---|
201 | if not frame.IsIconized(): |
---|
202 | try: |
---|
203 | icon = self.parent.GetIcon() |
---|
204 | frame.SetIcon(icon) |
---|
205 | except: |
---|
206 | pass |
---|