source: sasview/sasview/sasview.py @ 63c7d581

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 63c7d581 was 63c7d581, checked in by wojciech, 7 years ago

Fixing path in sasview.py

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