source: sasview/src/sas/perspectives/calculator/calculator.py @ 7a04dbb

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 7a04dbb was b9a5f0e, checked in by krzywon, 10 years ago

90% complete with the conversion.

  • Property mode set to 100644
File size: 9.4 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
38        logging.info("Calculator plug-in started")   
[fdc3cb0]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
51       
[a48842a2]52       
[427fa87]53    def help(self, evt):
54        """
[6137b150]55        Show a general help dialog.
56       
57        :TODO: replace the text with a nice image
[427fa87]58            provide more hint on the SLD calculator
59        """
60        from help_panel import  HelpWindow
[8e4a562]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 
[427fa87]69        frame.Show(True)
[a0ac888]70
[fb0d7a20]71    def get_tools(self):
72        """
[6137b150]73        Returns a set of menu entries for tools
[fb0d7a20]74        """
[ce3feca]75        data_oper_help = "Perform arithmetic data operation (+...) "
76        data_oper_help += "and combination (|)"
[5cc393b8]77        kiessig_help = "Approximately computes the "
[74b1770]78        kiessig_help += "thickness of a shell or the size of "
79        kiessig_help += "particles \n from the width of a Kiessig fringe."
[5cc393b8]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 "
[b9a5f0e]83        resolution_help += "resolution of Q in 2D based on the SAS "
[5cc393b8]84        resolution_help += "instrumental parameter values."
[49a8843]85        mass_volume_help = "Based on the chemical formula, "
[9520702]86        mass_volume_help += "compute the mass density or the molar volume."
[b9a5f0e]87        gensas_help = "Generic SAS"
[b1bda35]88        pyconsole_help = "Python Console."
[3e001f9]89        imageviewer_help = "Load an image file and display the image."
[b0ab6cb]90        #data_editor_help = "Meta Data Editor"
[a48842a2]91        return [("Data Operation", 
[ce3feca]92                        data_oper_help, self.on_data_operation),
[a48842a2]93                ("SLD Calculator", sld_help, self.on_calculate_sld),
[9520702]94                ("Density/Volume Calculator", mass_volume_help, 
95                                            self.on_calculate_dv),
[b500652]96                ("Slit Size Calculator", slit_length_help,
[74b1770]97                        self.on_calculate_slit_size),
98                ("Kiessig Thickness Calculator", 
[3be3a80]99                        kiessig_help, self.on_calculate_kiessig),
[b9a5f0e]100                          ("SAS Resolution Estimator", 
[ec6c520]101                        resolution_help, self.on_calculate_resoltuion),
[318b5bbb]102                ("Generic Scattering Calculator", 
[b9a5f0e]103                        gensas_help, self.on_gen_model),
[3e001f9]104                ("Python Shell/Editor", pyconsole_help, self.on_python_console),
105                ("Image Viewer", imageviewer_help, self.on_image_viewer),]
[fb0d7a20]106             
[91f151a]107    def on_edit_data(self, event):
108        """
[6137b150]109        Edit meta data
[91f151a]110        """
[ae84427]111        if self.data_edit_frame == None:
112            self.data_edit_frame = DataEditorWindow(parent=self.parent, 
113                                                    manager=self, data=[],
114                                                    title="Data Editor")
[79b550a]115            self.put_icon(self.data_edit_frame)
[7aa1685]116        else:
117            self.data_edit_frame.Show(False)   
[ae84427]118        self.data_edit_frame.Show(True)
[a48842a2]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, 
[ae84427]127                                                manager=self, 
[a48842a2]128                                                title="Data Operation")
[79b550a]129            self.put_icon(self.data_operator_frame)
[7aa1685]130        else:
131            self.data_operator_frame.Show(False)
[306219c]132        self.data_operator_frame.panel.set_panel_on_focus(None)
[a48842a2]133        self.data_operator_frame.Show(True)
134       
[74b1770]135    def on_calculate_kiessig(self, event):
136        """
137        Compute the Kiessig thickness
138        """
[ae84427]139        if self.kiessig_frame == None:
140            frame = KiessigWindow(parent=self.parent, manager=self)
[79b550a]141            self.put_icon(frame)
[ae84427]142            self.kiessig_frame = frame
[7aa1685]143        else:
144            self.kiessig_frame.Show(False)
[ae84427]145        self.kiessig_frame.Show(True) 
146       
[fb0d7a20]147    def on_calculate_sld(self, event):
148        """
[6137b150]149        Compute the scattering length density of molecula
[fb0d7a20]150        """
[ae84427]151        if self.sld_frame == None:
[7aa1685]152            frame = SldWindow(parent=self.parent, 
153                                  base=self.parent, manager=self)
[79b550a]154            self.put_icon(frame)
[ae84427]155            self.sld_frame = frame
[7aa1685]156        else:
157            self.sld_frame.Show(False)
[ae84427]158        self.sld_frame.Show(True) 
[9520702]159   
160    def on_calculate_dv(self, event):
161        """
162        Compute the mass density or molar voulme
163        """
[ae84427]164        if self.cal_md_frame == None:
[7aa1685]165            frame = DensityWindow(parent=self.parent, 
166                                  base=self.parent, manager=self)
[79b550a]167            self.put_icon(frame)
[ae84427]168            self.cal_md_frame = frame
[7aa1685]169        else:
170            self.cal_md_frame.Show(False)
[ae84427]171        self.cal_md_frame.Show(True) 
[9520702]172             
[378d2eb]173    def on_calculate_slit_size(self, event):
174        """
[6137b150]175        Compute the slit size a given data
[378d2eb]176        """
[ae84427]177        if self.cal_slit_frame == None:
178            frame = SlitLengthCalculatorWindow(parent=self.parent, manager=self) 
[79b550a]179            self.put_icon(frame)
[ae84427]180            self.cal_slit_frame = frame
[7aa1685]181        else:
182            self.cal_slit_frame.Show(False)     
[ae84427]183        self.cal_slit_frame.Show(True)
[3be3a80]184       
185    def on_calculate_resoltuion(self, event):
186        """
187        Estimate the instrumental resolution
188        """
[ae84427]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
[7aa1685]193        else:
194            self.cal_res_frame.Show(False)
[ae84427]195        self.cal_res_frame.Show(True) 
[318b5bbb]196       
197    def on_gen_model(self, event):
[49a8843]198        """
199        On Generic model menu event
200        """
[ae84427]201        if self.gen_frame == None:
202            frame = SasGenWindow(parent=self.parent, manager=self)
[79b550a]203            self.put_icon(frame)
[ae84427]204            self.gen_frame = frame
[7aa1685]205        else:
206            self.gen_frame.Show(False)
[ae84427]207        self.gen_frame.Show(True) 
[3e001f9]208
209    def on_image_viewer(self, event):
210        """
211        Get choose an image file dialog
212       
213        :param event: menu event
214        """
[ae84427]215        self.image_view = ImageView(parent=self.parent)
216        self.image_view.load()
[318b5bbb]217       
[ec6c520]218    def on_python_console(self, event):
219        """
220        Open Python Console
221       
222        :param event: menu event
223        """
[fb58234]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        """
[ae84427]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
[7aa1685]237        else:
238            self.py_frame.Show(False)
[ae84427]239        self.py_frame.Show(True) 
[fb58234]240       
[9a56619]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:
[3e001f9]251                    pass     
Note: See TracBrowser for help on using the repository browser.