Repository navigation
Expand file tree
/
Copy pathpynotes_plugin_installer.py
More file actions
110 lines (99 loc) · 3.19 KB
/
Copy pathpynotes_plugin_installer.py
File metadata and controls
110 lines (99 loc) · 3.19 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import platform
import time
import shutil
from tkinter import messagebox as mb
import getpass
import urllib.request
import urllib.error
import os
import tkinter as tk
try:
import ttkbootstrap
except:
from tkinter import ttk
try:
import ttkthemes
except:
root = tk.Tk()
ttk.Style().theme_use("clam")
else:
root = ttkthemes.ThemedTk(theme="breeze")
else:
import ttkbootstrap as ttk
root = ttk.Window(themename="pulse")
if platform.system() == "Linux":
homedir = f"/home/{getpass.getuser()}"
else:
homedir = f"C:/Users/{getpass.getuser()}"
def download(url, filename):
urllib.request.urlretrieve(url, filename)
root.geometry("400x400")
root.title("PyNotes Plugin Installer")
infotext = ttk.Label(
root, text="Downloading list of plugins", font=("TkDefaultFont", 15)
)
infotext.pack(anchor="nw", padx=10, pady=10)
selectframe = ttk.Frame(master=root)
selectframe.pack(fill="both", expand=True)
pb = ttk.Progressbar()
root.update()
listurl = "https://raw.githubusercontent.com/rafugafu/PyNotes/main/Plugins/list"
try:
with urllib.request.urlopen(listurl) as requested:
listplugins = requested.read().decode()
except Exception as e:
mb.showerror(
"Error", f"There was an error in downloading the list of plugins:\n{e}"
)
root.destroy()
exit()
def done():
installing = [
plugincheck[0] for plugincheck in pluginchecks if plugincheck[1].get()
]
if not installing:
mb.showinfo("Info", "Select plugins to install")
return
if not mb.askokcancel(
"Installing",
f'These plugins will be installed:\n\n{"\n".join(f'"{x}"' for x in installing)}\n\nContinue?',
):
return
donebutton.config(state="disabled")
[plugincheck[2].config(state="disabled") for plugincheck in pluginchecks]
pb.pack(anchor="nw", padx=10, pady=10)
increment = 100 / len(installing)
for plugin in installing:
infotext.config(text=f'Installing plugin "{plugin}"')
root.update()
try:
url = f'https://raw.githubusercontent.com/rafugafu/PyNotes/main/Plugins/{plugin.replace(" ", "%20")}.zip'
filename = f"{plugin}.zip"
download(url, filename)
os.makedirs(f"{homedir}/.local/share/PyNotes/add-ons", exist_ok=True)
shutil.unpack_archive(filename, f"{homedir}/.local/share/PyNotes/add-ons")
os.remove(filename)
except Exception as e:
mb.showerror(
"Error",
f"There was an error in downloading and installing the plugin:\n{e}",
)
pb["value"] += increment
root.update()
infotext.config(text="Done!")
pluginchecks = []
row = 0
infotext.config(text="Select the plugins to (re)install or update:")
root.update()
for plugin in listplugins.strip().split("\n"):
bv = tk.BooleanVar()
pluginchecks.append(
(plugin, bv, ttk.Checkbutton(selectframe, text=plugin, variable=bv))
)
pluginchecks[-1][2].grid(column=0, row=row, padx=10, pady=10, sticky="w")
row += 1
root.update()
time.sleep(0.1)
donebutton = ttk.Button(selectframe, text="Done", command=done)
donebutton.grid(column=0, row=row)
root.mainloop()