Changeset b963b20 in sasview for src/sas/sasgui


Ignore:
Timestamp:
Sep 24, 2017 11:29:13 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
b277220, fca1f50
Parents:
d3b0c77
Message:

pull config out of sas.sasgui so it can be used without reference to wx

Location:
src/sas/sasgui
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/__init__.py

    rc6bdb3b rb963b20  
    1 import sys 
    2 import os 
    3 from os.path import exists, expanduser, dirname, realpath, join as joinpath 
    4  
    5  
    6 def dirn(path, n): 
    7     path = realpath(path) 
    8     for _ in range(n): 
    9         path = dirname(path) 
    10     return path 
    11  
    12 # Set up config directories 
    13 def make_user_folder(): 
    14     path = joinpath(expanduser("~"),'.sasview') 
    15     if not exists(path): 
    16         os.mkdir(path) 
    17     return path 
    18  
    19  
    20 def find_app_folder(): 
    21     # We are starting out with the following info: 
    22     #     __file__ = .../sas/sasgui/__init__.pyc 
    23     # Check if the sister path .../sas/sasview exists, and use it as the 
    24     # app directory.  This will only be the case if the app is not frozen. 
    25     path = joinpath(dirn(__file__, 2), 'sasview') 
    26     if exists(path): 
    27         return path 
    28  
    29     # If we are running frozen, then root is a parent directory 
    30     if sys.platform == 'darwin': 
    31         # Here is the path to the file on the mac: 
    32         #     .../Sasview.app/Contents/Resources/lib/python2.7/site-packages.zip/sas/sasgui/__init__.pyc 
    33         # We want the path to the Resources directory. 
    34         path = dirn(__file__, 6) 
    35     elif os.name == 'nt': 
    36         # Here is the path to the file on windows: 
    37         #     ../Sasview/library.zip/sas/sasgui/__init__.pyc 
    38         # We want the path to the Sasview directory. 
    39         path = dirn(__file__, 4) 
    40     else: 
    41         raise RuntimeError("Couldn't find the app directory") 
    42     return path 
    43  
    44 USER_FOLDER = make_user_folder() 
    45 APP_FOLDER = find_app_folder() 
    46  
    47  
    48 def get_app_dir(): 
    49     return APP_FOLDER 
    50  
    51 def get_user_dir(): 
    52     return USER_FOLDER 
    53  
    54 def get_custom_config_path(): 
    55     dirname = os.path.join(get_user_dir(), 'config') 
    56     # If the directory doesn't exist, create it 
    57     if not os.path.exists(dirname): 
    58         os.makedirs(dirname) 
    59     path = os.path.join(dirname, "custom_config.py") 
    60     return path 
    61  
    62 _config_cache = None 
    63 def get_local_config(): 
    64     global _config_cache 
    65     if not _config_cache: 
    66         _config_cache = _load_config() 
    67     return _config_cache 
    68  
    69 def _load_config(): 
    70     import os 
    71     import sys 
    72     import logging 
    73     from sasmodels.custom import load_module_from_path 
    74  
    75     logger = logging.getLogger(__name__) 
    76     dirname = get_app_dir() 
    77     filename = 'local_config.py' 
    78     path = os.path.join(dirname, filename) 
    79     try: 
    80         module = load_module_from_path('sas.sasgui.local_config', path) 
    81         logger.info("GuiManager loaded %s", path) 
    82         return module 
    83     except Exception as exc: 
    84         logger.critical("Error loading %s: %s", path, exc) 
    85         sys.exit() 
  • src/sas/sasgui/guiframe/CategoryInstaller.py

    rd3b0c77 rb963b20  
    1515from collections import defaultdict, OrderedDict 
    1616 
    17 from sas.sasgui import get_user_dir 
     17from sas import get_user_dir 
    1818 
    1919USER_FILE = 'categories.json' 
  • src/sas/sasgui/guiframe/aboutbox.py

    r724af06 rb963b20  
    2525import os 
    2626 
    27 from sas.sasgui import get_local_config 
     27from sas import get_local_config 
    2828config = get_local_config() 
    2929 
  • src/sas/sasgui/guiframe/acknowledgebox.py

    r914ba0a rb963b20  
    1313from wx.lib.expando import ExpandoTextCtrl 
    1414 
    15 from sas.sasgui import get_local_config 
     15from sas import get_local_config 
    1616config = get_local_config() 
    1717 
  • src/sas/sasgui/guiframe/config.py

    r724af06 rb963b20  
    145145UPDATE_TIMEOUT = 2 
    146146 
    147 #OpenCL option 
    148 SAS_OPENCL = None 
    149  
    150147# Time out for updating sasview 
    151148UPDATE_TIMEOUT = 2 
  • src/sas/sasgui/guiframe/data_panel.py

    rc6bdb3b rb963b20  
    3333from sas.sasgui.guiframe.local_perspectives.plotting.SimplePlot \ 
    3434    import PlotFrame as QucikPlotDialog 
    35 from sas.sasgui import get_local_config 
     35from sas import get_local_config 
    3636 
    3737config = get_local_config() 
  • src/sas/sasgui/guiframe/documentation_window.py

    r724af06 rb963b20  
    2727    WX_SUPPORTS_HTML2 = False 
    2828 
    29 from sas.sasgui import get_app_dir 
     29from sas import get_app_dir 
    3030 
    3131# Don't use wx html renderer on windows. 
  • src/sas/sasgui/guiframe/gui_manager.py

    r914ba0a rb963b20  
    2828from matplotlib import _pylab_helpers 
    2929 
    30 from sas.sasgui import get_local_config, get_app_dir, get_user_dir 
     30from sas import get_local_config, get_custom_config, get_app_dir, get_user_dir 
    3131from sas.sasgui.guiframe.events import EVT_CATEGORY 
    3232from sas.sasgui.guiframe.events import EVT_STATUS 
     
    4747from sas.sascalc.dataloader.loader import Loader 
    4848from sas.sasgui.guiframe.proxy import Connection 
    49 from sas.sasgui.guiframe.customdir import setup_custom_config 
    5049 
    5150logger = logging.getLogger(__name__) 
     
    5352 
    5453config = get_local_config() 
    55 custom_config = setup_custom_config() 
     54custom_config = get_custom_config() 
    5655 
    5756# read some constants from config 
     
    6362SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT 
    6463SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME 
    65 SAS_OPENCL = config.SAS_OPENCL 
    6664if not WELCOME_PANEL_ON: 
    6765    WELCOME_PANEL_SHOW = False 
     
    138136        PARENT_FRAME = wx.Frame 
    139137        CHILD_FRAME = wx.Frame 
    140  
    141 #Initiliaze enviromental variable with custom setting but only if variable not set 
    142 if SAS_OPENCL and not "SAS_OPENCL" in os.environ: 
    143     os.environ["SAS_OPENCL"] = SAS_OPENCL 
    144138 
    145139class ViewerFrame(PARENT_FRAME): 
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py

    r759a8ab rb963b20  
    1010logger = logging.getLogger(__name__) 
    1111 
     12from sas import get_local_config 
     13 
    1214from sas.sascalc.dataloader.loader import Loader 
    1315from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
    1416 
    15 from sas.sasgui import get_local_config 
    1617from sas.sasgui.guiframe.plugin_base import PluginBase 
    1718from sas.sasgui.guiframe.events import StatusEvent 
  • src/sas/sasgui/guiframe/startup_configuration.py

    r914ba0a rb963b20  
    1313import wx 
    1414 
    15 from sas.sasgui import get_custom_config_path 
     15from sas import make_custom_config_path 
    1616from sas.sasgui.guiframe.events import StatusEvent 
    1717from sas.sasgui.guiframe.gui_style import GUIFRAME 
     
    194194        Write custom configuration 
    195195        """ 
    196         path = get_custom_config_path() 
     196        path = make_custom_config_path() 
    197197        with open(path, 'w') as out_f: 
    198198            out_f.write("#Application appearance custom configuration\n") 
Note: See TracChangeset for help on using the changeset viewer.