def shutdown(self): cube.debug("shutting down") # This call is very important: # gui.Window.shutdown() -> system.Window.shutdown() -> clean inputs # Some bound methods are released, and python is able to collect # properly again. if self._window is not None: self._window.shutdown() self._handlers = None self._window = None self._running = False
def __init__(self, game_directories = [], game_name = None): cube.debug("New application") game_dir = None for dir_ in game_directories: if os.path.isdir(os.path.join(dir_, game_name)): game_dir = dir_ break if game_dir is None: raise Exception("Couldn't find a game named '%s'" % str(game_name)) super().__init__(name = "8cube.io/%s" % game_name) self._game = game.load( game_dir, game_name, self.window, ) self._game.event_manager.register( lambda ev, delta: self.shutdown(), self._game.shutdown_channel )
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))