source: sasview/src/sas/qtgui/GuiUtils.py @ f721030

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since f721030 was f721030, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Initial commit of the main window prototype

  • Property mode set to 100755
File size: 6.7 KB
Line 
1"""
2    Global defaults and various utility functions usable by the general GUI
3"""
4
5import os
6import sys
7import time
8import imp
9import warnings
10import re
11warnings.simplefilter("ignore")
12import logging
13import traceback
14
15from PyQt4 import QtCore
16from PyQt4 import QtGui
17
18# Translate event handlers
19#from sas.sasgui.guiframe.events import EVT_CATEGORY
20#from sas.sasgui.guiframe.events import EVT_STATUS
21#from sas.sasgui.guiframe.events import EVT_APPEND_BOOKMARK
22#from sas.sasgui.guiframe.events import EVT_PANEL_ON_FOCUS
23#from sas.sasgui.guiframe.events import EVT_NEW_LOAD_DATA
24#from sas.sasgui.guiframe.events import EVT_NEW_COLOR
25#from sas.sasgui.guiframe.events import StatusEvent
26#from sas.sasgui.guiframe.events import NewPlotEvent
27
28
29def get_app_dir():
30    """
31        The application directory is the one where the default custom_config.py
32        file resides.
33
34        :returns: app_path - the path to the applicatin directory
35    """
36    # First, try the directory of the executable we are running
37    app_path = sys.path[0]
38    if os.path.isfile(app_path):
39        app_path = os.path.dirname(app_path)
40    if os.path.isfile(os.path.join(app_path, "custom_config.py")):
41        app_path = os.path.abspath(app_path)
42        logging.info("Using application path: %s", app_path)
43        return app_path
44
45    # Next, try the current working directory
46    if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")):
47        logging.info("Using application path: %s", os.getcwd())
48        return os.path.abspath(os.getcwd())
49
50    # Finally, try the directory of the sasview module
51    # TODO: gui_manager will have to know about sasview until we
52    # clean all these module variables and put them into a config class
53    # that can be passed by sasview.py.
54    logging.info(sys.executable)
55    logging.info(str(sys.argv))
56    from sas import sasview as sasview
57    app_path = os.path.dirname(sasview.__file__)
58    logging.info("Using application path: %s", app_path)
59    return app_path
60
61def get_user_directory():
62    """
63        Returns the user's home directory
64    """
65    userdir = os.path.join(os.path.expanduser("~"), ".sasview")
66    if not os.path.isdir(userdir):
67        os.makedirs(userdir)
68    return userdir
69
70def _find_local_config(file, path):
71    """
72        Find configuration file for the current application
73    """
74    config_module = None
75    fObj = None
76    try:
77        fObj, path_config, descr = imp.find_module(file, [path])
78        config_module = imp.load_module(file, fObj, path_config, descr)
79    except:
80        logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value))
81    finally:
82        if fObj is not None:
83            fObj.close()
84    logging.info("GuiManager loaded %s/%s" % (path, file))
85    return config_module
86
87# Get APP folder
88PATH_APP = get_app_dir()
89DATAPATH = PATH_APP
90
91# GUI always starts from the App folder
92#os.chdir(PATH_APP)
93# Read in the local config, which can either be with the main
94# application or in the installation directory
95config = _find_local_config('local_config', PATH_APP)
96if config is None:
97    config = _find_local_config('local_config', os.getcwd())
98    if config is None:
99        # Didn't find local config, load the default
100        import sas.sasgui.guiframe.config as config
101        logging.info("using default local_config")
102    else:
103        logging.info("found local_config in %s" % os.getcwd())
104else:
105    logging.info("found local_config in %s" % PATH_APP)
106
107
108from sas.sasgui.guiframe.customdir  import SetupCustom
109c_conf_dir = SetupCustom().setup_dir(PATH_APP)
110custom_config = _find_local_config('custom_config', c_conf_dir)
111if custom_config is None:
112    custom_config = _find_local_config('custom_config', os.getcwd())
113    if custom_config is None:
114        msgConfig = "Custom_config file was not imported"
115        logging.info(msgConfig)
116    else:
117        logging.info("using custom_config in %s" % os.getcwd())
118else:
119    logging.info("using custom_config from %s" % c_conf_dir)
120
121#read some constants from config
122APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION
123APPLICATION_NAME = config.__appname__
124SPLASH_SCREEN_PATH = config.SPLASH_SCREEN_PATH
125WELCOME_PANEL_ON = config.WELCOME_PANEL_ON
126SPLASH_SCREEN_WIDTH = config.SPLASH_SCREEN_WIDTH
127SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT
128SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME
129if not WELCOME_PANEL_ON:
130    WELCOME_PANEL_SHOW = False
131else:
132    WELCOME_PANEL_SHOW = True
133try:
134    DATALOADER_SHOW = custom_config.DATALOADER_SHOW
135    TOOLBAR_SHOW = custom_config.TOOLBAR_SHOW
136    FIXED_PANEL = custom_config.FIXED_PANEL
137    if WELCOME_PANEL_ON:
138        WELCOME_PANEL_SHOW = custom_config.WELCOME_PANEL_SHOW
139    PLOPANEL_WIDTH = custom_config.PLOPANEL_WIDTH
140    DATAPANEL_WIDTH = custom_config.DATAPANEL_WIDTH
141    GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH
142    GUIFRAME_HEIGHT = custom_config.GUIFRAME_HEIGHT
143    CONTROL_WIDTH = custom_config.CONTROL_WIDTH
144    CONTROL_HEIGHT = custom_config.CONTROL_HEIGHT
145    DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE
146    CLEANUP_PLOT = custom_config.CLEANUP_PLOT
147    # custom open_path
148    open_folder = custom_config.DEFAULT_OPEN_FOLDER
149    if open_folder != None and os.path.isdir(open_folder):
150        DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder)
151    else:
152        DEFAULT_OPEN_FOLDER = PATH_APP
153except:
154    DATALOADER_SHOW = True
155    TOOLBAR_SHOW = True
156    FIXED_PANEL = True
157    WELCOME_PANEL_SHOW = False
158    PLOPANEL_WIDTH = config.PLOPANEL_WIDTH
159    DATAPANEL_WIDTH = config.DATAPANEL_WIDTH
160    GUIFRAME_WIDTH = config.GUIFRAME_WIDTH
161    GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT
162    CONTROL_WIDTH = -1
163    CONTROL_HEIGHT = -1
164    DEFAULT_PERSPECTIVE = None
165    CLEANUP_PLOT = False
166    DEFAULT_OPEN_FOLDER = PATH_APP
167
168DEFAULT_STYLE = config.DEFAULT_STYLE
169
170PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS
171OPEN_SAVE_MENU = config.OPEN_SAVE_PROJECT_MENU
172VIEW_MENU = config.VIEW_MENU
173EDIT_MENU = config.EDIT_MENU
174extension_list = []
175if APPLICATION_STATE_EXTENSION is not None:
176    extension_list.append(APPLICATION_STATE_EXTENSION)
177EXTENSIONS = PLUGIN_STATE_EXTENSIONS + extension_list
178try:
179    PLUGINS_WLIST = '|'.join(config.PLUGINS_WLIST)
180except:
181    PLUGINS_WLIST = ''
182APPLICATION_WLIST = config.APPLICATION_WLIST
183IS_WIN = True
184IS_LINUX = False
185CLOSE_SHOW = True
186TIME_FACTOR = 2
187NOT_SO_GRAPH_LIST = ["BoxSum"]
188
189class Communicate(QtCore.QObject):
190    """
191    Utility class for tracking of the Qt signals
192    """
193    # File got successfully read
194    fileReadSignal = QtCore.pyqtSignal(list)
195
196    # Open File returns "list" of paths
197    fileDataReceivedSignal = QtCore.pyqtSignal(dict)
198
199    # Update Main window status bar with "str"
200    statusBarUpdateSignal = QtCore.pyqtSignal(str)
201
202    # Send data to the current perspective
203    updatePerspectiveWithDataSignal = QtCore.pyqtSignal(list)
Note: See TracBrowser for help on using the repository browser.