fishyboteso/fishy/gui/splash.py
Adam Saudagar 17c014d690 close splash when gui finishes loading
hide fishy window until its ready to show
draw splash screen above fishy window
2022-02-03 01:06:41 +05:30

55 lines
1.4 KiB
Python

import logging
import time
import tkinter as tk
from multiprocessing import Process, Queue
from PIL import Image, ImageTk
from fishy.helper import helper
from fishy.helper.config import config
def show(win_loc, q):
logging.debug("started splash process")
dim = (300, 200)
top = tk.Tk()
top.overrideredirect(True)
top.lift()
top.attributes('-topmost', True)
top.title("Loading...")
top.resizable(False, False)
top.iconbitmap(helper.manifest_file('icon.ico'))
canvas = tk.Canvas(top, width=dim[0], height=dim[1], bg='white')
canvas.pack()
top.image = Image.open(helper.manifest_file('fishybot_logo.png')).resize(dim)
top.image = ImageTk.PhotoImage(top.image)
canvas.create_image(0, 0, anchor=tk.NW, image=top.image)
# Position splash at the center of the main window
default_loc = (str(top.winfo_reqwidth()) + "+" + str(top.winfo_reqheight()) + "+" + "0" + "0")
loc = (win_loc or default_loc).split("+")[1:]
top.geometry("{}x{}+{}+{}".format(dim[0], dim[1], int(loc[0]) + int(dim[0] / 2), int(loc[1]) + int(dim[1] / 2)))
top.update()
q.get()
time.sleep(0.2)
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)