Changeset 914ba0a in sasview for src/sas/sasview/sasview.py
- Timestamp:
- May 2, 2017 3:58:01 PM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d66dbcc
- Parents:
- 74d9780 (diff), 658dd57 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasview/sasview.py
r899e084 r914ba0a 1 # -*- coding: utf-8 -*- 1 2 """ 2 3 Base module for loading and running the main SasView application. 3 4 """ 4 5 ################################################################################ 5 # This software was developed by the University of Tennessee as part of the6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)7 # project funded by the US National Science Foundation.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. 8 9 # 9 # See the license text in license.txt10 # See the license text in license.txt 10 11 # 11 # copyright 2009, University of Tennessee12 # copyright 2009, University of Tennessee 12 13 ################################################################################ 13 14 import os 15 import os.path 14 16 import sys 15 import logging16 17 import traceback 17 18 19 from sas.sasview.logger_config import SetupLogger 18 20 19 21 reload(sys) 20 22 sys.setdefaultencoding("iso-8859-1") 21 23 22 23 class StreamToLogger(object): 24 """ 25 File-like stream object that redirects writes to a logger instance. 26 """ 27 def __init__(self, logger, log_level=logging.INFO): 28 self.logger = logger 29 self.log_level = log_level 30 self.linebuf = '' 31 32 def write(self, buf): 33 """ 34 Main logging method 35 """ 36 # Write the message to stdout so we can see it when running interactively 37 sys.stdout.write(buf) 38 for line in buf.rstrip().splitlines(): 39 self.logger.log(self.log_level, line.rstrip()) 24 logger = SetupLogger(__name__).config_production() 25 # Log the start of the session 26 logger.info(" --- SasView session started ---") 27 # Log the python version 28 logger.info("Python: %s" % sys.version) 29 40 30 41 31 PLUGIN_MODEL_DIR = 'plugin_models' … … 66 56 self.gui.add_perspective(fitting_plug) 67 57 except Exception: 68 logg ing.error("%s: could not find Fitting plug-in module"% APP_NAME)69 logg ing.error(traceback.format_exc())58 logger.error("%s: could not find Fitting plug-in module"% APP_NAME) 59 logger.error(traceback.format_exc()) 70 60 71 61 # P(r) perspective … … 75 65 self.gui.add_perspective(pr_plug) 76 66 except: 77 logg ing.error("%s: could not find P(r) plug-in module"% APP_NAME)78 logg ing.error(traceback.format_exc())79 80 # Invariant perspective67 logger.error("%s: could not find P(r) plug-in module"% APP_NAME) 68 logger.error(traceback.format_exc()) 69 70 # Invariant perspective 81 71 try: 82 72 import sas.sasgui.perspectives.invariant as module … … 84 74 self.gui.add_perspective(invariant_plug) 85 75 except Exception as e : 86 logg ing.error("%s: could not find Invariant plug-in module"% \76 logger.error("%s: could not find Invariant plug-in module"% \ 87 77 APP_NAME) 88 logging.error(traceback.format_exc()) 89 90 #Calculator perspective 78 logger.error(traceback.format_exc()) 79 80 # Corfunc perspective 81 try: 82 import sas.sasgui.perspectives.corfunc as module 83 corfunc_plug = module.Plugin() 84 self.gui.add_perspective(corfunc_plug) 85 except: 86 logger.error("Unable to load corfunc module") 87 88 # Calculator perspective 91 89 try: 92 90 import sas.sasgui.perspectives.calculator as module … … 94 92 self.gui.add_perspective(calculator_plug) 95 93 except: 96 logg ing.error("%s: could not find Calculator plug-in module"% \94 logger.error("%s: could not find Calculator plug-in module"% \ 97 95 APP_NAME) 98 logging.error(traceback.format_exc()) 99 96 logger.error(traceback.format_exc()) 97 98 # File converter tool 99 try: 100 import sas.sasgui.perspectives.file_converter as module 101 converter_plug = module.Plugin() 102 self.gui.add_perspective(converter_plug) 103 except: 104 logger.error("%s: could not find File Converter plug-in module"% \ 105 APP_NAME) 106 logger.error(traceback.format_exc()) 100 107 101 108 # Add welcome page … … 138 145 WX_ENV_VAR = "SASVIEW_WX_VERSION" 139 146 if WX_ENV_VAR in os.environ: 140 logg ing.info("You have set the %s environment variable to %s." % \147 logger.info("You have set the %s environment variable to %s." % \ 141 148 (WX_ENV_VAR, os.environ[WX_ENV_VAR])) 142 149 import wxversion 143 150 if wxversion.checkInstalled(os.environ[WX_ENV_VAR]): 144 logg ing.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR])151 logger.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR]) 145 152 wxversion.select(os.environ[WX_ENV_VAR]) 146 153 else: 147 logg ing.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR])154 logger.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR]) 148 155 else: 149 logg ing.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR)156 logger.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR) 150 157 151 158 import wx 152 159 153 160 try: 154 logg ing.info("Wx version: %s" % wx.__version__)161 logger.info("Wx version: %s" % wx.__version__) 155 162 except: 156 logg ing.error("Wx version: error reading version")163 logger.error("Wx version: error reading version") 157 164 158 165 from . import wxcruft … … 165 172 def setup_mpl(): 166 173 import sas.sasgui 174 # Always use private .matplotlib setup to avoid conflicts with other 167 175 mplconfigdir = os.path.join(sas.sasgui.get_user_dir(), '.matplotlib') 168 176 if not os.path.exists(mplconfigdir): … … 176 184 177 185 186 from matplotlib import backend_bases 187 backend_bases.FigureCanvasBase.filetypes.pop('pgf', None) 188 178 189 def run_gui(): 179 190 """ … … 197 208 else: 198 209 # Run sasview as a python script interpreter 210 ## Run sasview as an interactive python interpreter 211 # if sys.argv[1] == "-i": 212 # sys.argv = ["ipython", "--pylab"] 213 # from IPython import start_ipython 214 # sys.exit(start_ipython()) 199 215 thing_to_run = sys.argv[1] 200 216 sys.argv = sys.argv[1:] … … 205 221 runpy.run_module(thing_to_run, run_name="__main__") 206 222 223 207 224 if __name__ == "__main__": 208 225 run_gui() 209
Note: See TracChangeset
for help on using the changeset viewer.