mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
Python: rework the load_file API, part 2
Take arguments for configuring style, etc., throw an exception on errors, and log warning diagnostics.
This commit is contained in:
parent
280f314eeb
commit
765c773b90
3 changed files with 47 additions and 5 deletions
|
@ -3,12 +3,41 @@
|
|||
|
||||
from . import slint as native
|
||||
import types
|
||||
import logging
|
||||
|
||||
|
||||
def load_file(path):
|
||||
class CompileError(Exception):
|
||||
def __init__(self, message, diagnostics):
|
||||
self.message = message
|
||||
self.diagnostics = diagnostics
|
||||
|
||||
|
||||
def load_file(path, quiet=False, style=None, include_paths=None, library_paths=None, translation_domain=None):
|
||||
compiler = native.ComponentCompiler()
|
||||
|
||||
if style is not None:
|
||||
compiler.style = style
|
||||
if include_paths is not None:
|
||||
compiler.include_paths = include_paths
|
||||
if library_paths is not None:
|
||||
compiler.library_paths = library_paths
|
||||
if translation_domain is not None:
|
||||
compiler.translation_domain = translation_domain
|
||||
|
||||
compdef = compiler.build_from_path(path)
|
||||
|
||||
diagnostics = compiler.diagnostics
|
||||
if diagnostics:
|
||||
if not quiet:
|
||||
for diag in diagnostics:
|
||||
if diag.level == native.DiagnosticLevel.Warning:
|
||||
logging.warning(diag)
|
||||
|
||||
errors = [diag for diag in diagnostics if diag.level ==
|
||||
native.DiagnosticLevel.Error]
|
||||
if errors:
|
||||
raise CompileError(f"Could not compile {path}", diagnostics)
|
||||
|
||||
module = types.SimpleNamespace()
|
||||
setattr(module, compdef.name, type("SlintMetaClass", (), {
|
||||
"__compdef": compdef,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue