source: sasview/sasview/sasview.py @ 38beeab

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

Logger is now a separate file

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[415fb82]1"""
2Base module for loading and running the main SasView application.
3"""
[f76bf17]4################################################################################
5#This software was developed by the University of Tennessee as part of the
6#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
[415fb82]7#project funded by the US National Science Foundation.
[f76bf17]8#
9#See the license text in license.txt
10#
11#copyright 2009, University of Tennessee
12################################################################################
13import os
[5af6f58]14import os.path
[f76bf17]15import sys
16import logging
[6722fae]17import logging.config
[4e080980]18import traceback
19
[38beeab]20from logger_config import SetupLogger
21
22l = SetupLogger(__name__)
23logger = l.config_production()
[f76bf17]24
[415fb82]25# Log the start of the session
[64ca561]26logger.info(" --- SasView session started ---")
[f76bf17]27# Log the python version
[64ca561]28logger.info("Python: %s" % sys.version)
[f76bf17]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:
[64ca561]37    logger.info("You have set the %s environment variable to %s." % \
[415fb82]38                 (WX_ENV_VAR, os.environ[WX_ENV_VAR]))
[f76bf17]39    import wxversion
40    if wxversion.checkInstalled(os.environ[WX_ENV_VAR]):
[64ca561]41        logger.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR])
[f76bf17]42        wxversion.select(os.environ[WX_ENV_VAR])
43    else:
[64ca561]44        logger.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR])
[f76bf17]45else:
[64ca561]46    logger.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR)
[f76bf17]47
48import wx
[6f3fea2]49
[f76bf17]50try:
[64ca561]51    logger.info("Wx version: %s" % wx.__version__)
[f76bf17]52except:
[64ca561]53    logger.error("Wx version: error reading version")
[415fb82]54
[85130cb]55import wxcruft
[6f16e25]56wxcruft.call_later_fix()
[6f3fea2]57#wxcruft.trace_new_id()
58
[558d64e]59#Always use private .matplotlib setup to avoid conflicts with other
60#uses of matplotlib
[77d92cd]61#Have to check if .sasview exists first
[1be5202]62sasdir = os.path.join(os.path.expanduser("~"),'.sasview')
63if not os.path.exists(sasdir):
64    os.mkdir(sasdir)
[558d64e]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")
[d85c194]71from sas.sasgui.guiframe import gui_manager
72from sas.sasgui.guiframe.gui_style import GUIFRAME
[5f0be1f]73from welcome_panel import WelcomePanel
[f76bf17]74# For py2exe, import config here
[5f0be1f]75import local_config
[f76bf17]76PLUGIN_MODEL_DIR = 'plugin_models'
77APP_NAME = 'SasView'
78
[e68c9bf]79from matplotlib import backend_bases
[cde6e52]80backend_bases.FigureCanvasBase.filetypes.pop('pgf', None)
[e68c9bf]81
[f76bf17]82class SasView():
83    """
[415fb82]84    Main class for running the SasView application
[f76bf17]85    """
86    def __init__(self):
87        """
88        """
89        #from gui_manager import ViewApp
[78f75d02]90        self.gui = gui_manager.SasViewApp(0)
[f76bf17]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:
[77d92cd]102            import sas.sasgui.perspectives.fitting as module
[f76bf17]103            fitting_plug = module.Plugin()
104            self.gui.add_perspective(fitting_plug)
[415fb82]105        except Exception:
[64ca561]106            logger.error("%s: could not find Fitting plug-in module"% APP_NAME)
107            logger.error(traceback.format_exc())
[f76bf17]108
109        # P(r) perspective
110        try:
[d85c194]111            import sas.sasgui.perspectives.pr as module
[f21d496]112            pr_plug = module.Plugin()
[f76bf17]113            self.gui.add_perspective(pr_plug)
114        except:
[64ca561]115            logger.error("%s: could not find P(r) plug-in module"% APP_NAME)
116            logger.error(traceback.format_exc())
[4e080980]117
[f76bf17]118        #Invariant perspective
119        try:
[d85c194]120            import sas.sasgui.perspectives.invariant as module
[f21d496]121            invariant_plug = module.Plugin()
[f76bf17]122            self.gui.add_perspective(invariant_plug)
[b699768]123        except Exception as e :
[64ca561]124            logger.error("%s: could not find Invariant plug-in module"% \
[f76bf17]125                          APP_NAME)
[64ca561]126            logger.error(traceback.format_exc())
[4e080980]127
[c23f303]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:
[64ca561]134            logger.error("Unable to load corfunc module")
[c23f303]135
[77d92cd]136        #Calculator perspective
[f76bf17]137        try:
[d85c194]138            import sas.sasgui.perspectives.calculator as module
[f21d496]139            calculator_plug = module.Plugin()
[f76bf17]140            self.gui.add_perspective(calculator_plug)
141        except:
[64ca561]142            logger.error("%s: could not find Calculator plug-in module"% \
[f76bf17]143                                                        APP_NAME)
[64ca561]144            logger.error(traceback.format_exc())
[4e080980]145
[77d92cd]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:
[64ca561]152            logger.error("%s: could not find File Converter plug-in module"% \
[77d92cd]153                                                        APP_NAME)
[64ca561]154            logger.error(traceback.format_exc())
[77d92cd]155
[415fb82]156
[f76bf17]157        # Add welcome page
158        self.gui.set_welcome_panel(WelcomePanel)
[415fb82]159
[f76bf17]160        # Build the GUI
161        self.gui.build_gui()
[415fb82]162        # delete unused model folder
[f76bf17]163        self.gui.clean_plugin_models(PLUGIN_MODEL_DIR)
164        # Start the main loop
165        self.gui.MainLoop()
166
167
168def run():
[415fb82]169    """
170    __main__ method for loading and running SasView
171    """
[f76bf17]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.