fix: make bot initializable without recorder

This commit is contained in:
2025-10-24 22:28:50 +02:00
parent fa61e27825
commit 97f9765705
2 changed files with 15 additions and 4 deletions

View File

@@ -27,7 +27,8 @@ def main():
app: QApplication = QApplication(sys.argv)
recorder: RecorderWindow = RecorderWindow("localhost", 5000)
bot: ExampleBot = ExampleBot(recorder)
bot: ExampleBot = ExampleBot()
bot.set_recorder(recorder)
app.aboutToQuit.connect(recorder.shutdown)
recorder.register_bot(bot)

View File

@@ -1,6 +1,6 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from src.snapshot import Snapshot
@@ -9,8 +9,18 @@ if TYPE_CHECKING:
class Bot:
def __init__(self, recorder: RecorderWindow):
self.recorder: RecorderWindow = recorder
def __init__(self):
self._recorder: Optional[RecorderWindow] = None
@property
def recorder(self) -> RecorderWindow:
if self._recorder is None:
raise RuntimeError(
"Bot does not have a recorder. Call Bot.set_recorder to set one")
return self._recorder
def set_recorder(self, recorder: RecorderWindow):
self._recorder = recorder
def on_snapshot_received(self, snapshot: Snapshot):
pass