UI: init flash poc

This commit is contained in:
Johannes Kirschbauer
2024-07-06 19:52:19 +02:00
parent 9407902398
commit 44d2f58c47
5 changed files with 183 additions and 2 deletions

View File

@@ -55,6 +55,34 @@ class _MethodRegistry:
self._orig: dict[str, Callable[[Any], Any]] = {}
self._registry: dict[str, Callable[[Any], Any]] = {}
def register_abstract(self, fn: Callable[..., T]) -> Callable[..., T]:
@wraps(fn)
def wrapper(
*args: Any, op_key: str | None = None, **kwargs: Any
) -> ApiResponse[T]:
raise NotImplementedError(
f"""{fn.__name__} - The platform didn't implement this function.
---
# Example
The function 'open_file()' depends on the platform.
def open_file(file_request: FileRequest) -> str | None:
# In GTK we open a file dialog window
# In Android we open a file picker dialog
# and so on.
pass
# At runtime the clan-app must override platform specific functions
API.register(open_file)
---
"""
)
self.register(wrapper)
return fn
def register(self, fn: Callable[..., T]) -> Callable[..., T]:
self._orig[fn.__name__] = fn

View File

@@ -28,13 +28,13 @@ class FileRequest:
filters: FileFilter | None = None
@API.register
@API.register_abstract
def open_file(file_request: FileRequest) -> str | None:
"""
Abstract api method to open a file dialog window.
It must return the name of the selected file or None if no file was selected.
"""
raise NotImplementedError("Each specific platform should implement this function.")
pass
@dataclass