source: sasview/sasview/sasview.py @ 3a39c2e

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 3a39c2e was 3a39c2e, checked in by krzywon, 9 years ago

Next iteration of the SANS→SAS is complete.

  • Property mode set to 100644
File size: 5.6 KB
Line 
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################################################################################
11import os
12import logging
13from shutil import copy
14logging.basicConfig(level=logging.INFO,
15                    format='%(asctime)s %(levelname)s %(message)s',
16                    filename=os.path.join(os.path.expanduser("~"),
17                                          'sasview.log'))
18
19# Allow the dynamic selection of wxPython via an evironment variable, when devs
20# who have multiple versions of the module installed want to pick between them.
21# This variable does not have to be set of course, and through normal usage will
22# probably not be, but this can make things a little easier when upgrading to a
23# new version of wx.
24WX_ENV_VAR = "SASVIEW_WX_VERSION"
25if WX_ENV_VAR in os.environ:
26    logging.info("You have set the %s environment variable to %s." % (WX_ENV_VAR, os.environ[WX_ENV_VAR]))
27    import wxversion
28    if wxversion.checkInstalled(os.environ[WX_ENV_VAR]):
29        logging.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR])
30        wxversion.select(os.environ[WX_ENV_VAR])
31    else:
32        logging.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR])
33else:
34    logging.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR)
35
36import wx
37import sys
38# The below will make sure that sasview application uses the matplotlib font
39# bundled with sasview.
40if hasattr(sys, 'frozen'):
41    mplconfigdir = os.path.join(os.path.expanduser("~"), '.matplotlib')
42    if not os.path.exists(mplconfigdir):
43        os.mkdir(mplconfigdir)
44    os.environ['MPLCONFIGDIR'] = mplconfigdir
45    if sys.version_info < (2, 7):
46        reload(sys)
47    sys.setdefaultencoding("iso-8859-1")
48from sas.guiframe import gui_manager
49from sas.guiframe.gui_style import GUIFRAME
50from welcome_panel import WelcomePanel
51# For py2exe, import config here
52import local_config
53PLUGIN_MODEL_DIR = 'plugin_models'
54APP_NAME = 'SasView'
55
56class SasViewApp(gui_manager.ViewApp):
57    """
58    """
59 
60
61class SasView():
62    """
63    """
64    def __init__(self):
65        """
66        """
67        #from gui_manager import ViewApp
68        self.gui = SasViewApp(0) 
69        # Set the application manager for the GUI
70        self.gui.set_manager(self)
71        # Add perspectives to the basic application
72        # Additional perspectives can still be loaded
73        # dynamically
74        # Note: py2exe can't find dynamically loaded
75        # modules. We load the fitting module here
76        # to ensure a complete Windows executable build.
77
78        # Fitting perspective
79        try:
80            import sas.perspectives.fitting as module   
81            fitting_plug = module.Plugin()
82            self.gui.add_perspective(fitting_plug)
83        except Exception as inst:
84            logging.error("Fitting problems: " + str(inst))
85            logging.error("%s: could not find Fitting plug-in module"% APP_NAME) 
86            logging.error(sys.exc_value)
87
88        # P(r) perspective
89        try:
90            import sas.perspectives.pr as module   
91            pr_plug = module.Plugin(standalone=False)
92            self.gui.add_perspective(pr_plug)
93        except:
94            logging.error("%s: could not find P(r) plug-in module"% APP_NAME)
95            logging.error(sys.exc_value) 
96       
97        #Invariant perspective
98        try:
99            import sas.perspectives.invariant as module   
100            invariant_plug = module.Plugin(standalone=False)
101            self.gui.add_perspective(invariant_plug)
102        except:
103            raise
104            logging.error("%s: could not find Invariant plug-in module"% \
105                          APP_NAME)
106            logging.error(sys.exc_value) 
107       
108        #Calculator perspective   
109        try:
110            import sas.perspectives.calculator as module   
111            calculator_plug = module.Plugin(standalone=False)
112            self.gui.add_perspective(calculator_plug)
113        except:
114            logging.error("%s: could not find Calculator plug-in module"% \
115                                                        APP_NAME)
116            logging.error(sys.exc_value) 
117       
118           
119        # Add welcome page
120        self.gui.set_welcome_panel(WelcomePanel)
121     
122        # Build the GUI
123        self.gui.build_gui()
124        # delete unused model folder   
125        self.gui.clean_plugin_models(PLUGIN_MODEL_DIR)
126        # Start the main loop
127        self.gui.MainLoop()
128
129
130def run():
131    from multiprocessing import freeze_support
132    freeze_support()
133    if len(sys.argv) > 1:
134        ## Run sasview as an interactive python interpreter
135        #if sys.argv[1] == "-i":
136        #    sys.argv = ["ipython", "--pylab"]
137        #    from IPython import start_ipython
138        #    sys.exit(start_ipython())
139        thing_to_run = sys.argv[1]
140        sys.argv = sys.argv[1:]
141        import runpy
142        if os.path.exists(thing_to_run):
143            runpy.run_path(thing_to_run, run_name="__main__")
144        else:
145            runpy.run_module(thing_to_run, run_name="__main__")
146    else:
147        SasView()
148
149if __name__ == "__main__":
150    run()
151
Note: See TracBrowser for help on using the repository browser.