diff --git a/scripts/example_bot.py b/scripts/example_bot.py index c331a82..0778a92 100644 --- a/scripts/example_bot.py +++ b/scripts/example_bot.py @@ -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) diff --git a/src/bot.py b/src/bot.py index 85046c5..990af08 100644 --- a/src/bot.py +++ b/src/bot.py @@ -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