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

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 ec8886e was 463e7ffc, checked in by Ricardo Ferraz Leal <ricleal@…>, 8 years ago

getLogger with module name

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