示例#1
0
def font_dictionary(filename=None, force=False):
    """\
    Path specification for the font dictionary, cached
    """
    global _FONT_DICTIONARY
    if _FONT_DICTIONARY is None:
        if filename is None:
            if os.path.exists(USER_FONTS_CACHE_PATH):
                filename = USER_FONTS_CACHE_PATH
            else:
                filename = ROOT_FONTS_CACHE_PATH
        if filename and os.path.exists(filename) and not force:
            _FONT_DICTIONARY = safe.eval_safe(file(filename, 'rb').read())
        else:
            _FONT_DICTIONARY = {}
        if not _FONT_DICTIONARY:
            _FONT_DICTIONARY = _font_dictionary()
            if not (WRITABLE_FONTS_CACHE_PATH is None):
                f = file(WRITABLE_FONTS_CACHE_PATH, 'wb')
                f.write(unicode(_FONT_DICTIONARY))
                f.close()
    if not _FONT_DICTIONARY:
        # 'empty' dict for ui
        _FONT_DICTIONARY = {'': ''}
    _FONT_DICTIONARY.update(SHIPPED_FONTS)
    return _FONT_DICTIONARY
示例#2
0
def open_actionlist(filename):
    """Open the action list from a file.

    :param filename: the filename of the action list
    :type filename: string
    :returns: action list
    :rtype: dictionary
    """
    #read source
    f = open(filename, 'rb')
    source = f.read()
    f.close()
    #load data
    data = safe.eval_safe(source)
    if not data.get('version', '').startswith('0.2'):
        send.frame_show_error(ERROR_INCOMPATIBLE_ACTIONLIST % ct.INFO)
        return None
    result = []
    invalid_labels = []
    actions = data['actions']
    for action in actions:
        actionLabel = action['label']
        actionFields = action['fields']
        newAction = ACTIONS[actionLabel]()
        invalid_labels.extend(['- %s (%s)' % (label, actionLabel)
                                for label in newAction.load(actionFields)])
        result.append(newAction)
    warning = assert_safe(result)
    data['actions'] = result
    data['invalid labels'] = invalid_labels
    return data, warning
示例#3
0
def get_library_list():
    """Get library actionlists"""
    global __LIBRARY_ACTIONLISTS
    if __LIBRARY_ACTIONLISTS:
        return __LIBRARY_ACTIONLISTS
    pattern = os.path.join(config.PHATCH_ACTIONLISTS_PATH, '*.phatch')
    actionlist_paths = glob.glob(pattern)
    __LIBRARY_ACTIONLISTS = dict((utils.file_name(actionlist_file),
                                  eval_safe(open(actionlist_file).read()))
                                 for actionlist_file in actionlist_paths)
    return __LIBRARY_ACTIONLISTS
示例#4
0
def get_library_list():
    """Get library actionlists"""
    global __LIBRARY_ACTIONLISTS
    if __LIBRARY_ACTIONLISTS:
        return __LIBRARY_ACTIONLISTS
    pattern = os.path.join(config.PHATCH_ACTIONLISTS_PATH, '*.phatch')
    actionlist_paths = glob.glob(pattern)
    __LIBRARY_ACTIONLISTS = dict(
        (
            utils.file_name(actionlist_file),
            eval_safe(open(actionlist_file).read()))
        for actionlist_file in actionlist_paths)
    return __LIBRARY_ACTIONLISTS