source: sasview/sasview/sasview.py @ f36e01f

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

Some pylint enhancements

  • Property mode set to 100644
File size: 6.5 KB
Line 
1# -*- coding: utf-8 -*-
2"""
3Base module for loading and running the main SasView application.
4"""
5################################################################################
6# This software was developed by the University of Tennessee as part of the
7# Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
8# project funded by the US National Science Foundation.
9#
10# See the license text in license.txt
11#
12# copyright 2009, University of Tennessee
13################################################################################
14import os
15import os.path
16import sys
17import traceback
18
19from sas.sasview.logger_config import SetupLogger
20
21logger = SetupLogger(__name__).config_production()
22
23
24# Log the start of the session
25logger.info(" --- SasView session started ---")
26# Log the python version
27logger.info("Python: %s" % sys.version)
28
29# Allow the dynamic selection of wxPython via an environment variable, when devs
30# who have multiple versions of the module installed want to pick between them.
31# This variable does not have to be set of course, and through normal usage will
32# probably not be, but this can make things a little easier when upgrading to a
33# new version of wx.
34WX_ENV_VAR = "SASVIEW_WX_VERSION"
35if WX_ENV_VAR in os.environ:
36    logger.info("You have set the %s environment variable to %s." % \
37                 (WX_ENV_VAR, os.environ[WX_ENV_VAR]))
38    import wxversion
39    if wxversion.checkInstalled(os.environ[WX_ENV_VAR]):
40        logger.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR])
41        wxversion.select(os.environ[WX_ENV_VAR])
42    else:
43        logger.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR])
44else:
45    logger.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR)
46
47import wx
48
49try:
50    logger.info("Wx version: %s" % wx.__version__)
51except:
52    logger.error("Wx version: error reading version")
53
54import wxcruft
55wxcruft.call_later_fix()
56# wxcruft.trace_new_id()
57
58# Always use private .matplotlib setup to avoid conflicts with other
59# uses of matplotlib
60# Have to check if .sasview exists first
61sasdir = os.path.join(os.path.expanduser("~"),'.sasview')
62if not os.path.exists(sasdir):
63    os.mkdir(sasdir)
64mplconfigdir = os.path.join(os.path.expanduser("~"),'.sasview','.matplotlib')
65if not os.path.exists(mplconfigdir):
66    os.mkdir(mplconfigdir)
67os.environ['MPLCONFIGDIR'] = mplconfigdir
68reload(sys)
69sys.setdefaultencoding("iso-8859-1")
70from sas.sasgui.guiframe import gui_manager
71from sas.sasgui.guiframe.gui_style import GUIFRAME
72from welcome_panel import WelcomePanel
73
74PLUGIN_MODEL_DIR = 'plugin_models'
75APP_NAME = 'SasView'
76
77from matplotlib import backend_bases
78backend_bases.FigureCanvasBase.filetypes.pop('pgf', None)
79
80class SasView():
81    """
82    Main class for running the SasView application
83    """
84    def __init__(self):
85        """
86        """
87        # from gui_manager import ViewApp
88        self.gui = gui_manager.SasViewApp(0)
89        # Set the application manager for the GUI
90        self.gui.set_manager(self)
91        # Add perspectives to the basic application
92        # Additional perspectives can still be loaded
93        # dynamically
94        # Note: py2exe can't find dynamically loaded
95        # modules. We load the fitting module here
96        # to ensure a complete Windows executable build.
97
98        # Fitting perspective
99        try:
100            import sas.sasgui.perspectives.fitting as module
101            fitting_plug = module.Plugin()
102            self.gui.add_perspective(fitting_plug)
103        except Exception:
104            logger.error("%s: could not find Fitting plug-in module"% APP_NAME)
105            logger.error(traceback.format_exc())
106
107        # P(r) perspective
108        try:
109            import sas.sasgui.perspectives.pr as module
110            pr_plug = module.Plugin()
111            self.gui.add_perspective(pr_plug)
112        except:
113            logger.error("%s: could not find P(r) plug-in module"% APP_NAME)
114            logger.error(traceback.format_exc())
115
116        # Invariant perspective
117        try:
118            import sas.sasgui.perspectives.invariant as module
119            invariant_plug = module.Plugin()
120            self.gui.add_perspective(invariant_plug)
121        except Exception as e :
122            logger.error("%s: could not find Invariant plug-in module"% \
123                          APP_NAME)
124            logger.error(traceback.format_exc())
125
126        # Corfunc perspective
127        try:
128            import sas.sasgui.perspectives.corfunc as module
129            corfunc_plug = module.Plugin()
130            self.gui.add_perspective(corfunc_plug)
131        except:
132            logger.error("Unable to load corfunc module")
133
134        # Calculator perspective
135        try:
136            import sas.sasgui.perspectives.calculator as module
137            calculator_plug = module.Plugin()
138            self.gui.add_perspective(calculator_plug)
139        except:
140            logger.error("%s: could not find Calculator plug-in module"% \
141                                                        APP_NAME)
142            logger.error(traceback.format_exc())
143
144        # File converter tool
145        try:
146            import sas.sasgui.perspectives.file_converter as module
147            converter_plug = module.Plugin()
148            self.gui.add_perspective(converter_plug)
149        except:
150            logger.error("%s: could not find File Converter plug-in module"% \
151                                                        APP_NAME)
152            logger.error(traceback.format_exc())
153
154        # Add welcome page
155        self.gui.set_welcome_panel(WelcomePanel)
156
157        # Build the GUI
158        self.gui.build_gui()
159        # delete unused model folder
160        self.gui.clean_plugin_models(PLUGIN_MODEL_DIR)
161        # Start the main loop
162        self.gui.MainLoop()
163
164
165def run():
166    """
167    __main__ method for loading and running SasView
168    """
169    from multiprocessing import freeze_support
170    freeze_support()
171    if len(sys.argv) > 1:
172        ## Run sasview as an interactive python interpreter
173        # if sys.argv[1] == "-i":
174        #    sys.argv = ["ipython", "--pylab"]
175        #    from IPython import start_ipython
176        #    sys.exit(start_ipython())
177        thing_to_run = sys.argv[1]
178        sys.argv = sys.argv[1:]
179        import runpy
180        if os.path.exists(thing_to_run):
181            runpy.run_path(thing_to_run, run_name="__main__")
182        else:
183            runpy.run_module(thing_to_run, run_name="__main__")
184    else:
185        SasView()
186
187
188if __name__ == "__main__":
189    run()
Note: See TracBrowser for help on using the repository browser.