fishyboteso/fishy/engine/common/IEngine.py

36 lines
754 B
Python
Raw Normal View History

2020-06-01 12:58:18 +00:00
import typing
from abc import ABC, abstractmethod
from threading import Thread
from typing import Callable
2020-10-17 19:06:07 +00:00
from fishy.gui.funcs import GUIFuncsMock
2020-06-01 12:58:18 +00:00
if typing.TYPE_CHECKING:
from fishy.gui import GUI
class IEngine(ABC):
2020-10-17 19:06:07 +00:00
def __init__(self, gui_ref: 'Callable[[], GUI]'):
2020-06-01 12:58:18 +00:00
self.get_gui = gui_ref
self.start = False
self.window = None
2020-06-01 12:58:18 +00:00
self.thread = None
@property
def gui(self):
if self.get_gui is None:
return GUIFuncsMock()
2020-06-01 12:58:18 +00:00
return self.get_gui().funcs
def toggle_start(self):
self.start = not self.start
if self.start:
self.thread = Thread(target=self.run)
self.thread.start()
@abstractmethod
def run(self):
...