source: sasview/src/sas/perspectives/calculator/calculator.py @ 2df0b74

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.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2df0b74 was 49ab5d7, checked in by Doucet, Mathieu <doucetm@…>, 10 years ago

Take care of white spaces (pylint)

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