2022-02-02 21:10:22 +00:00
|
|
|
import logging
|
2021-05-09 06:32:36 +00:00
|
|
|
import tkinter as tk
|
2021-02-14 18:07:49 +00:00
|
|
|
|
2022-02-02 21:10:22 +00:00
|
|
|
from fishy.helper import helper, auto_update
|
|
|
|
from fishy.helper.config import config
|
|
|
|
from fishy.helper.popup import PopUp
|
2021-03-24 11:20:38 +00:00
|
|
|
|
2021-05-09 07:05:51 +00:00
|
|
|
|
2022-02-02 21:10:22 +00:00
|
|
|
def _show(gui, currentversion, newversion, returns):
|
|
|
|
|
|
|
|
def _clickYes():
|
|
|
|
returns[0], returns[1] = True, False
|
|
|
|
top.quit_top()
|
|
|
|
|
|
|
|
def _clickNo():
|
|
|
|
returns[0], returns[1] = False, bool(cbVar.get())
|
|
|
|
top.quit_top()
|
|
|
|
|
|
|
|
top = PopUp(helper.empty_function, gui._root)
|
2021-03-24 11:20:38 +00:00
|
|
|
top.title("A wild fishy update appeared!")
|
|
|
|
top.iconbitmap(helper.manifest_file('icon.ico'))
|
2021-02-14 18:07:49 +00:00
|
|
|
|
2021-05-09 09:44:19 +00:00
|
|
|
dialogLabel = tk.Label(top, text="There is a new fishy update available (" +
|
|
|
|
currentversion + "->" + newversion + "). Do you want to update now?")
|
2021-02-14 18:07:49 +00:00
|
|
|
dialogLabel.grid(row=0, columnspan=2, padx=5, pady=5)
|
|
|
|
|
2021-05-09 06:32:36 +00:00
|
|
|
cbVar = tk.IntVar()
|
|
|
|
dialogCheckbutton = tk.Checkbutton(top, text="don't ask again", variable=cbVar)
|
2021-02-14 18:07:49 +00:00
|
|
|
dialogCheckbutton.grid(row=1, columnspan=2, padx=5, pady=0)
|
|
|
|
top.update()
|
2021-05-09 09:09:26 +00:00
|
|
|
buttonWidth = int(dialogLabel.winfo_width() / 2) - 20
|
2021-02-14 18:07:49 +00:00
|
|
|
|
2021-05-09 09:09:26 +00:00
|
|
|
pixelVirtual = tk.PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols
|
2021-05-09 09:44:19 +00:00
|
|
|
dialogBtnNo = tk.Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual,
|
|
|
|
width=buttonWidth, compound="c")
|
2021-03-24 11:20:16 +00:00
|
|
|
dialogBtnNo.grid(row=2, column=0, padx=5, pady=5)
|
2021-05-09 09:44:19 +00:00
|
|
|
dialogBtnYes = tk.Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual,
|
|
|
|
width=buttonWidth, compound="c")
|
2021-03-24 11:20:16 +00:00
|
|
|
dialogBtnYes.grid(row=2, column=1, padx=5, pady=5)
|
|
|
|
dialogBtnYes.focus_set()
|
2021-02-14 18:07:49 +00:00
|
|
|
|
|
|
|
top.protocol('WM_DELETE_WINDOW', _clickNo)
|
2022-02-02 21:10:22 +00:00
|
|
|
top.start()
|
2021-02-14 18:07:49 +00:00
|
|
|
|
|
|
|
|
2022-02-02 22:27:22 +00:00
|
|
|
def check_update(gui, manual_check=False):
|
2022-02-02 21:10:22 +00:00
|
|
|
if not auto_update.upgrade_avail() or config.get("dont_ask_update", False):
|
2022-02-02 22:27:22 +00:00
|
|
|
if manual_check:
|
|
|
|
logging.info("No update is available.")
|
2022-02-02 21:10:22 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
cv, hv = auto_update.versions()
|
|
|
|
returns = [None, None]
|
|
|
|
_show(gui, cv, hv, returns)
|
|
|
|
[update_now, dont_ask_update] = returns
|
|
|
|
if dont_ask_update:
|
|
|
|
config.set("dont_ask_update", dont_ask_update)
|
|
|
|
else:
|
|
|
|
config.delete("dont_ask_update")
|
2021-02-14 18:07:49 +00:00
|
|
|
|
2022-02-02 21:10:22 +00:00
|
|
|
if update_now:
|
|
|
|
gui.engine.set_update(hv)
|