forked from tecwindow/WikiSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_dialog.py
More file actions
96 lines (78 loc) · 2.73 KB
/
Copy pathupdate_dialog.py
File metadata and controls
96 lines (78 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#-*- coding: utf-8 -*-
# import project libraries.
import wx
import threading
import requests
from urllib.request import urlopen
import os
import json
import subprocess
#geting what's new and download ling from online info file.
try:
# url = "https://mx-blind.com/WikiSearch/WikiSearch.json"
url = "https://raw.githubusercontent.com/tecwindow/WikiSearch/main/WikiSearch.json"
response = urlopen(url)
data_json = json.loads(response.read())
whatIsNew = data_json["What's new"]
DownloadLink = data_json["url"]
except:
pass
#extracting the name file and geting temp path.
try:
file_name = DownloadLink.split('/')[-1]
temp = os.getenv("temp")
path = str(temp+"/"+file_name)
except:
path = ""
#Delete setup file if is found in temp.
if os.path.exists(path):
os.remove(path)
#creating update dialog
class UpdateDialog(wx.Dialog):
def __init__(self, parent):
super().__init__(None, title = "there is an update", size=(300, 300))
self.Center()
self.Maximize(False)
#creating panel
Panel = wx.Panel(self)
#creating field to show what's new.
wx.StaticText(Panel, -1, "What's new in this version?", pos=(20,20), size=(170, 30))
self.WhatsNew = wx.TextCtrl(Panel, -1, value=f"{whatIsNew}", pos=(10,60), size=(250,90))
# Creating Buttons
self.Update = wx.Button(Panel, -1, "Update", pos=(20,200), size=(60,30))
self.Update.SetDefault()
self.Close = wx.Button(Panel, wx.ID_CANCEL, "Cancel", pos=(90,200), size=(60,30))
#show the dialog
self.Show()
#event for update button
self.Update.Bind(wx.EVT_BUTTON, self.OnDownloadUpdate)
#creating OnDownloadUpdate function to show progress dialog.
def OnDownloadUpdate(self, event):
ProgressDialog = progress_dialog("downloading update", "please wait", maximum=100, parent=self, style=wx.PD_CAN_ABORT)
#creating progress dialog
class progress_dialog(wx.ProgressDialog):
def __init__(self, *args, **kwargs):
wx.ProgressDialog.__init__(self, *args, **kwargs)
self.handle = kwargs["parent"]
#making downloading function in thread to download update.
threading.Thread(target=self.downloading, daemon=True).start()
#creating downloading function
def downloading(self):
f = open(path, 'wb')
with requests.get(DownloadLink, stream=True) as r:
downloaded=0
total = int(r.headers['content-length'])
for i in r.iter_content(chunk_size=1024):
if self.WasCancelled():
self.Destroy()
f.close()
os.remove(path)
self.handle.Destroy()
return None
downloaded+=len(i)
progress = int((downloaded/total)*100)
f.write(i)
if progress == 100:
f.close()
subprocess.run([path, "/SILENT", "/VERYSILENT", "/SUPPRESSMSGBOXES"])
self.Update(progress)