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

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 ae84427 was ae84427, checked in by Jae Cho <jhjcho@…>, 11 years ago

mdi frames for main applications

  • Property mode set to 100644
File size: 9.2 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 sans.guiframe.plugin_base import PluginBase
16from sans.perspectives.calculator.data_operator import DataOperatorWindow
17from sans.perspectives.calculator.data_editor import DataEditorWindow
18from sans.perspectives.calculator.kiessig_calculator_panel import KiessigWindow
19from sans.perspectives.calculator.sld_panel import SldWindow
20from sans.perspectives.calculator.density_panel import DensityWindow
21from sans.perspectives.calculator.slit_length_calculator_panel \
22            import SlitLengthCalculatorWindow
23from sans.perspectives.calculator.resolution_calculator_panel \
24            import ResolutionWindow
25from sans.perspectives.calculator.gen_scatter_panel import SasGenWindow
26from sans.perspectives.calculator.image_viewer import ImageView
27from sans.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 SANS "
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        gensans_help = "Generic SANS"
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                          ("SANS Resolution Estimator", 
101                        resolution_help, self.on_calculate_resoltuion),
102                ("Generic Scattering Calculator", 
103                        gensans_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        self.data_edit_frame.Show(False)   
117        self.data_edit_frame.Show(True)
118             
119    def on_data_operation(self, event):
120        """
121        Data operation
122        """
123        if self.data_operator_frame == None:
124            # Use one frame all the time
125            self.data_operator_frame = DataOperatorWindow(parent=self.parent, 
126                                                manager=self, 
127                                                title="Data Operation")
128            self.put_icon(self.data_operator_frame)
129        self.data_operator_frame.Show(False)
130        self.data_operator_frame.panel.set_panel_on_focus(None)
131        self.data_operator_frame.Show(True)
132       
133    def on_calculate_kiessig(self, event):
134        """
135        Compute the Kiessig thickness
136        """
137        if self.kiessig_frame == None:
138            frame = KiessigWindow(parent=self.parent, manager=self)
139            self.put_icon(frame)
140            self.kiessig_frame = frame
141        self.kiessig_frame.Show(False)
142        self.kiessig_frame.Show(True) 
143       
144    def on_calculate_sld(self, event):
145        """
146        Compute the scattering length density of molecula
147        """
148        if self.sld_frame == None:
149            frame = SldWindow(base=self.parent, manager=self)
150            self.put_icon(frame)
151            self.sld_frame = frame
152        self.sld_frame.Show(False)
153        self.sld_frame.Show(True) 
154   
155    def on_calculate_dv(self, event):
156        """
157        Compute the mass density or molar voulme
158        """
159        if self.cal_md_frame == None:
160            frame = DensityWindow(base=self.parent, manager=self)
161            self.put_icon(frame)
162            self.cal_md_frame = frame
163        self.cal_md_frame.Show(False)
164        self.cal_md_frame.Show(True) 
165             
166    def on_calculate_slit_size(self, event):
167        """
168        Compute the slit size a given data
169        """
170        if self.cal_slit_frame == None:
171            frame = SlitLengthCalculatorWindow(parent=self.parent, manager=self) 
172            self.put_icon(frame)
173            self.cal_slit_frame = frame
174        self.cal_slit_frame.Show(False)     
175        self.cal_slit_frame.Show(True)
176       
177    def on_calculate_resoltuion(self, event):
178        """
179        Estimate the instrumental resolution
180        """
181        if self.cal_res_frame == None:
182            frame = ResolutionWindow(parent=self.parent, manager=self)
183            self.put_icon(frame)
184            self.cal_res_frame = frame
185        self.cal_res_frame.Show(False)
186        self.cal_res_frame.Show(True) 
187       
188    def on_gen_model(self, event):
189        """
190        On Generic model menu event
191        """
192        if self.gen_frame == None:
193            frame = SasGenWindow(parent=self.parent, manager=self)
194            self.put_icon(frame)
195            self.gen_frame = frame
196        self.gen_frame.Show(False)
197        self.gen_frame.Show(True) 
198
199    def on_image_viewer(self, event):
200        """
201        Get choose an image file dialog
202       
203        :param event: menu event
204        """
205        self.image_view = ImageView(parent=self.parent)
206        self.image_view.load()
207       
208    def on_python_console(self, event):
209        """
210        Open Python Console
211       
212        :param event: menu event
213        """
214        self.get_python_panel(filename=None)
215       
216    def get_python_panel(self, filename=None):
217        """
218        Get the python shell panel
219       
220        :param filename: file name to open in editor
221        """
222        if self.py_frame == None:
223            frame = PyConsole(parent=self.parent, base=self, 
224                              filename=filename)
225            self.put_icon(frame)
226            self.py_frame = frame
227        self.py_frame.Show(False)
228        self.py_frame.Show(True) 
229       
230    def put_icon(self, frame):
231        """
232        Put icon in the frame title bar
233        """
234        if hasattr(frame, "IsIconized"):
235            if not frame.IsIconized():
236                try:
237                    icon = self.parent.GetIcon()
238                    frame.SetIcon(icon)
239                except:
240                    pass     
Note: See TracBrowser for help on using the repository browser.