source: sasview/sansview/sansview.py @ 38a8c4c

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.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 38a8c4c was 1790664, checked in by pkienzle, 10 years ago

include exception details in sasview.log; run scripts as main

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[fa597990]1
2################################################################################
3#This software was developed by the University of Tennessee as part of the
4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
5#project funded by the US National Science Foundation.
6#
7#See the license text in license.txt
8#
9#copyright 2009, University of Tennessee
10################################################################################
[6bdf6ae]11import os
12import logging
[df7a7e3]13from shutil import copy
[6bdf6ae]14logging.basicConfig(level=logging.INFO,
15                    format='%(asctime)s %(levelname)s %(message)s',
[ea5fa58]16                    filename=os.path.join(os.path.expanduser("~"),
17                                          'sasview.log'))
[fa597990]18
19import wx
20import sys
[c329f4d]21# The below will make sure that sasview application uses the matplotlib font
22# bundled with sasview.
[fa597990]23if hasattr(sys, 'frozen'):
[709b1dc]24    mplconfigdir = os.path.join(os.path.expanduser("~"), '.matplotlib')
[fa597990]25    if not os.path.exists(mplconfigdir):
26        os.mkdir(mplconfigdir)
27    os.environ['MPLCONFIGDIR'] = mplconfigdir
[5559171]28    if sys.version_info < (2, 7):
29        reload(sys)
[270cc72e]30    sys.setdefaultencoding("iso-8859-1")
[fa597990]31from sans.guiframe import gui_manager
32from sans.guiframe.gui_style import GUIFRAME
33from welcome_panel import WelcomePanel
34# For py2exe, import config here
35import local_config
[19e614a]36PLUGIN_MODEL_DIR = 'plugin_models'
[c329f4d]37APP_NAME = 'SasView'
[6fe5100]38
[c329f4d]39class SasViewApp(gui_manager.ViewApp):
[fa597990]40    """
41    """
42 
43
[c329f4d]44class SasView():
[fa597990]45    """
46    """
47    def __init__(self):
48        """
49        """
50        #from gui_manager import ViewApp
[c329f4d]51        self.gui = SasViewApp(0) 
[fa597990]52        # Set the application manager for the GUI
53        self.gui.set_manager(self)
54        # Add perspectives to the basic application
55        # Additional perspectives can still be loaded
56        # dynamically
57        # Note: py2exe can't find dynamically loaded
58        # modules. We load the fitting module here
59        # to ensure a complete Windows executable build.
[1790664]60
[fa597990]61        # Fitting perspective
[d4c19e5]62        try:
63            import sans.perspectives.fitting as module   
64            fitting_plug = module.Plugin()
65            self.gui.add_perspective(fitting_plug)
[df7a7e3]66        except Exception as inst:
67            logging.error("Fitting problems: " + str(inst))
[10b3e1e]68            logging.error("%s: could not find Fitting plug-in module"% APP_NAME) 
[1790664]69            logging.error(sys.exc_value)
70
[fa597990]71        # P(r) perspective
72        try:
73            import sans.perspectives.pr as module   
74            pr_plug = module.Plugin(standalone=False)
75            self.gui.add_perspective(pr_plug)
76        except:
[10b3e1e]77            logging.error("%s: could not find P(r) plug-in module"% APP_NAME)
[fa597990]78            logging.error(sys.exc_value) 
79       
80        #Invariant perspective
81        try:
82            import sans.perspectives.invariant as module   
83            invariant_plug = module.Plugin(standalone=False)
84            self.gui.add_perspective(invariant_plug)
85        except:
86            raise
[10b3e1e]87            logging.error("%s: could not find Invariant plug-in module"% \
88                          APP_NAME)
[fa597990]89            logging.error(sys.exc_value) 
90       
91        #Calculator perspective   
92        try:
93            import sans.perspectives.calculator as module   
94            calculator_plug = module.Plugin(standalone=False)
95            self.gui.add_perspective(calculator_plug)
96        except:
[10b3e1e]97            logging.error("%s: could not find Calculator plug-in module"% \
98                                                        APP_NAME)
[fa597990]99            logging.error(sys.exc_value) 
[334c50d]100       
[d4c19e5]101           
[fa597990]102        # Add welcome page
103        self.gui.set_welcome_panel(WelcomePanel)
104     
105        # Build the GUI
106        self.gui.build_gui()
[19e614a]107        # delete unused model folder   
108        self.gui.clean_plugin_models(PLUGIN_MODEL_DIR)
[fa597990]109        # Start the main loop
[6fe5100]110        self.gui.MainLoop()
[fa597990]111
[930f559]112
[6fe5100]113def run():
[5e491e6]114    from multiprocessing import freeze_support
115    freeze_support()
[6fe5100]116    if len(sys.argv) > 1:
[1790664]117        ## Run sasview as an interactive python interpreter
118        #if sys.argv[1] == "-i":
119        #    sys.argv = ["ipython", "--pylab"]
120        #    from IPython import start_ipython
121        #    sys.exit(start_ipython())
[6fe5100]122        thing_to_run = sys.argv[1]
123        sys.argv = sys.argv[1:]
124        import runpy
125        if os.path.exists(thing_to_run):
[1790664]126            runpy.run_path(thing_to_run, run_name="__main__")
[6fe5100]127        else:
[1790664]128            runpy.run_module(thing_to_run, run_name="__main__")
[6fe5100]129    else:
130        SasView()
131
132if __name__ == "__main__":
133    run()
[930f559]134
Note: See TracBrowser for help on using the repository browser.