mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
Merge pull request #153 from fishyboteso/wip/keyboard-interup
handling keyboard interupt and exiting main thread safely
This commit is contained in:
commit
bc491c8cb0
@ -2,10 +2,11 @@ import logging
|
||||
import sys
|
||||
|
||||
import fishy
|
||||
from fishy.gui import GUI, splash, update_dialog, check_eula
|
||||
from fishy.gui import GUI, update_dialog, check_eula
|
||||
from fishy import helper, web
|
||||
from fishy.engine.common.event_handler import EngineEventHandler
|
||||
from fishy.gui.log_config import GuiLogger
|
||||
from fishy.gui.splash import Splash
|
||||
from fishy.helper import hotkey
|
||||
from fishy.helper.active_poll import active
|
||||
from fishy.helper.config import config
|
||||
@ -39,6 +40,12 @@ def initialize():
|
||||
helper.install_required_addons()
|
||||
|
||||
|
||||
def on_gui_load(gui, splash, logger):
|
||||
splash.finish()
|
||||
update_dialog.check_update(gui)
|
||||
logger.connect(gui)
|
||||
|
||||
|
||||
def main():
|
||||
print("launching please wait...")
|
||||
|
||||
@ -50,30 +57,33 @@ def main():
|
||||
if not check_eula():
|
||||
return
|
||||
|
||||
finish_splash = splash.start()
|
||||
logger = GuiLogger()
|
||||
config.start_backup_scheduler()
|
||||
active.init()
|
||||
hotkey.init()
|
||||
|
||||
def on_gui_load():
|
||||
finish_splash()
|
||||
update_dialog.check_update(gui)
|
||||
logger.connect(gui)
|
||||
|
||||
bot = EngineEventHandler(lambda: gui)
|
||||
gui = GUI(lambda: bot, on_gui_load)
|
||||
gui = GUI(lambda: bot, lambda: on_gui_load(gui, splash, logger))
|
||||
logger = GuiLogger()
|
||||
hotkey.init()
|
||||
active.init()
|
||||
|
||||
hotkey.start()
|
||||
try:
|
||||
config.init()
|
||||
if not check_eula():
|
||||
return
|
||||
|
||||
logging.info(f"Fishybot v{fishy.__version__}")
|
||||
|
||||
splash = Splash().start()
|
||||
config.start_backup_scheduler()
|
||||
|
||||
initialize()
|
||||
|
||||
hotkey.start()
|
||||
gui.start()
|
||||
active.start()
|
||||
|
||||
bot.start_event_handler() # main thread loop
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("caught KeyboardInterrupt, Stopping main thread")
|
||||
finally:
|
||||
gui.stop()
|
||||
hotkey.stop()
|
||||
active.stop()
|
||||
config.stop()
|
||||
|
@ -69,6 +69,9 @@ class GUI:
|
||||
def create(self):
|
||||
main_gui._create(self)
|
||||
|
||||
def stop(self):
|
||||
self._destroyed = True
|
||||
|
||||
def start(self):
|
||||
self._thread.start()
|
||||
|
||||
|
@ -10,7 +10,19 @@ from fishy.helper import helper
|
||||
from fishy.helper.config import config
|
||||
|
||||
|
||||
def show(win_loc, q):
|
||||
class Splash:
|
||||
def __init__(self):
|
||||
self.q = Queue()
|
||||
self.process = Process(name=Splash.__name__, target=self.show, args=(config.get("win_loc"), self.q,))
|
||||
|
||||
def finish(self):
|
||||
self.q.put("stop")
|
||||
|
||||
def start(self):
|
||||
self.process.start()
|
||||
return self
|
||||
|
||||
def show(self, win_loc, q):
|
||||
logging.debug("started splash process")
|
||||
dim = (300, 200)
|
||||
top = tk.Tk()
|
||||
@ -39,6 +51,7 @@ def show(win_loc, q):
|
||||
q.get()
|
||||
time.sleep(0.2)
|
||||
running[0] = False
|
||||
|
||||
Thread(target=waiting).start()
|
||||
|
||||
running = [True]
|
||||
@ -48,16 +61,3 @@ def show(win_loc, q):
|
||||
|
||||
top.destroy()
|
||||
logging.debug("ended splash process")
|
||||
|
||||
|
||||
def create_finish(q):
|
||||
def finish():
|
||||
q.put("stop")
|
||||
|
||||
return finish
|
||||
|
||||
|
||||
def start():
|
||||
q = Queue()
|
||||
Process(target=show, args=(config.get("win_loc"), q,)).start()
|
||||
return create_finish(q)
|
||||
|
@ -14,12 +14,12 @@ class active:
|
||||
return
|
||||
|
||||
active._scheduler = EventScheduler()
|
||||
active._scheduler.start()
|
||||
logging.debug("active scheduler initialized")
|
||||
|
||||
@staticmethod
|
||||
def start():
|
||||
web.ping()
|
||||
active._scheduler.start()
|
||||
active._scheduler.enter_recurring(60, 1, web.ping)
|
||||
logging.debug("active scheduler started")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user