source: sasview/sasview/sasview.py @ 463e7ffc

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

getLogger with module name

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