77from pathlib import Path
88from typing import TYPE_CHECKING , Iterable
99
10- from .. import core
1110from ..api import _normalize_prop
11+ from ..core import Brush , CompilationResult , Compiler , DiagnosticLevel , Image
1212from .emitters import write_python_module , write_stub_module
1313from .models import (
1414 CallbackMeta ,
@@ -41,7 +41,8 @@ def generate_project(
4141 if output_dir is not None :
4242 output_dir .mkdir (parents = True , exist_ok = True )
4343
44- compiler = core .Compiler ()
44+ compiler = Compiler ()
45+
4546 if config .style :
4647 compiler .style = config .style
4748 if config .include_paths :
@@ -101,23 +102,23 @@ def _discover_slint_files(inputs: Iterable[Path]) -> Iterable[tuple[Path, Path]]
101102
102103
103104def _compile_slint (
104- compiler : core . Compiler ,
105+ compiler : Compiler ,
105106 source_path : Path ,
106107 config : GenerationConfig ,
107- ) -> core . CompilationResult | None :
108+ ) -> CompilationResult | None :
108109 result = compiler .build_from_path (source_path )
109110
110- diagnostics = result .diagnostics
111- diagnostic_error = getattr (core , "DiagnosticLevel" , None )
112- error_enum = getattr (diagnostic_error , "Error" , None )
113-
114111 def is_error (diag : PyDiagnostic ) -> bool :
115- if error_enum is not None :
116- return diag .level == error_enum
117- return str (diag .level ).lower ().startswith ("error" )
112+ return diag .level == DiagnosticLevel .Error
118113
119- errors = [diag for diag in diagnostics if is_error (diag )]
120- warnings = [diag for diag in diagnostics if not is_error (diag )]
114+ errors : list [PyDiagnostic ] = []
115+ warnings : list [PyDiagnostic ] = []
116+
117+ for diag in result .diagnostics :
118+ if is_error (diag ):
119+ errors .append (diag )
120+ else :
121+ warnings .append (diag )
121122
122123 if warnings and not config .quiet :
123124 for diag in warnings :
@@ -132,8 +133,9 @@ def is_error(diag: PyDiagnostic) -> bool:
132133 return result
133134
134135
135- def _collect_metadata (result : core . CompilationResult ) -> ModuleArtifacts :
136+ def _collect_metadata (result : CompilationResult ) -> ModuleArtifacts :
136137 components : list [ComponentMeta ] = []
138+
137139 for name in result .component_names :
138140 comp = result .component (name )
139141
@@ -274,9 +276,9 @@ def _python_value_hint(value: object) -> str:
274276 return "float"
275277 if isinstance (value , str ):
276278 return "str"
277- if isinstance (value , core . Image ):
279+ if isinstance (value , Image ):
278280 return "slint.Image"
279- if isinstance (value , core . Brush ):
281+ if isinstance (value , Brush ):
280282 return "slint.Brush"
281283 return "Any"
282284
0 commit comments