Changeset 914ba0a in sasview for src/sas/sasview/sasview.py


Ignore:
Timestamp:
May 2, 2017 3:58:01 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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.
Message:

merge with master

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasview/sasview.py

    r899e084 r914ba0a  
     1# -*- coding: utf-8 -*- 
    12""" 
    23Base module for loading and running the main SasView application. 
    34""" 
    45################################################################################ 
    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. 
     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. 
    89# 
    9 #See the license text in license.txt 
     10# See the license text in license.txt 
    1011# 
    11 #copyright 2009, University of Tennessee 
     12# copyright 2009, University of Tennessee 
    1213################################################################################ 
    1314import os 
     15import os.path 
    1416import sys 
    15 import logging 
    1617import traceback 
    1718 
     19from sas.sasview.logger_config import SetupLogger 
    1820 
    1921reload(sys) 
    2022sys.setdefaultencoding("iso-8859-1") 
    2123 
    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()) 
     24logger = SetupLogger(__name__).config_production() 
     25# Log the start of the session 
     26logger.info(" --- SasView session started ---") 
     27# Log the python version 
     28logger.info("Python: %s" % sys.version) 
     29 
    4030 
    4131PLUGIN_MODEL_DIR = 'plugin_models' 
     
    6656            self.gui.add_perspective(fitting_plug) 
    6757        except Exception: 
    68             logging.error("%s: could not find Fitting plug-in module"% APP_NAME) 
    69             logging.error(traceback.format_exc()) 
     58            logger.error("%s: could not find Fitting plug-in module"% APP_NAME) 
     59            logger.error(traceback.format_exc()) 
    7060 
    7161        # P(r) perspective 
     
    7565            self.gui.add_perspective(pr_plug) 
    7666        except: 
    77             logging.error("%s: could not find P(r) plug-in module"% APP_NAME) 
    78             logging.error(traceback.format_exc()) 
    79  
    80         #Invariant perspective 
     67            logger.error("%s: could not find P(r) plug-in module"% APP_NAME) 
     68            logger.error(traceback.format_exc()) 
     69 
     70        # Invariant perspective 
    8171        try: 
    8272            import sas.sasgui.perspectives.invariant as module 
     
    8474            self.gui.add_perspective(invariant_plug) 
    8575        except Exception as e : 
    86             logging.error("%s: could not find Invariant plug-in module"% \ 
     76            logger.error("%s: could not find Invariant plug-in module"% \ 
    8777                          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 
    9189        try: 
    9290            import sas.sasgui.perspectives.calculator as module 
     
    9492            self.gui.add_perspective(calculator_plug) 
    9593        except: 
    96             logging.error("%s: could not find Calculator plug-in module"% \ 
     94            logger.error("%s: could not find Calculator plug-in module"% \ 
    9795                                                        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()) 
    100107 
    101108        # Add welcome page 
     
    138145    WX_ENV_VAR = "SASVIEW_WX_VERSION" 
    139146    if WX_ENV_VAR in os.environ: 
    140         logging.info("You have set the %s environment variable to %s." % \ 
     147        logger.info("You have set the %s environment variable to %s." % \ 
    141148                     (WX_ENV_VAR, os.environ[WX_ENV_VAR])) 
    142149        import wxversion 
    143150        if wxversion.checkInstalled(os.environ[WX_ENV_VAR]): 
    144             logging.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]) 
    145152            wxversion.select(os.environ[WX_ENV_VAR]) 
    146153        else: 
    147             logging.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]) 
    148155    else: 
    149         logging.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) 
    150157 
    151158    import wx 
    152159 
    153160    try: 
    154         logging.info("Wx version: %s" % wx.__version__) 
     161        logger.info("Wx version: %s" % wx.__version__) 
    155162    except: 
    156         logging.error("Wx version: error reading version") 
     163        logger.error("Wx version: error reading version") 
    157164 
    158165    from . import wxcruft 
     
    165172def setup_mpl(): 
    166173    import sas.sasgui 
     174    # Always use private .matplotlib setup to avoid conflicts with other 
    167175    mplconfigdir = os.path.join(sas.sasgui.get_user_dir(), '.matplotlib') 
    168176    if not os.path.exists(mplconfigdir): 
     
    176184 
    177185 
     186    from matplotlib import backend_bases 
     187    backend_bases.FigureCanvasBase.filetypes.pop('pgf', None) 
     188 
    178189def run_gui(): 
    179190    """ 
     
    197208    else: 
    198209        # 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()) 
    199215        thing_to_run = sys.argv[1] 
    200216        sys.argv = sys.argv[1:] 
     
    205221            runpy.run_module(thing_to_run, run_name="__main__") 
    206222 
     223 
    207224if __name__ == "__main__": 
    208225    run_gui() 
    209  
Note: See TracChangeset for help on using the changeset viewer.