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