source: sasview/sasview/sasview.py @ 5af6f58

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

Solved file problem for py2exe?

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