♻️ Restructured sources and managers

This commit is contained in:
GeoffreyCoulaud
2023-05-23 17:00:47 +02:00
parent 95524563bb
commit a11569014d
10 changed files with 17 additions and 24 deletions

View File

@@ -0,0 +1,49 @@
from abc import abstractmethod
from gi.repository import Gio
from src.game import Game
class Manager:
"""Class in charge of handling a post creation action for games.
* May connect to signals on the game to handle them.
* May cancel its running tasks on critical error,
in that case a new cancellable must be generated for new tasks to run.
"""
run_after: set[type["Manager"]]
cancellable: Gio.Cancellable
errors: list[Exception]
def __init__(self) -> None:
super().__init__()
self.cancellable = Gio.Cancellable()
self.errors = list()
def cancel_tasks(self):
"""Cancel all tasks for this manager"""
self.cancellable.cancel()
def reset_cancellable(self):
"""Reset the cancellable for this manager.
Alreadyn scheduled Tasks will no longer be cancellable."""
self.cancellable = Gio.Cancellable()
def report_error(self, error: Exception):
"""Report an error that happened in of run"""
self.errors.append(error)
def collect_errors(self) -> list[Exception]:
"""Get the errors produced by the manager and remove them from self.errors"""
errors = list(self.errors)
self.errors.clear()
return errors
@abstractmethod
def run(self, game: Game) -> None:
"""Pass the game through the manager.
May block its thread.
May not raise exceptions, as they will be silently ignored."""
pass