source: sasview/calculatorview/src/sans/perspectives/calculator/calculator.py @ 0008f54

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 0008f54 was a48842a2, checked in by Jae Cho <jhjcho@…>, 12 years ago

added data operation tool

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