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 | ################################################################################ |
---|
11 | import os |
---|
12 | import logging |
---|
13 | from shutil import copy |
---|
14 | logging.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 | import wx |
---|
20 | import sys |
---|
21 | # The below will make sure that sasview application uses the matplotlib font |
---|
22 | # bundled with sasview. |
---|
23 | if hasattr(sys, 'frozen'): |
---|
24 | mplconfigdir = os.path.join(os.path.expanduser("~"), '.matplotlib') |
---|
25 | if not os.path.exists(mplconfigdir): |
---|
26 | os.mkdir(mplconfigdir) |
---|
27 | os.environ['MPLCONFIGDIR'] = mplconfigdir |
---|
28 | if sys.version_info < (2, 7): |
---|
29 | reload(sys) |
---|
30 | sys.setdefaultencoding("iso-8859-1") |
---|
31 | from sans.guiframe import gui_manager |
---|
32 | from sans.guiframe.gui_style import GUIFRAME |
---|
33 | from welcome_panel import WelcomePanel |
---|
34 | # For py2exe, import config here |
---|
35 | import local_config |
---|
36 | PLUGIN_MODEL_DIR = 'plugin_models' |
---|
37 | APP_NAME = 'SasView' |
---|
38 | |
---|
39 | class SasViewApp(gui_manager.ViewApp): |
---|
40 | """ |
---|
41 | """ |
---|
42 | |
---|
43 | |
---|
44 | class SasView(): |
---|
45 | """ |
---|
46 | """ |
---|
47 | def __init__(self): |
---|
48 | """ |
---|
49 | """ |
---|
50 | #from gui_manager import ViewApp |
---|
51 | self.gui = SasViewApp(0) |
---|
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. |
---|
60 | |
---|
61 | # Fitting perspective |
---|
62 | try: |
---|
63 | import sans.perspectives.fitting as module |
---|
64 | fitting_plug = module.Plugin() |
---|
65 | self.gui.add_perspective(fitting_plug) |
---|
66 | except Exception as inst: |
---|
67 | logging.error("Fitting problems: " + str(inst)) |
---|
68 | logging.error("%s: could not find Fitting plug-in module"% APP_NAME) |
---|
69 | logging.error(sys.exc_value) |
---|
70 | |
---|
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: |
---|
77 | logging.error("%s: could not find P(r) plug-in module"% APP_NAME) |
---|
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 |
---|
87 | logging.error("%s: could not find Invariant plug-in module"% \ |
---|
88 | APP_NAME) |
---|
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: |
---|
97 | logging.error("%s: could not find Calculator plug-in module"% \ |
---|
98 | APP_NAME) |
---|
99 | logging.error(sys.exc_value) |
---|
100 | |
---|
101 | |
---|
102 | # Add welcome page |
---|
103 | self.gui.set_welcome_panel(WelcomePanel) |
---|
104 | |
---|
105 | # Build the GUI |
---|
106 | self.gui.build_gui() |
---|
107 | # delete unused model folder |
---|
108 | self.gui.clean_plugin_models(PLUGIN_MODEL_DIR) |
---|
109 | # Start the main loop |
---|
110 | self.gui.MainLoop() |
---|
111 | |
---|
112 | |
---|
113 | def run(): |
---|
114 | from multiprocessing import freeze_support |
---|
115 | freeze_support() |
---|
116 | if len(sys.argv) > 1: |
---|
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()) |
---|
122 | thing_to_run = sys.argv[1] |
---|
123 | sys.argv = sys.argv[1:] |
---|
124 | import runpy |
---|
125 | if os.path.exists(thing_to_run): |
---|
126 | runpy.run_path(thing_to_run, run_name="__main__") |
---|
127 | else: |
---|
128 | runpy.run_module(thing_to_run, run_name="__main__") |
---|
129 | else: |
---|
130 | SasView() |
---|
131 | |
---|
132 | if __name__ == "__main__": |
---|
133 | run() |
---|
134 | |
---|