[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] | 11 | import os |
---|
| 12 | import logging |
---|
[df7a7e3] | 13 | from shutil import copy |
---|
[6bdf6ae] | 14 | logging.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 | |
---|
[ec3bd65] | 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. |
---|
| 24 | WX_ENV_VAR = "SASVIEW_WX_VERSION" |
---|
| 25 | if 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]) |
---|
| 33 | else: |
---|
[55cc5cf] | 34 | logging.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR) |
---|
[ec3bd65] | 35 | |
---|
[fa597990] | 36 | import wx |
---|
| 37 | import sys |
---|
[c329f4d] | 38 | # The below will make sure that sasview application uses the matplotlib font |
---|
| 39 | # bundled with sasview. |
---|
[fa597990] | 40 | if hasattr(sys, 'frozen'): |
---|
[709b1dc] | 41 | mplconfigdir = os.path.join(os.path.expanduser("~"), '.matplotlib') |
---|
[fa597990] | 42 | if not os.path.exists(mplconfigdir): |
---|
| 43 | os.mkdir(mplconfigdir) |
---|
| 44 | os.environ['MPLCONFIGDIR'] = mplconfigdir |
---|
[caf3baa6] | 45 | reload(sys) |
---|
[270cc72e] | 46 | sys.setdefaultencoding("iso-8859-1") |
---|
[3a39c2e] | 47 | from sas.guiframe import gui_manager |
---|
| 48 | from sas.guiframe.gui_style import GUIFRAME |
---|
[fa597990] | 49 | from welcome_panel import WelcomePanel |
---|
| 50 | # For py2exe, import config here |
---|
| 51 | import local_config |
---|
[19e614a] | 52 | PLUGIN_MODEL_DIR = 'plugin_models' |
---|
[c329f4d] | 53 | APP_NAME = 'SasView' |
---|
[6fe5100] | 54 | |
---|
[c329f4d] | 55 | class SasViewApp(gui_manager.ViewApp): |
---|
[fa597990] | 56 | """ |
---|
| 57 | """ |
---|
| 58 | |
---|
| 59 | |
---|
[c329f4d] | 60 | class SasView(): |
---|
[fa597990] | 61 | """ |
---|
| 62 | """ |
---|
| 63 | def __init__(self): |
---|
| 64 | """ |
---|
| 65 | """ |
---|
| 66 | #from gui_manager import ViewApp |
---|
[c329f4d] | 67 | self.gui = SasViewApp(0) |
---|
[fa597990] | 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. |
---|
[1790664] | 76 | |
---|
[fa597990] | 77 | # Fitting perspective |
---|
[d4c19e5] | 78 | try: |
---|
[3a39c2e] | 79 | import sas.perspectives.fitting as module |
---|
[d4c19e5] | 80 | fitting_plug = module.Plugin() |
---|
| 81 | self.gui.add_perspective(fitting_plug) |
---|
[df7a7e3] | 82 | except Exception as inst: |
---|
| 83 | logging.error("Fitting problems: " + str(inst)) |
---|
[10b3e1e] | 84 | logging.error("%s: could not find Fitting plug-in module"% APP_NAME) |
---|
[1790664] | 85 | logging.error(sys.exc_value) |
---|
| 86 | |
---|
[fa597990] | 87 | # P(r) perspective |
---|
| 88 | try: |
---|
[3a39c2e] | 89 | import sas.perspectives.pr as module |
---|
[fa597990] | 90 | pr_plug = module.Plugin(standalone=False) |
---|
| 91 | self.gui.add_perspective(pr_plug) |
---|
| 92 | except: |
---|
[10b3e1e] | 93 | logging.error("%s: could not find P(r) plug-in module"% APP_NAME) |
---|
[fa597990] | 94 | logging.error(sys.exc_value) |
---|
| 95 | |
---|
| 96 | #Invariant perspective |
---|
| 97 | try: |
---|
[3a39c2e] | 98 | import sas.perspectives.invariant as module |
---|
[fa597990] | 99 | invariant_plug = module.Plugin(standalone=False) |
---|
| 100 | self.gui.add_perspective(invariant_plug) |
---|
| 101 | except: |
---|
| 102 | raise |
---|
[10b3e1e] | 103 | logging.error("%s: could not find Invariant plug-in module"% \ |
---|
| 104 | APP_NAME) |
---|
[fa597990] | 105 | logging.error(sys.exc_value) |
---|
| 106 | |
---|
| 107 | #Calculator perspective |
---|
| 108 | try: |
---|
[3a39c2e] | 109 | import sas.perspectives.calculator as module |
---|
[fa597990] | 110 | calculator_plug = module.Plugin(standalone=False) |
---|
| 111 | self.gui.add_perspective(calculator_plug) |
---|
| 112 | except: |
---|
[10b3e1e] | 113 | logging.error("%s: could not find Calculator plug-in module"% \ |
---|
| 114 | APP_NAME) |
---|
[fa597990] | 115 | logging.error(sys.exc_value) |
---|
[334c50d] | 116 | |
---|
[d4c19e5] | 117 | |
---|
[fa597990] | 118 | # Add welcome page |
---|
| 119 | self.gui.set_welcome_panel(WelcomePanel) |
---|
| 120 | |
---|
| 121 | # Build the GUI |
---|
| 122 | self.gui.build_gui() |
---|
[19e614a] | 123 | # delete unused model folder |
---|
| 124 | self.gui.clean_plugin_models(PLUGIN_MODEL_DIR) |
---|
[fa597990] | 125 | # Start the main loop |
---|
[6fe5100] | 126 | self.gui.MainLoop() |
---|
[fa597990] | 127 | |
---|
[930f559] | 128 | |
---|
[6fe5100] | 129 | def run(): |
---|
[5e491e6] | 130 | from multiprocessing import freeze_support |
---|
| 131 | freeze_support() |
---|
[6fe5100] | 132 | if len(sys.argv) > 1: |
---|
[1790664] | 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()) |
---|
[6fe5100] | 138 | thing_to_run = sys.argv[1] |
---|
| 139 | sys.argv = sys.argv[1:] |
---|
| 140 | import runpy |
---|
| 141 | if os.path.exists(thing_to_run): |
---|
[1790664] | 142 | runpy.run_path(thing_to_run, run_name="__main__") |
---|
[6fe5100] | 143 | else: |
---|
[1790664] | 144 | runpy.run_module(thing_to_run, run_name="__main__") |
---|
[6fe5100] | 145 | else: |
---|
| 146 | SasView() |
---|
| 147 | |
---|
| 148 | if __name__ == "__main__": |
---|
| 149 | run() |
---|
[930f559] | 150 | |
---|