abstracted event_handler and config to make developing gui easier

This commit is contained in:
Adam Saudagar 2021-05-01 14:58:09 +05:30
parent c86e86b901
commit a710246081
4 changed files with 38 additions and 4 deletions

View File

@ -5,8 +5,29 @@ from fishy.engine import SemiFisherEngine
from fishy.engine.fullautofisher.engine import FullAuto from fishy.engine.fullautofisher.engine import FullAuto
class EngineEventHandler: class IEngineHandler:
def __init__(self):
...
def start_event_handler(self):
...
def toggle_semifisher(self):
...
def toggle_fullfisher(self):
...
def check_pixel_val(self):
...
def quit(self):
...
class EngineEventHandler(IEngineHandler):
def __init__(self, gui_ref): def __init__(self, gui_ref):
super().__init__()
self.event_handler_running = True self.event_handler_running = True
self.event = [] self.event = []

View File

@ -3,6 +3,7 @@ import os
import typing import typing
from tkinter.filedialog import askopenfilename from tkinter.filedialog import askopenfilename
from fishy.engine.common.event_handler import IEngineHandler
from fishy.helper import helper from fishy.helper import helper
from fishy import web from fishy import web
@ -109,3 +110,10 @@ def start_semifisher_config(gui: 'GUI'):
controls_frame.pack(padx=(5, 5), pady=(5, 5)) controls_frame.pack(padx=(5, 5), pady=(5, 5))
top.start() top.start()
if __name__ == '__main__':
from fishy.gui import GUI
gui = GUI(lambda: IEngineHandler())
gui.call_in_thread(lambda: start_fullfisher_config(gui))
gui.create()

View File

@ -8,7 +8,7 @@ import threading
from fishy.web import web from fishy.web import web
from ttkthemes import ThemedTk from ttkthemes import ThemedTk
from fishy.engine.common.event_handler import EngineEventHandler from fishy.engine.common.event_handler import EngineEventHandler, IEngineHandler
from fishy.gui import config_top from fishy.gui import config_top
from fishy.gui.funcs import GUIFuncs from fishy.gui.funcs import GUIFuncs
from . import main_gui from . import main_gui
@ -18,7 +18,7 @@ from ..helper.helper import wait_until
class GUI: class GUI:
def __init__(self, get_engine: Callable[[], EngineEventHandler]): def __init__(self, get_engine: Callable[[], IEngineHandler]):
self.funcs = GUIFuncs(self) self.funcs = GUIFuncs(self)
self.get_engine = get_engine self.get_engine = get_engine

View File

@ -107,7 +107,7 @@ class config:
:param default: default value to return if key is not found :param default: default value to return if key is not found
:return: config value :return: config value
""" """
return default if config._instance[key] is None else config._instance[key] return default if config._instance is None or config._instance[key] is None else config._instance[key]
@staticmethod @staticmethod
def set(key, value, save=True): def set(key, value, save=True):
@ -117,6 +117,9 @@ class config:
:param value: value to save :param value: value to save
:param save: False if don't want to save right away :param save: False if don't want to save right away
""" """
if config._instance is None:
return
config._instance[key] = value config._instance[key] = value
if save: if save:
config.save_config() config.save_config()
@ -135,4 +138,6 @@ class config:
@staticmethod @staticmethod
def save_config(): def save_config():
if config._instance is None:
return
config._instance.save_config() config._instance.save_config()