fix: make bot initializable without recorder
This commit is contained in:
@@ -27,7 +27,8 @@ def main():
|
|||||||
|
|
||||||
app: QApplication = QApplication(sys.argv)
|
app: QApplication = QApplication(sys.argv)
|
||||||
recorder: RecorderWindow = RecorderWindow("localhost", 5000)
|
recorder: RecorderWindow = RecorderWindow("localhost", 5000)
|
||||||
bot: ExampleBot = ExampleBot(recorder)
|
bot: ExampleBot = ExampleBot()
|
||||||
|
bot.set_recorder(recorder)
|
||||||
|
|
||||||
app.aboutToQuit.connect(recorder.shutdown)
|
app.aboutToQuit.connect(recorder.shutdown)
|
||||||
recorder.register_bot(bot)
|
recorder.register_bot(bot)
|
||||||
|
|||||||
16
src/bot.py
16
src/bot.py
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from src.snapshot import Snapshot
|
from src.snapshot import Snapshot
|
||||||
|
|
||||||
@@ -9,8 +9,18 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
class Bot:
|
class Bot:
|
||||||
def __init__(self, recorder: RecorderWindow):
|
def __init__(self):
|
||||||
self.recorder: RecorderWindow = recorder
|
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):
|
def on_snapshot_received(self, snapshot: Snapshot):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user