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