mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
add update dialog
This commit is contained in:
parent
3c0b6488b7
commit
444aef9f20
@ -9,7 +9,7 @@ import win32gui
|
|||||||
import fishy
|
import fishy
|
||||||
from fishy import web, helper, gui
|
from fishy import web, helper, gui
|
||||||
from fishy.engine.common.event_handler import EngineEventHandler
|
from fishy.engine.common.event_handler import EngineEventHandler
|
||||||
from fishy.gui import GUI, splash
|
from fishy.gui import GUI, splash, update_dialog
|
||||||
from fishy.helper import hotkey
|
from fishy.helper import hotkey
|
||||||
from fishy.helper.config import config
|
from fishy.helper.config import config
|
||||||
|
|
||||||
@ -36,11 +36,19 @@ def initialize(window_to_hide):
|
|||||||
is_admin = os.getuid() == 0
|
is_admin = os.getuid() == 0
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
|
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
|
||||||
|
|
||||||
if is_admin:
|
if is_admin:
|
||||||
logging.info("Running with admin privileges")
|
logging.info("Running with admin privileges")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if helper.upgrade_avail() and not config.get("dont_ask_update", False):
|
||||||
|
cv,hv = helper.versions()
|
||||||
|
update_now, dont_ask_update = update_dialog.start(cv,hv)
|
||||||
|
if dont_ask_update:
|
||||||
|
config.set("dont_ask_update", dont_ask_update)
|
||||||
|
else:
|
||||||
|
config.delete("dont_ask_update")
|
||||||
|
|
||||||
|
if update_now:
|
||||||
helper.auto_upgrade()
|
helper.auto_upgrade()
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.error(traceback.format_exc())
|
logging.error(traceback.format_exc())
|
||||||
|
43
fishy/gui/update_dialog.py
Normal file
43
fishy/gui/update_dialog.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from multiprocessing import Process, Manager
|
||||||
|
from tkinter import *
|
||||||
|
import time
|
||||||
|
|
||||||
|
def show(currentversion, newversion, returns):
|
||||||
|
top = Tk()
|
||||||
|
top.title("A wild update appears!")
|
||||||
|
|
||||||
|
dialogLabel = Label(top, text="There is a new update available ("+currentversion+"->"+newversion+"). Do you want to update now?")
|
||||||
|
dialogLabel.grid(row=0, columnspan=2, padx=5, pady=5)
|
||||||
|
|
||||||
|
cbVar = IntVar()
|
||||||
|
dialogCheckbutton = Checkbutton(top, text="don't ask again", variable=cbVar)
|
||||||
|
dialogCheckbutton.grid(row=1, columnspan=2, padx=5, pady=0)
|
||||||
|
top.update()
|
||||||
|
buttonWidth = int(dialogLabel.winfo_width()/2)-20
|
||||||
|
|
||||||
|
def _clickYes():
|
||||||
|
returns[0],returns[1]=True, False
|
||||||
|
top.destroy()
|
||||||
|
|
||||||
|
def _clickNo():
|
||||||
|
returns[0],returns[1]=False, bool(cbVar.get())
|
||||||
|
top.destroy()
|
||||||
|
|
||||||
|
pixelVirtual = PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols
|
||||||
|
dialogBtnYes = Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, width=buttonWidth, compound="c")
|
||||||
|
dialogBtnYes.grid(row=2, column=0, padx=5, pady=5)
|
||||||
|
dialogBtnNo = Button(top, text="No " + str(chr(10005)), fg='red', command=_clickNo, image=pixelVirtual, width=buttonWidth, compound="c")
|
||||||
|
dialogBtnNo.grid(row=2, column=1, padx=5, pady=5)
|
||||||
|
|
||||||
|
top.protocol('WM_DELETE_WINDOW', _clickNo)
|
||||||
|
|
||||||
|
top.update()
|
||||||
|
top.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
def start(currentversion, newversion):
|
||||||
|
returns = Manager().dict()
|
||||||
|
p = Process(target=show, args=(currentversion, newversion, returns))
|
||||||
|
p.start()
|
||||||
|
p.join()
|
||||||
|
return returns[0], returns[1]
|
Loading…
Reference in New Issue
Block a user