def apply_runtime_settings(override_debug=False): """Apply runtime settings, can and needs to be called only once""" global __apply_lock__, SETTINGS_APPLIED if not __apply_lock__ and not SETTINGS_APPLIED: __apply_lock__ = True # Get command line arguments global ARGS ARGS = _parse_args() # Set gui flag global GUI_MODE GUI_MODE = not bool(ARGS.script) # Set debug flag global DEBUG DEBUG = ARGS.debug or override_debug # Setup data registry: global DATA_REG, DATA_DIRS, DATA_FILES from pyxrd.generic.io.data_registry import DataRegistry DATA_REG = DataRegistry(dirs=DATA_DIRS, files=DATA_FILES) # If we are running in GUI mode, setup GUI stuff: if GUI_MODE: import matplotlib import gtk # Setup matplotlib fonts: font = { 'weight' : 'heavy', 'size': 14, 'family' : 'sans-serif', } if sys.platform == "win32": font['sans-serif'] = 'Verdana, Arial, Helvetica, sans-serif' matplotlib.rc('font', **font) mathtext = {'default': 'regular', 'fontset': 'stixsans'} matplotlib.rc('mathtext', **mathtext) # matplotlib.rc('text', **{'usetex':True}) # Load our own icons: iconfactory = gtk.IconFactory() icons_path = DATA_REG.get_directory_path("APPLICATION_ICONS") for root, dirnames, filenames in os.walk(icons_path): for filename in filenames: if filename.endswith(".png"): stock_id = filename[:-4] # remove extensions filename = "%s/%s" % (icons_path, filename) pixbuf = gtk.gdk.pixbuf_new_from_file(filename) # @UndefinedVariable iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default() # Make sure default directories exist: for path in DATA_REG.get_all_directories(): try: os.makedirs(path) except OSError: pass # Register file parsers: for name in PARSER_MODULES: if not name.startswith('.'): # do not import relative paths! __import__(name) # Free some memory at this point: import gc gc.collect() # Log that we did all of this: import logging logger = logging.getLogger(__name__) logger.info("Runtime settings applied") __apply_lock__ = False SETTINGS_APPLIED = True
def initialize(override_debug=DEBUG): """Apply runtime settings, can and needs to be called only once""" global __apply_lock__, SETTINGS_APPLIED if not __apply_lock__ and not SETTINGS_APPLIED: __apply_lock__ = True # Get command line arguments global ARGS ARGS = _parse_args() # Set gui flag global GUI_MODE GUI_MODE = not bool(ARGS.script) # Set debug flag global DEBUG DEBUG = ARGS.debug or override_debug # Setup data registry: global DATA_REG, DATA_DIRS, DATA_FILES from pyxrd.generic.io.data_registry import DataRegistry DATA_REG = DataRegistry(dirs=DATA_DIRS, files=DATA_FILES) # If we are running in GUI mode, setup GUI stuff: if GUI_MODE: import matplotlib import gtk # Setup matplotlib fonts: font = { 'weight': 'heavy', 'size': 14, 'sans-serif': 'Helvetica, Arial, sans-serif', 'family': 'sans-serif', } matplotlib.rc('font', **font) mathtext = { 'default': 'regular', 'fontset': 'stixsans', } matplotlib.rc('mathtext', **mathtext) # matplotlib.rc('text', **{'usetex':True}) # Load our own icons: iconfactory = gtk.IconFactory() icons_path = DATA_REG.get_directory_path("APPLICATION_ICONS") for root, dirnames, filenames in os.walk(icons_path): for filename in filenames: if filename.endswith(".png"): stock_id = filename[:-4] # remove extensions filename = "%s/%s" % (icons_path, filename) pixbuf = gtk.gdk.pixbuf_new_from_file( filename) # @UndefinedVariable iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default() # Make sure default directories exist: for path in DATA_REG.get_all_directories(): try: os.makedirs(path) except OSError: pass # Free some memory at this point: import gc gc.collect() # Log that we did all of this: import logging logger = logging.getLogger(__name__) logger.info("Runtime settings applied") __apply_lock__ = False SETTINGS_APPLIED = True