[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 |
---|
[5559171] | 45 | if sys.version_info < (2, 7): |
---|
| 46 | reload(sys) |
---|
[270cc72e] | 47 | sys.setdefaultencoding("iso-8859-1") |
---|
[fa597990] | 48 | from sans.guiframe import gui_manager |
---|
| 49 | from sans.guiframe.gui_style import GUIFRAME |
---|
| 50 | from welcome_panel import WelcomePanel |
---|
| 51 | # For py2exe, import config here |
---|
| 52 | import local_config |
---|
[19e614a] | 53 | PLUGIN_MODEL_DIR = 'plugin_models' |
---|
[c329f4d] | 54 | APP_NAME = 'SasView' |
---|
[6fe5100] | 55 | |
---|
[c329f4d] | 56 | class SasViewApp(gui_manager.ViewApp): |
---|
[fa597990] | 57 | """ |
---|
| 58 | """ |
---|
| 59 | |
---|
| 60 | |
---|
[c329f4d] | 61 | class SasView(): |
---|
[fa597990] | 62 | """ |
---|
| 63 | """ |
---|
| 64 | def __init__(self): |
---|
| 65 | """ |
---|
| 66 | """ |
---|
| 67 | #from gui_manager import ViewApp |
---|
[c329f4d] | 68 | self.gui = SasViewApp(0) |
---|
[fa597990] | 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. |
---|
[1790664] | 77 | |
---|
[fa597990] | 78 | # Fitting perspective |
---|
[d4c19e5] | 79 | try: |
---|
| 80 | import sans.perspectives.fitting as module |
---|
| 81 | fitting_plug = module.Plugin() |
---|
| 82 | self.gui.add_perspective(fitting_plug) |
---|
[df7a7e3] | 83 | except Exception as inst: |
---|
| 84 | logging.error("Fitting problems: " + str(inst)) |
---|
[10b3e1e] | 85 | logging.error("%s: could not find Fitting plug-in module"% APP_NAME) |
---|
[1790664] | 86 | logging.error(sys.exc_value) |
---|
| 87 | |
---|
[fa597990] | 88 | # P(r) perspective |
---|
| 89 | try: |
---|
| 90 | import sans.perspectives.pr as module |
---|
| 91 | pr_plug = module.Plugin(standalone=False) |
---|
| 92 | self.gui.add_perspective(pr_plug) |
---|
| 93 | except: |
---|
[10b3e1e] | 94 | logging.error("%s: could not find P(r) plug-in module"% APP_NAME) |
---|
[fa597990] | 95 | logging.error(sys.exc_value) |
---|
| 96 | |
---|
| 97 | #Invariant perspective |
---|
| 98 | try: |
---|
| 99 | import sans.perspectives.invariant as module |
---|
| 100 | invariant_plug = module.Plugin(standalone=False) |
---|
| 101 | self.gui.add_perspective(invariant_plug) |
---|
| 102 | except: |
---|
| 103 | raise |
---|
[10b3e1e] | 104 | logging.error("%s: could not find Invariant plug-in module"% \ |
---|
| 105 | APP_NAME) |
---|
[fa597990] | 106 | logging.error(sys.exc_value) |
---|
| 107 | |
---|
| 108 | #Calculator perspective |
---|
| 109 | try: |
---|
| 110 | import sans.perspectives.calculator as module |
---|
| 111 | calculator_plug = module.Plugin(standalone=False) |
---|
| 112 | self.gui.add_perspective(calculator_plug) |
---|
| 113 | except: |
---|
[10b3e1e] | 114 | logging.error("%s: could not find Calculator plug-in module"% \ |
---|
| 115 | APP_NAME) |
---|
[fa597990] | 116 | logging.error(sys.exc_value) |
---|
[334c50d] | 117 | |
---|
[d4c19e5] | 118 | |
---|
[fa597990] | 119 | # Add welcome page |
---|
| 120 | self.gui.set_welcome_panel(WelcomePanel) |
---|
| 121 | |
---|
| 122 | # Build the GUI |
---|
| 123 | self.gui.build_gui() |
---|
[19e614a] | 124 | # delete unused model folder |
---|
| 125 | self.gui.clean_plugin_models(PLUGIN_MODEL_DIR) |
---|
[fa597990] | 126 | # Start the main loop |
---|
[6fe5100] | 127 | self.gui.MainLoop() |
---|
[fa597990] | 128 | |
---|
[930f559] | 129 | |
---|
[6fe5100] | 130 | def run(): |
---|
[5e491e6] | 131 | from multiprocessing import freeze_support |
---|
| 132 | freeze_support() |
---|
[6fe5100] | 133 | if len(sys.argv) > 1: |
---|
[1790664] | 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()) |
---|
[6fe5100] | 139 | thing_to_run = sys.argv[1] |
---|
| 140 | sys.argv = sys.argv[1:] |
---|
| 141 | import runpy |
---|
| 142 | if os.path.exists(thing_to_run): |
---|
[1790664] | 143 | runpy.run_path(thing_to_run, run_name="__main__") |
---|
[6fe5100] | 144 | else: |
---|
[1790664] | 145 | runpy.run_module(thing_to_run, run_name="__main__") |
---|
[6fe5100] | 146 | else: |
---|
| 147 | SasView() |
---|
| 148 | |
---|
| 149 | if __name__ == "__main__": |
---|
| 150 | run() |
---|
[930f559] | 151 | |
---|