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 sys
|
||||||
|
|
||||||
import fishy
|
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 import helper, web
|
||||||
from fishy.engine.common.event_handler import EngineEventHandler
|
from fishy.engine.common.event_handler import EngineEventHandler
|
||||||
from fishy.gui.log_config import GuiLogger
|
from fishy.gui.log_config import GuiLogger
|
||||||
|
from fishy.gui.splash import Splash
|
||||||
from fishy.helper import hotkey
|
from fishy.helper import hotkey
|
||||||
from fishy.helper.active_poll import active
|
from fishy.helper.active_poll import active
|
||||||
from fishy.helper.config import config
|
from fishy.helper.config import config
|
||||||
@ -39,6 +40,12 @@ def initialize():
|
|||||||
helper.install_required_addons()
|
helper.install_required_addons()
|
||||||
|
|
||||||
|
|
||||||
|
def on_gui_load(gui, splash, logger):
|
||||||
|
splash.finish()
|
||||||
|
update_dialog.check_update(gui)
|
||||||
|
logger.connect(gui)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("launching please wait...")
|
print("launching please wait...")
|
||||||
|
|
||||||
@ -50,30 +57,33 @@ def main():
|
|||||||
if not check_eula():
|
if not check_eula():
|
||||||
return
|
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)
|
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__}")
|
logging.info(f"Fishybot v{fishy.__version__}")
|
||||||
|
|
||||||
|
splash = Splash().start()
|
||||||
|
config.start_backup_scheduler()
|
||||||
|
|
||||||
initialize()
|
initialize()
|
||||||
|
|
||||||
|
hotkey.start()
|
||||||
gui.start()
|
gui.start()
|
||||||
active.start()
|
active.start()
|
||||||
|
|
||||||
bot.start_event_handler() # main thread loop
|
bot.start_event_handler() # main thread loop
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("caught KeyboardInterrupt, Stopping main thread")
|
||||||
|
finally:
|
||||||
|
gui.stop()
|
||||||
hotkey.stop()
|
hotkey.stop()
|
||||||
active.stop()
|
active.stop()
|
||||||
config.stop()
|
config.stop()
|
||||||
|
@ -69,6 +69,9 @@ class GUI:
|
|||||||
def create(self):
|
def create(self):
|
||||||
main_gui._create(self)
|
main_gui._create(self)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._destroyed = True
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self._thread.start()
|
self._thread.start()
|
||||||
|
|
||||||
|
@ -10,7 +10,19 @@ from fishy.helper import helper
|
|||||||
from fishy.helper.config import config
|
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")
|
logging.debug("started splash process")
|
||||||
dim = (300, 200)
|
dim = (300, 200)
|
||||||
top = tk.Tk()
|
top = tk.Tk()
|
||||||
@ -39,6 +51,7 @@ def show(win_loc, q):
|
|||||||
q.get()
|
q.get()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
running[0] = False
|
running[0] = False
|
||||||
|
|
||||||
Thread(target=waiting).start()
|
Thread(target=waiting).start()
|
||||||
|
|
||||||
running = [True]
|
running = [True]
|
||||||
@ -48,16 +61,3 @@ def show(win_loc, q):
|
|||||||
|
|
||||||
top.destroy()
|
top.destroy()
|
||||||
logging.debug("ended splash process")
|
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
|
return
|
||||||
|
|
||||||
active._scheduler = EventScheduler()
|
active._scheduler = EventScheduler()
|
||||||
active._scheduler.start()
|
|
||||||
logging.debug("active scheduler initialized")
|
logging.debug("active scheduler initialized")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def start():
|
def start():
|
||||||
web.ping()
|
web.ping()
|
||||||
|
active._scheduler.start()
|
||||||
active._scheduler.enter_recurring(60, 1, web.ping)
|
active._scheduler.enter_recurring(60, 1, web.ping)
|
||||||
logging.debug("active scheduler started")
|
logging.debug("active scheduler started")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user