2020-05-14 02:03:13 +00:00
|
|
|
import logging
|
2021-04-15 11:47:43 +00:00
|
|
|
import queue
|
2020-05-14 02:03:13 +00:00
|
|
|
import threading
|
2021-05-09 07:05:51 +00:00
|
|
|
import tkinter as tk
|
|
|
|
import uuid
|
|
|
|
from typing import Any, Callable, Dict, Optional
|
2020-05-14 02:03:13 +00:00
|
|
|
|
2020-06-25 01:22:39 +00:00
|
|
|
from ttkthemes import ThemedTk
|
|
|
|
|
2020-10-17 10:52:04 +00:00
|
|
|
from fishy.engine.common.event_handler import EngineEventHandler
|
2020-06-25 16:39:05 +00:00
|
|
|
from fishy.gui import config_top
|
2020-05-19 03:11:58 +00:00
|
|
|
from fishy.gui.funcs import GUIFuncs
|
2021-05-09 07:05:51 +00:00
|
|
|
from fishy.web import web
|
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
from ..helper.config import config
|
2020-11-30 21:04:33 +00:00
|
|
|
from ..helper.helper import wait_until
|
2021-05-09 07:05:51 +00:00
|
|
|
from . import main_gui
|
|
|
|
from .log_config import GUIStreamHandler
|
2020-05-14 02:03:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GUI:
|
2020-10-17 19:06:07 +00:00
|
|
|
def __init__(self, get_engine: Callable[[], EngineEventHandler]):
|
2020-05-19 03:11:58 +00:00
|
|
|
self.funcs = GUIFuncs(self)
|
|
|
|
self.get_engine = get_engine
|
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
self.config = config
|
2020-05-14 02:03:13 +00:00
|
|
|
self._start_restart = False
|
|
|
|
self._destroyed = True
|
|
|
|
self._log_strings = []
|
2021-04-15 11:47:43 +00:00
|
|
|
self._function_queue = queue.Queue()
|
|
|
|
self._result_dict: Dict[str, Any] = {}
|
2020-05-14 02:03:13 +00:00
|
|
|
self._bot_running = False
|
|
|
|
|
|
|
|
# UI items
|
2020-10-17 19:06:07 +00:00
|
|
|
self._root: Optional[ThemedTk] = None
|
2020-05-14 02:03:13 +00:00
|
|
|
self._console = None
|
|
|
|
self._start_button = None
|
|
|
|
self._notify_check = None
|
2021-05-09 06:32:36 +00:00
|
|
|
self._engine_select: Optional[tk.OptionMenu] = None
|
|
|
|
self._config_button: Optional[tk.Button] = None
|
2020-06-25 16:39:05 +00:00
|
|
|
self._engine_var = None
|
2020-05-14 02:03:13 +00:00
|
|
|
|
|
|
|
self._thread = threading.Thread(target=self.create, args=())
|
|
|
|
|
2020-10-29 21:24:52 +00:00
|
|
|
self._notify = None
|
|
|
|
self.login = None
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
root_logger = logging.getLogger('')
|
|
|
|
root_logger.setLevel(logging.DEBUG)
|
|
|
|
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
|
|
|
new_console = GUIStreamHandler(self)
|
|
|
|
root_logger.addHandler(new_console)
|
|
|
|
|
2020-05-19 03:11:58 +00:00
|
|
|
@property
|
|
|
|
def engine(self):
|
2020-06-01 12:58:18 +00:00
|
|
|
return self.get_engine()
|
2020-05-19 03:11:58 +00:00
|
|
|
|
2020-06-25 16:39:05 +00:00
|
|
|
@property
|
|
|
|
def engines(self):
|
|
|
|
engines = {
|
2020-11-02 19:04:50 +00:00
|
|
|
"Semi Fisher": [lambda: config_top.start_semifisher_config(self), # start config function
|
|
|
|
self.engine.toggle_semifisher], # start engine function
|
2020-06-25 16:39:05 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 19:04:50 +00:00
|
|
|
if web.has_beta():
|
2020-06-25 16:39:05 +00:00
|
|
|
engines["Full-Auto Fisher"] = [lambda: config_top.start_fullfisher_config(self),
|
|
|
|
self.engine.toggle_fullfisher]
|
|
|
|
return engines
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
def create(self):
|
|
|
|
main_gui._create(self)
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self._thread.start()
|
|
|
|
|
2020-05-19 03:11:58 +00:00
|
|
|
def _clear_function_queue(self):
|
2021-04-15 11:47:43 +00:00
|
|
|
while not self._function_queue.empty():
|
|
|
|
_id, func = self._function_queue.get()
|
2020-11-30 21:04:33 +00:00
|
|
|
result = func()
|
2021-04-15 11:47:43 +00:00
|
|
|
self._result_dict[_id] = result
|
2020-05-19 03:11:58 +00:00
|
|
|
|
2020-11-30 21:04:33 +00:00
|
|
|
def call_in_thread(self, func: Callable, block=False):
|
|
|
|
_id = str(uuid.uuid4())
|
2021-04-15 11:47:43 +00:00
|
|
|
self._function_queue.put((_id, func))
|
2020-11-30 21:04:33 +00:00
|
|
|
|
|
|
|
if not block:
|
|
|
|
return None
|
|
|
|
|
2021-04-15 11:47:43 +00:00
|
|
|
wait_until(lambda: _id in self._result_dict)
|
2020-11-30 21:04:33 +00:00
|
|
|
|
2021-04-15 11:47:43 +00:00
|
|
|
return self._result_dict.pop(_id)
|
2020-06-25 01:22:39 +00:00
|
|
|
|
|
|
|
def _get_start_stop_text(self):
|
|
|
|
return "STOP (F9)" if self._bot_running else "START (F9)"
|