source: sasview/sasview/sasview.py @ caf3baa6

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 caf3baa6 was caf3baa6, checked in by Mathieu Doucet <doucetm@…>, 9 years ago

Remove crud that prevented sasview from starting as an OSX app

  • Property mode set to 100644
File size: 5.5 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    reload(sys)
46    sys.setdefaultencoding("iso-8859-1")
47from sas.guiframe import gui_manager
48from sas.guiframe.gui_style import GUIFRAME
49from welcome_panel import WelcomePanel
50# For py2exe, import config here
51import local_config
52PLUGIN_MODEL_DIR = 'plugin_models'
53APP_NAME = 'SasView'
54
55class SasViewApp(gui_manager.ViewApp):
56    """
57    """
58 
59
60class SasView():
61    """
62    """
63    def __init__(self):
64        """
65        """
66        #from gui_manager import ViewApp
67        self.gui = SasViewApp(0) 
68        # Set the application manager for the GUI
69        self.gui.set_manager(self)
70        # Add perspectives to the basic application
71        # Additional perspectives can still be loaded
72        # dynamically
73        # Note: py2exe can't find dynamically loaded
74        # modules. We load the fitting module here
75        # to ensure a complete Windows executable build.
76
77        # Fitting perspective
78        try:
79            import sas.perspectives.fitting as module   
80            fitting_plug = module.Plugin()
81            self.gui.add_perspective(fitting_plug)
82        except Exception as inst:
83            logging.error("Fitting problems: " + str(inst))
84            logging.error("%s: could not find Fitting plug-in module"% APP_NAME) 
85            logging.error(sys.exc_value)
86
87        # P(r) perspective
88        try:
89            import sas.perspectives.pr as module   
90            pr_plug = module.Plugin(standalone=False)
91            self.gui.add_perspective(pr_plug)
92        except:
93            logging.error("%s: could not find P(r) plug-in module"% APP_NAME)
94            logging.error(sys.exc_value) 
95       
96        #Invariant perspective
97        try:
98            import sas.perspectives.invariant as module   
99            invariant_plug = module.Plugin(standalone=False)
100            self.gui.add_perspective(invariant_plug)
101        except:
102            raise
103            logging.error("%s: could not find Invariant plug-in module"% \
104                          APP_NAME)
105            logging.error(sys.exc_value) 
106       
107        #Calculator perspective   
108        try:
109            import sas.perspectives.calculator as module   
110            calculator_plug = module.Plugin(standalone=False)
111            self.gui.add_perspective(calculator_plug)
112        except:
113            logging.error("%s: could not find Calculator plug-in module"% \
114                                                        APP_NAME)
115            logging.error(sys.exc_value) 
116       
117           
118        # Add welcome page
119        self.gui.set_welcome_panel(WelcomePanel)
120     
121        # Build the GUI
122        self.gui.build_gui()
123        # delete unused model folder   
124        self.gui.clean_plugin_models(PLUGIN_MODEL_DIR)
125        # Start the main loop
126        self.gui.MainLoop()
127
128
129def run():
130    from multiprocessing import freeze_support
131    freeze_support()
132    if len(sys.argv) > 1:
133        ## Run sasview as an interactive python interpreter
134        #if sys.argv[1] == "-i":
135        #    sys.argv = ["ipython", "--pylab"]
136        #    from IPython import start_ipython
137        #    sys.exit(start_ipython())
138        thing_to_run = sys.argv[1]
139        sys.argv = sys.argv[1:]
140        import runpy
141        if os.path.exists(thing_to_run):
142            runpy.run_path(thing_to_run, run_name="__main__")
143        else:
144            runpy.run_module(thing_to_run, run_name="__main__")
145    else:
146        SasView()
147
148if __name__ == "__main__":
149    run()
150
Note: See TracBrowser for help on using the repository browser.