source: sasview/sasview/sasview.py @ 9c923a3

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

Removed quotes

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