source: sasview/src/sas/sasgui/perspectives/calculator/calculator.py @ 61379c2e

magnetic_scattrelease-4.2.2ticket-1009ticket-1249
Last change on this file since 61379c2e was 5251ec6, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

improved support for py37 in sasgui

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