feat: use functools.wraps

This commit is contained in:
aclist 2026-02-13 02:43:08 +09:00
parent c786ba2c9a
commit 82c585a195
2 changed files with 19 additions and 13 deletions

View File

@ -22,6 +22,7 @@ from typing import Any
logger = logging.getLogger(__name__)
@dataclass
class ModMeta:
protocol: str
@ -41,6 +42,7 @@ def get_local_mod_path(steam_path: Path) -> Path:
workshop_path = p / WORKSHOP_PATH
return workshop_path
def get_local_mods(workshop_path: Path) -> list[Path]:
mods = [file for file in workshop_path.iterdir() if file.is_dir()]
return mods
@ -148,6 +150,7 @@ def find_stale_mods(config: Path) -> list[int]:
steam = lookup(config, Preferences.DEFAULT)
steam_path = Path(steam)
# TODO: use concurrency
local = get_local_mod_ids(steam_path)
servers = lookup(config, Preferences.IP_LIST)

View File

@ -7,6 +7,7 @@ from warnings import deprecated
from concurrent.futures import wait
from concurrent.futures import ThreadPoolExecutor
from functools import wraps
from pathlib import Path
from typing import Any, Callable, TYPE_CHECKING
@ -101,15 +102,17 @@ class Controller(GObject.GObject):
def get_emitter(self) -> Emitter:
return self.emitter
def call_on_thread(func: Callable) -> Callable:
def wrapper(*args, **kwargs):
self = args[0]
# TODO: get dialog string from own attribute
self.wait_dialog = WaitDialog(self, strings.dialog.filtering)
self.wait_dialog.show_all()
thread = threading.Thread(target=func, args=args)
thread.start()
return wrapper
def call_on_thread(dialog_str: str) -> Callable:
def decorator(func: Callable) -> Callable:
@wraps(func)
def wrapper(*args, **kwargs):
self = args[0]
self.wait_dialog = WaitDialog(self, dialog_str)
self.wait_dialog.show_all()
thread = threading.Thread(target=func, args=args)
thread.start()
return wrapper
return decorator
def register_widget(self, attr: str, widget: Gtk.Widget) -> None:
try:
@ -693,7 +696,7 @@ class Controller(GObject.GObject):
treeview.set_loaded(True)
GLib.idle_add(self.cleanup)
@call_on_thread
@call_on_thread(strings.dialog.working)
def highlight_stale(self) -> None:
self.colorize_mods()
@ -746,7 +749,7 @@ class Controller(GObject.GObject):
dialog = ExceptionDialog(self, strings.api_error)
dialog.run()
@call_on_thread
@call_on_thread(strings.dialog.working)
# FIXME: entire process is behind thread, including destroy_on_idle()
def update_api_key(self, text: str, key: Preferences) -> None:
self.test_api_response(text, key)
@ -794,11 +797,11 @@ class Controller(GObject.GObject):
def get_statusbar(self) -> None:
return self.mediator.statusbar
@call_on_thread
@call_on_thread(strings.dialog.fetching)
def run_query_func(self, func: Callable) -> None:
func()
@call_on_thread
@call_on_thread(strings.dialog.filtering)
def filter_threaded(self, mode: FilterMode, label: str) -> None:
tv = self.get_active_treeview()
tv.filter_man.filter(mode, label)