ruff: apply automatic fixes

This commit is contained in:
Jörg Thalheim
2025-08-20 13:52:45 +02:00
parent 798d445f3e
commit ea2d6aab65
217 changed files with 2283 additions and 1739 deletions

View File

@@ -16,8 +16,7 @@ log = logging.getLogger(__name__)
class ToastOverlay:
"""
The ToastOverlay is a class that manages the display of toasts
"""The ToastOverlay is a class that manages the display of toasts
It should be used as a singleton in your application to prevent duplicate toasts
Usage
"""
@@ -53,11 +52,14 @@ class ErrorToast:
toast: Adw.Toast
def __init__(
self, message: str, persistent: bool = False, details: str = ""
self,
message: str,
persistent: bool = False,
details: str = "",
) -> None:
super().__init__()
self.toast = Adw.Toast.new(
f"""<span foreground='red'>❌ Error </span> {message}"""
f"""<span foreground='red'>❌ Error </span> {message}""",
)
self.toast.set_use_markup(True)
@@ -85,7 +87,7 @@ class WarningToast:
def __init__(self, message: str, persistent: bool = False) -> None:
super().__init__()
self.toast = Adw.Toast.new(
f"<span foreground='orange'>⚠ Warning </span> {message}"
f"<span foreground='orange'>⚠ Warning </span> {message}",
)
self.toast.set_use_markup(True)
@@ -135,7 +137,7 @@ class LogToast:
) -> None:
super().__init__()
self.toast = Adw.Toast.new(
f"""Logs are available <span weight="regular">{message}</span>"""
f"""Logs are available <span weight="regular">{message}</span>""",
)
self.toast.set_use_markup(True)

View File

@@ -45,8 +45,7 @@ class JoinValue(GObject.Object):
class JoinList:
"""
This is a singleton.
"""This is a singleton.
It is initialized with the first call of use()
"""
@@ -69,28 +68,32 @@ class JoinList:
return cls._instance
def rerender_join_list(
self, source: GKVStore, position: int, removed: int, added: int
self,
source: GKVStore,
position: int,
removed: int,
added: int,
) -> None:
self.list_store.items_changed(
0, self.list_store.get_n_items(), self.list_store.get_n_items()
0,
self.list_store.get_n_items(),
self.list_store.get_n_items(),
)
def is_empty(self) -> bool:
return self.list_store.get_n_items() == 0
def push(self, uri: ClanURI, after_join: Callable[[JoinValue], None]) -> None:
"""
Add a join request.
"""Add a join request.
This method can add multiple join requests if called subsequently for each request.
"""
value = JoinValue(uri)
machine_id = Machine(uri.machine_name, uri.flake)
machine_id_list = []
for machine_obj in self.list_store:
mvalue: ClanURI = cast(JoinValue, machine_obj).url
mvalue: ClanURI = cast("JoinValue", machine_obj).url
machine = Machine(mvalue.machine_name, mvalue.flake)
machine_id_list.append(machine.get_id())

View File

@@ -8,8 +8,7 @@ from gi.repository import Adw
class ViewStack:
"""
This is a singleton.
"""This is a singleton.
It is initialized with the first call of use()
Usage:

View File

@@ -53,7 +53,8 @@ class ClanStore:
if cls._instance is None:
cls._instance = cls.__new__(cls)
cls._clan_store = GKVStore(
VMStore, lambda store: store.first().data.flake.flake_url
VMStore,
lambda store: store.first().data.flake.flake_url,
)
cls._emitter = Emitter()
@@ -74,19 +75,24 @@ class ClanStore:
return self._logging_vm
def register_on_deep_change(
self, callback: Callable[[GKVStore, int, int, int], None]
self,
callback: Callable[[GKVStore, int, int, int], None],
) -> None:
"""
Register a callback that is called when a clan_store or one of the included VMStores changes
"""
"""Register a callback that is called when a clan_store or one of the included VMStores changes"""
def on_vmstore_change(
store: VMStore, position: int, removed: int, added: int
store: VMStore,
position: int,
removed: int,
added: int,
) -> None:
callback(store, position, removed, added)
def on_clanstore_change(
store: "GKVStore", position: int, removed: int, added: int
store: "GKVStore",
position: int,
removed: int,
added: int,
) -> None:
if added > 0:
store.values()[position].register_on_change(on_vmstore_change)
@@ -120,7 +126,9 @@ class ClanStore:
logs_view: Logs = views.get_child_by_name("logs") # type: ignore
def file_read_callback(
source_object: Gio.File, result: Gio.AsyncResult, _user_data: Any
source_object: Gio.File,
result: Gio.AsyncResult,
_user_data: Any,
) -> None:
try:
# Finish the asynchronous read operation
@@ -155,7 +163,7 @@ class ClanStore:
if old_vm:
log.info(
f"VM {vm.data.flake.flake_attr} already exists in store. Updating data field."
f"VM {vm.data.flake.flake_attr} already exists in store. Updating data field.",
)
old_vm.update(vm.data)
else: