cutter/src/python/reg_qtres_importer.py
2019-05-17 13:40:50 +02:00

31 lines
741 B
Python

import sys
import importlib
import _qtres
class QtResLoader:
@classmethod
def get_code(cls, name):
return _qtres.get_code(name)
@classmethod
def create_module(cls, spec):
return None
@classmethod
def exec_module(cls, module):
code = cls.get_code(module.__name__)
if code is None:
raise ImportError("get_code() failed")
exec(code, module.__dict__)
class QtResFinder:
@classmethod
def find_spec(cls, fullname, path=None, target=None):
if path or target:
return None
if not _qtres.exists(fullname):
return None
return importlib._bootstrap.ModuleSpec(fullname, QtResLoader)
sys.meta_path.append(QtResFinder)