source: sasview/src/sas/perspectives/calculator/calculator.py @ 684fade

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 684fade was b9a5f0e, checked in by krzywon, 9 years ago

90% complete with the conversion.

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