source: sasview/src/sas/sasgui/perspectives/calculator/calculator.py @ 05d167e

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 05d167e was a0c1e1d, checked in by smk78, 8 years ago

Changed tool name "SAS Resolution Estimator" to "Q Resolution Estimator"
to better match purpose and documentation.

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