API: rename {open_file, open_clan_folder} into {get_system_file, get_clan_folder}

This commit is contained in:
Johannes Kirschbauer
2025-07-10 18:42:03 +02:00
parent 4d25f29ce7
commit 1449ff622f
5 changed files with 24 additions and 24 deletions

View File

@@ -24,7 +24,7 @@ def remove_none(_list: list) -> list:
RESULT: dict[str, SuccessDataClass[list[str] | None] | ErrorDataClass] = {}
def open_clan_folder(*, op_key: str) -> SuccessDataClass[Flake] | ErrorDataClass:
def get_clan_folder(*, op_key: str) -> SuccessDataClass[Flake] | ErrorDataClass:
"""
Opens the clan folder using the GTK file dialog.
Returns the path to the clan folder or an error if it fails.
@@ -34,7 +34,7 @@ def open_clan_folder(*, op_key: str) -> SuccessDataClass[Flake] | ErrorDataClass
title="Select Clan Folder",
initial_folder=str(Path.home()),
)
response = open_file(file_request, op_key=op_key)
response = get_system_file(file_request, op_key=op_key)
if isinstance(response, ErrorDataClass):
return response
@@ -47,7 +47,7 @@ def open_clan_folder(*, op_key: str) -> SuccessDataClass[Flake] | ErrorDataClass
ApiError(
message="No folder selected",
description="You must select a folder to open.",
location=["open_clan_folder"],
location=["get_clan_folder"],
)
],
)
@@ -61,7 +61,7 @@ def open_clan_folder(*, op_key: str) -> SuccessDataClass[Flake] | ErrorDataClass
ApiError(
message="Invalid clan folder",
description=f"The selected folder '{clan_folder}' is not a valid clan folder.",
location=["open_clan_folder"],
location=["get_clan_folder"],
)
],
)
@@ -69,7 +69,7 @@ def open_clan_folder(*, op_key: str) -> SuccessDataClass[Flake] | ErrorDataClass
return SuccessDataClass(op_key=op_key, data=clan_folder, status="success")
def open_file(
def get_system_file(
file_request: FileRequest, *, op_key: str
) -> SuccessDataClass[list[str] | None] | ErrorDataClass:
GLib.idle_add(gtk_open_file, file_request, op_key)
@@ -106,7 +106,7 @@ def gtk_open_file(file_request: FileRequest, op_key: str) -> bool:
ApiError(
message=e.__class__.__name__,
description=str(e),
location=["open_file"],
location=["get_system_file"],
)
],
)
@@ -134,7 +134,7 @@ def gtk_open_file(file_request: FileRequest, op_key: str) -> bool:
ApiError(
message=e.__class__.__name__,
description=str(e),
location=["open_file"],
location=["get_system_file"],
)
],
)
@@ -162,7 +162,7 @@ def gtk_open_file(file_request: FileRequest, op_key: str) -> bool:
ApiError(
message=e.__class__.__name__,
description=str(e),
location=["open_file"],
location=["get_system_file"],
)
],
)
@@ -190,7 +190,7 @@ def gtk_open_file(file_request: FileRequest, op_key: str) -> bool:
ApiError(
message=e.__class__.__name__,
description=str(e),
location=["open_file"],
location=["get_system_file"],
)
],
)
@@ -239,7 +239,7 @@ def gtk_open_file(file_request: FileRequest, op_key: str) -> bool:
dialog.select_folder(callback=on_folder_select)
if file_request.mode == "open_multiple_files":
dialog.open_multiple(callback=on_file_select_multiple)
elif file_request.mode == "open_file":
elif file_request.mode == "get_system_file":
dialog.open(callback=on_file_select)
elif file_request.mode == "save":
dialog.save(callback=on_save_finish)

View File

@@ -10,7 +10,7 @@ from clan_lib.dirs import user_data_dir
from clan_lib.log_manager import LogGroupConfig, LogManager
from clan_lib.log_manager import api as log_manager_api
from clan_app.api.file_gtk import open_clan_folder, open_file
from clan_app.api.file_gtk import get_clan_folder, get_system_file
from clan_app.api.middleware import (
ArgumentParsingMiddleware,
LoggingMiddleware,
@@ -113,8 +113,8 @@ def app_run(app_opts: ClanAppOptions) -> int:
shared_threads=shared_threads,
)
API.overwrite_fn(open_file)
API.overwrite_fn(open_clan_folder)
API.overwrite_fn(get_system_file)
API.overwrite_fn(get_clan_folder)
# Add middleware to the webview
webview.add_middleware(ArgumentParsingMiddleware(api=API))

View File

@@ -103,16 +103,16 @@ class MethodRegistry:
---
# Example
The function 'open_file()' depends on the platform.
The function 'get_system_file()' depends on the platform.
def open_file(file_request: FileRequest) -> str | None:
def get_system_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)
API.register(get_system_file)
---
"""
raise NotImplementedError(msg)

View File

@@ -20,7 +20,7 @@ class FileFilter:
@dataclass
class FileRequest:
# Mode of the os dialog window
mode: Literal["open_file", "select_folder", "save", "open_multiple_files"]
mode: Literal["get_system_file", "select_folder", "save", "open_multiple_files"]
# Title of the os dialog window
title: str | None = field(default=None)
# Pre-applied filters for the file dialog
@@ -30,25 +30,25 @@ class FileRequest:
@API.register_abstract
def open_file(file_request: FileRequest) -> list[str] | None:
def get_system_file(file_request: FileRequest) -> list[str] | None:
"""
Api method to open a file dialog window.
Implementations is specific to the platform and
returns the name of the selected file or None if no file was selected.
"""
msg = "open_file() is not implemented"
msg = "get_system_file() is not implemented"
raise NotImplementedError(msg)
@API.register_abstract
def open_clan_folder() -> Flake:
def get_clan_folder() -> Flake:
"""
Api method to open the clan folder.
Implementations is specific to the platform and returns the path to the clan folder.
"""
msg = "open_clan_folder() is not implemented"
msg = "get_clan_folder() is not implemented"
raise NotImplementedError(msg)

View File

@@ -324,10 +324,10 @@ def test_private_public_fields() -> None:
def test_literal_field() -> None:
@dataclass
class Person:
name: Literal["open_file", "select_folder", "save"]
name: Literal["get_system_file", "select_folder", "save"]
data = {"name": "open_file"}
expected = Person(name="open_file")
data = {"name": "get_system_file"}
expected = Person(name="get_system_file")
assert from_dict(Person, data) == expected
assert dataclass_to_dict(expected) == data