UI: init flash poc

This commit is contained in:
Johannes Kirschbauer
2024-07-06 19:52:19 +02:00
parent 0a98bd6cc7
commit 10bae7dcb0
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

View File

@@ -11,6 +11,8 @@ from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any
from clan_cli.api import API
from .clan_uri import FlakeId
from .cmd import Log, run
from .completions import add_dynamic_completer, complete_machines
@@ -22,6 +24,7 @@ from .nix import nix_shell
log = logging.getLogger(__name__)
@API.register
def flash_machine(
machine: Machine,
*,