コード例 #1
0
ファイル: main.py プロジェクト: hotgloupi/8cube
def console():
    import cube
    locals_ = {
        'cube': cube,
    }
    import code
    readline = None
    for m in ['readline', 'pyreadline']:
        try:
            readline = __import__(m)
        except:
            pass
    if readline is None:
        cube.warn("Couldn't import any readline module")
    else:
        import rlcompleter
        readline.set_completer(rlcompleter.Completer(locals_).complete)
        readline.parse_and_bind("tab: complete")

    code.InteractiveConsole(locals_).interact(
        banner="Type 'help(cube)' to get started."
    )
コード例 #2
0
ファイル: font_manager.py プロジェクト: hotgloupi/8cube
    def populate(cls):
        if cls.fonts is not None:
            return

        start = time.time()
        from cube.constants.application import config_directory
        fonts_dir = os.path.join(config_directory(), "fonts")
        if not os.path.exists(fonts_dir):
            os.makedirs(fonts_dir)
        fonts_file = os.path.join(fonts_dir, "fonts.lst")
        if os.path.exists(fonts_file):
            cube.debug("Loading fonts from cache file '%s'" % fonts_file)
            try:
                with open(fonts_file, 'rb') as f:
                    cls.fonts = pickle.loads(f.read())
            except Exception as e:
                cube.warn("font cache file '%s' is not valid, it will be removed:" % fonts_file, e)
                os.unlink(fonts_file)
        else:
            cube.info("Finding fonts on your system, this may take a while...")
            cls.fonts = {}
            for font_dir in cls.font_directories():
                for root, dirs, files in os.walk(font_dir):
                    for f in files:
                        path = os.path.join(root, f)
                        if font.is_valid(path):
                            try:
                                cls.fonts[path] = font.get_infos(path)
                            except:
                                cube.error("ignoring font file", path)

        if not cls.fonts:
            raise Exception("Couldn't find any font on your system !")
        cube.info(len(cls.fonts), "font infos fetched in %f seconds" % (time.time() - start))

        cube.debug("Saving fonts into cache file '%s'" % fonts_file)
        with open(fonts_file, 'wb') as f:
            f.write(pickle.dumps(cls.fonts))
コード例 #3
0
ファイル: font_manager.py プロジェクト: hotgloupi/8cube
# -*- encoding: utf-8 -*-

import cube
from cube.gl import font

import os
import time

try:
    import _pickle as pickle
except:
    cube.warn("Optimized pickle not available")
    import pickle



class FontManager:

    fonts = None

    def __init__(self):
        raise Exception("Cannot instanciate a font manager")

    @classmethod
    def search(cls,
               family=None,
               scalable=None,
               fixed_width=None):
        results = []
        for path, infos_list in cls.fonts.items():
            results.extend(