fishyboteso/fishy/gui/gui.py

79 lines
2.3 KiB
Python
Raw Normal View History

import logging
2020-10-29 21:24:52 +00:00
from tkinter import OptionMenu, Button, IntVar
2020-10-17 19:06:07 +00:00
from typing import List, Callable, Optional
import threading
from ttkthemes import ThemedTk
from fishy.engine.common.event_handler import EngineEventHandler
from fishy.gui import config_top
from fishy.gui.funcs import GUIFuncs
from . import main_gui
from .log_config import GUIStreamHandler
2020-10-17 19:06:07 +00:00
from ..helper.config import config
class GUI:
2020-10-17 19:06:07 +00:00
def __init__(self, get_engine: Callable[[], EngineEventHandler]):
self.funcs = GUIFuncs(self)
self.get_engine = get_engine
2020-10-17 19:06:07 +00:00
self.config = config
self._start_restart = False
self._destroyed = True
self._log_strings = []
self._function_queue: List[Callable] = []
self._bot_running = False
# UI items
2020-10-17 19:06:07 +00:00
self._root: Optional[ThemedTk] = None
self._console = None
self._start_button = None
self._notify_check = None
2020-10-17 19:06:07 +00:00
self._engine_select: Optional[OptionMenu] = None
self._config_button: Optional[Button] = None
self._engine_var = None
self._thread = threading.Thread(target=self.create, args=())
2020-10-29 21:24:52 +00:00
self._notify = None
self.login = None
root_logger = logging.getLogger('')
root_logger.setLevel(logging.DEBUG)
logging.getLogger('urllib3').setLevel(logging.WARNING)
new_console = GUIStreamHandler(self)
root_logger.addHandler(new_console)
@property
def engine(self):
2020-06-01 12:58:18 +00:00
return self.get_engine()
@property
def engines(self):
engines = {
"Semi Fisher": [lambda: config_top.start_semifisher_config(self), self.engine.toggle_semifisher],
}
2020-10-17 19:06:07 +00:00
if config.get('debug', False):
engines["Full-Auto Fisher"] = [lambda: config_top.start_fullfisher_config(self),
self.engine.toggle_fullfisher]
return engines
def create(self):
main_gui._create(self)
def start(self):
self._thread.start()
def _clear_function_queue(self):
while len(self._function_queue) > 0:
func = self._function_queue.pop(0)
func()
def call_in_thread(self, func: Callable):
self._function_queue.append(func)
def _get_start_stop_text(self):
return "STOP (F9)" if self._bot_running else "START (F9)"