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("~"),'sasview.log')) |
---|
17 | |
---|
18 | import wx |
---|
19 | import sys |
---|
20 | # The below will make sure that sasview application uses the matplotlib font |
---|
21 | # bundled with sasview. |
---|
22 | if hasattr(sys, 'frozen'): |
---|
23 | mplconfigdir = os.path.join(os.path.expanduser("~"), '.matplotlib') |
---|
24 | if not os.path.exists(mplconfigdir): |
---|
25 | os.mkdir(mplconfigdir) |
---|
26 | os.environ['MPLCONFIGDIR'] = mplconfigdir |
---|
27 | if sys.version_info < (2, 7): |
---|
28 | reload(sys) |
---|
29 | sys.setdefaultencoding("iso-8859-1") |
---|
30 | from sans.guiframe import gui_manager |
---|
31 | from sans.guiframe.gui_style import GUIFRAME |
---|
32 | from welcome_panel import WelcomePanel |
---|
33 | # For py2exe, import config here |
---|
34 | import local_config |
---|
35 | PLUGIN_MODEL_DIR = 'plugin_models' |
---|
36 | APP_NAME = 'SasView' |
---|
37 | def run(): |
---|
38 | sys.path.append(os.path.join("..","..","..")) |
---|
39 | from multiprocessing import freeze_support |
---|
40 | freeze_support() |
---|
41 | sasview = SasView() |
---|
42 | |
---|
43 | class SasViewApp(gui_manager.ViewApp): |
---|
44 | """ |
---|
45 | """ |
---|
46 | |
---|
47 | |
---|
48 | class SasView(): |
---|
49 | """ |
---|
50 | """ |
---|
51 | def __init__(self): |
---|
52 | """ |
---|
53 | """ |
---|
54 | #from gui_manager import ViewApp |
---|
55 | self.gui = SasViewApp(0) |
---|
56 | # Set the application manager for the GUI |
---|
57 | self.gui.set_manager(self) |
---|
58 | # Add perspectives to the basic application |
---|
59 | # Additional perspectives can still be loaded |
---|
60 | # dynamically |
---|
61 | # Note: py2exe can't find dynamically loaded |
---|
62 | # modules. We load the fitting module here |
---|
63 | # to ensure a complete Windows executable build. |
---|
64 | |
---|
65 | # Fitting perspective |
---|
66 | try: |
---|
67 | import sans.perspectives.fitting as module |
---|
68 | fitting_plug = module.Plugin() |
---|
69 | self.gui.add_perspective(fitting_plug) |
---|
70 | except Exception as inst: |
---|
71 | logging.error("Fitting problems: " + str(inst)) |
---|
72 | logging.error("%s: could not find Fitting plug-in module"% APP_NAME) |
---|
73 | logging.error(sys.exc_value) |
---|
74 | |
---|
75 | # P(r) perspective |
---|
76 | try: |
---|
77 | import sans.perspectives.pr as module |
---|
78 | pr_plug = module.Plugin(standalone=False) |
---|
79 | self.gui.add_perspective(pr_plug) |
---|
80 | except: |
---|
81 | logging.error("%s: could not find P(r) plug-in module"% APP_NAME) |
---|
82 | logging.error(sys.exc_value) |
---|
83 | |
---|
84 | #Invariant perspective |
---|
85 | try: |
---|
86 | import sans.perspectives.invariant as module |
---|
87 | invariant_plug = module.Plugin(standalone=False) |
---|
88 | self.gui.add_perspective(invariant_plug) |
---|
89 | except: |
---|
90 | raise |
---|
91 | logging.error("%s: could not find Invariant plug-in module"% \ |
---|
92 | APP_NAME) |
---|
93 | logging.error(sys.exc_value) |
---|
94 | |
---|
95 | #Calculator perspective |
---|
96 | try: |
---|
97 | import sans.perspectives.calculator as module |
---|
98 | calculator_plug = module.Plugin(standalone=False) |
---|
99 | self.gui.add_perspective(calculator_plug) |
---|
100 | except: |
---|
101 | logging.error("%s: could not find Calculator plug-in module"% \ |
---|
102 | APP_NAME) |
---|
103 | logging.error(sys.exc_value) |
---|
104 | |
---|
105 | # initialize category stuff |
---|
106 | user_file = os.path.join(os.path.expanduser("~"), |
---|
107 | 'serialized_categories.p') |
---|
108 | |
---|
109 | if not os.path.isfile(user_file): |
---|
110 | # either first time starting sansview or the |
---|
111 | # user has deleted their category file |
---|
112 | my_dir = os.path.dirname(os.path.abspath(__file__)) |
---|
113 | default_file = os.path.join(my_dir, '..', |
---|
114 | 'sansmodels', |
---|
115 | 'default_categories.p' ) |
---|
116 | copy(default_file, user_file) |
---|
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 | |
---|
130 | |
---|
131 | if __name__ == "__main__": |
---|
132 | from multiprocessing import freeze_support |
---|
133 | freeze_support() |
---|
134 | #Process(target=SasView).start() |
---|
135 | sasview = SasView() |
---|
136 | |
---|
137 | |
---|