Changeset 80c2c85 in sasview for src/sas/sasview/sasview.py


Ignore:
Timestamp:
Jun 28, 2016 3:10:33 PM (8 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:
3aa2f3c
Parents:
899e084 (diff), 5552396 (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 branch 'master' into sasview-cleanup

File:
1 moved

Legend:

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

    r1be5202 r899e084  
    1616import traceback 
    1717 
    18 logging.basicConfig(level=logging.INFO, 
    19                     format='%(asctime)s %(levelname)s %(message)s', 
    20                     filename=os.path.join(os.path.expanduser("~"), 
    21                                           'sasview.log')) 
    22 logging.captureWarnings(True) 
     18 
     19reload(sys) 
     20sys.setdefaultencoding("iso-8859-1") 
     21 
    2322 
    2423class StreamToLogger(object): 
     
    4039            self.logger.log(self.log_level, line.rstrip()) 
    4140 
    42 stderr_logger = logging.getLogger('STDERR') 
    43 sl = StreamToLogger(stderr_logger, logging.ERROR) 
    44 sys.stderr = sl 
    45  
    46 # Log the start of the session 
    47 logging.info(" --- SasView session started ---") 
    48  
    49 # Log the python version 
    50 logging.info("Python: %s" % sys.version) 
    51  
    52 # Allow the dynamic selection of wxPython via an environment variable, when devs 
    53 # who have multiple versions of the module installed want to pick between them. 
    54 # This variable does not have to be set of course, and through normal usage will 
    55 # probably not be, but this can make things a little easier when upgrading to a 
    56 # new version of wx. 
    57 WX_ENV_VAR = "SASVIEW_WX_VERSION" 
    58 if WX_ENV_VAR in os.environ: 
    59     logging.info("You have set the %s environment variable to %s." % \ 
    60                  (WX_ENV_VAR, os.environ[WX_ENV_VAR])) 
    61     import wxversion 
    62     if wxversion.checkInstalled(os.environ[WX_ENV_VAR]): 
    63         logging.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR]) 
    64         wxversion.select(os.environ[WX_ENV_VAR]) 
    65     else: 
    66         logging.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR]) 
    67 else: 
    68     logging.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR) 
    69  
    70 import wx 
    71  
    72 try: 
    73     logging.info("Wx version: %s" % wx.__version__) 
    74 except: 
    75     logging.error("Wx version: error reading version") 
    76  
    77 import wxcruft 
    78 wxcruft.call_later_fix() 
    79 #wxcruft.trace_new_id() 
    80  
    81 #Always use private .matplotlib setup to avoid conflicts with other 
    82 #uses of matplotlib 
    83 #Have to check if .sasview exists first  
    84 sasdir = os.path.join(os.path.expanduser("~"),'.sasview') 
    85 if not os.path.exists(sasdir): 
    86     os.mkdir(sasdir) 
    87 mplconfigdir = os.path.join(os.path.expanduser("~"),'.sasview','.matplotlib') 
    88 if not os.path.exists(mplconfigdir): 
    89     os.mkdir(mplconfigdir) 
    90 os.environ['MPLCONFIGDIR'] = mplconfigdir 
    91 reload(sys) 
    92 sys.setdefaultencoding("iso-8859-1") 
    93 from sas.sasgui.guiframe import gui_manager 
    94 from sas.sasgui.guiframe.gui_style import GUIFRAME 
    95 from welcome_panel import WelcomePanel 
    96 # For py2exe, import config here 
    97 import local_config 
    9841PLUGIN_MODEL_DIR = 'plugin_models' 
    9942APP_NAME = 'SasView' 
     
    10649        """ 
    10750        """ 
    108         #from gui_manager import ViewApp 
    109         self.gui = gui_manager.SasViewApp(0) 
     51        from sas.sasgui.guiframe.gui_manager import SasViewApp 
     52        self.gui = SasViewApp(0) 
    11053        # Set the application manager for the GUI 
    11154        self.gui.set_manager(self) 
     
    11962        # Fitting perspective 
    12063        try: 
    121             import sas.sasgui.perspectives.fitting as module     
     64            import sas.sasgui.perspectives.fitting as module 
    12265            fitting_plug = module.Plugin() 
    12366            self.gui.add_perspective(fitting_plug) 
     
    14588            logging.error(traceback.format_exc()) 
    14689 
    147         #Calculator perspective    
     90        #Calculator perspective 
    14891        try: 
    14992            import sas.sasgui.perspectives.calculator as module 
     
    157100 
    158101        # Add welcome page 
     102        from .welcome_panel import WelcomePanel 
    159103        self.gui.set_welcome_panel(WelcomePanel) 
    160104 
     
    167111 
    168112 
    169 def run(): 
     113def setup_logging(): 
     114    log_file = os.path.join(os.path.expanduser("~"), 'sasview.log') 
     115    logging.basicConfig(level=logging.INFO, 
     116                        format='%(asctime)s %(levelname)s %(message)s', 
     117                        filename=log_file, 
     118                        ) 
     119    logging.captureWarnings(True) 
     120 
     121    stderr_logger = logging.getLogger('STDERR') 
     122    sl = StreamToLogger(stderr_logger, logging.ERROR) 
     123    sys.stderr = sl 
     124 
     125    # Log the start of the session 
     126    logging.info(" --- SasView session started ---") 
     127 
     128    # Log the python version 
     129    logging.info("Python: %s" % sys.version) 
     130 
     131 
     132def setup_wx(): 
     133    # Allow the dynamic selection of wxPython via an environment variable, when devs 
     134    # who have multiple versions of the module installed want to pick between them. 
     135    # This variable does not have to be set of course, and through normal usage will 
     136    # probably not be, but this can make things a little easier when upgrading to a 
     137    # new version of wx. 
     138    WX_ENV_VAR = "SASVIEW_WX_VERSION" 
     139    if WX_ENV_VAR in os.environ: 
     140        logging.info("You have set the %s environment variable to %s." % \ 
     141                     (WX_ENV_VAR, os.environ[WX_ENV_VAR])) 
     142        import wxversion 
     143        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]) 
     145            wxversion.select(os.environ[WX_ENV_VAR]) 
     146        else: 
     147            logging.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR]) 
     148    else: 
     149        logging.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR) 
     150 
     151    import wx 
     152 
     153    try: 
     154        logging.info("Wx version: %s" % wx.__version__) 
     155    except: 
     156        logging.error("Wx version: error reading version") 
     157 
     158    from . import wxcruft 
     159    wxcruft.call_later_fix() 
     160    #wxcruft.trace_new_id() 
     161    #Always use private .matplotlib setup to avoid conflicts with other 
     162    #uses of matplotlib 
     163 
     164 
     165def setup_mpl(): 
     166    import sas.sasgui 
     167    mplconfigdir = os.path.join(sas.sasgui.get_user_dir(), '.matplotlib') 
     168    if not os.path.exists(mplconfigdir): 
     169        os.mkdir(mplconfigdir) 
     170    os.environ['MPLCONFIGDIR'] = mplconfigdir 
     171    # Set backend to WXAgg; this overrides matplotlibrc, but shouldn't override 
     172    # mpl.use().  Note: Don't import matplotlib here since the script that 
     173    # we are running may not actually need it; also, putting as little on the 
     174    # path as we can 
     175    os.environ['MPLBACKEND'] = 'WXAgg' 
     176 
     177 
     178def run_gui(): 
    170179    """ 
    171180    __main__ method for loading and running SasView 
     
    173182    from multiprocessing import freeze_support 
    174183    freeze_support() 
    175     if len(sys.argv) > 1: 
    176         ## Run sasview as an interactive python interpreter 
    177         #if sys.argv[1] == "-i": 
    178         #    sys.argv = ["ipython", "--pylab"] 
    179         #    from IPython import start_ipython 
    180         #    sys.exit(start_ipython()) 
     184    setup_logging() 
     185    setup_wx() 
     186    setup_mpl() 
     187    SasView() 
     188 
     189 
     190def run_cli(): 
     191    setup_mpl() 
     192    if len(sys.argv) == 1: 
     193        # Run sasview as an interactive python interpreter 
     194        sys.argv = ["ipython", "--pylab"] 
     195        from IPython import start_ipython 
     196        sys.exit(start_ipython()) 
     197    else: 
     198        # Run sasview as a python script interpreter 
    181199        thing_to_run = sys.argv[1] 
    182200        sys.argv = sys.argv[1:] 
     
    186204        else: 
    187205            runpy.run_module(thing_to_run, run_name="__main__") 
    188     else: 
    189         SasView() 
    190206 
    191207if __name__ == "__main__": 
    192     run() 
    193  
     208    run_gui() 
     209 
Note: See TracChangeset for help on using the changeset viewer.