Repository navigation
Expand file tree
/
Copy pathPyGet.py
More file actions
180 lines (145 loc) · 5.35 KB
/
Copy pathPyGet.py
File metadata and controls
180 lines (145 loc) · 5.35 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from tkinter import *
from tkinter import messagebox
import os, platform, subprocess as sp, sys
# We want to create a new window
root = Tk()
root.title("PyGet - Pip GUI")
root.config(bg='#3d3d3d')
root.geometry("500x400")
# We decided that it can remain resizable
#root.resizable(0, 0)
# Find os name
osname = platform.system()
# Check for osname, and change the PIP command
# If this doesnt work on your operating system. Please open a github issue
if osname == "Linux": execc = "python3 -m pip"
elif osname == "Windows": execc = "pip"
elif osname == "Darwin": exec = "pip"
elif osname == "Java":
# I dont know the pip command (or even if python is supported) on Java based platforms.
messagebox.showerror("Unsupported OS?", f"Java based Plaforms are not supported by PyGet?")
sys.exit()
else:
# IDK if python supports any other OS
messagebox.showerror("Unsupported OS?", f"{osname} OS/Platform is not suppored by PyGet?")
sys.exit()
print(execc)
# Define some help text
help_text = """PyGet is an GUI for pip, pythons package manager. PyGet allows you to:
- Install PIP moudles
- Execute pip commands
- Show this help message"""
# Create an input box
inputs = Entry(root, bg='#808080', fg='black', bd=0, state=DISABLED)
inputs.config(font=('Consolas', 16), selectbackground='lightblue')
inputs.config(selectforeground='black', highlightthickness=0)
inputs.pack(fill='x', side='bottom', ipady=3, ipadx=3)
# Header
header = Label(root, bg='#3d3d3d', text='PyGet - Pip GUI', fg='white')
header.config(font=('arab', 26))
header.pack(fill='x', padx=5, pady=5)
# Now the frame
frames = Frame(root, bg='#808080', bd=0)
frames.pack(anchor='center')
def hidexe():
output.config(state=NORMAL)
inputs.config(state=NORMAL)
output.delete(1.0, END)
inputs.config(state=DISABLED)
output.config(state=DISABLED)
exec_btn.config(command=execWpip)
def executeThePip(e):
global output
pip_cmd_out = str(sp.getoutput(f"{execc} {inputs.get()}"))
output.pack(fill='x', expand=1, pady=5, padx=5)
output.config(state=NORMAL)
output.delete(1.0, END)
output.insert(1.0, pip_cmd_out)
output.config(state=DISABLED)
inputs.config(state=DISABLED)
exec_btn.config(command=hidexe)
print(pip_cmd_out)
# An pip exec function
def execWpip():
inputs.config(state=NORMAL)
inputs.bind("<Return>", executeThePip)
# Hide view
def hideView():
output.pack_forget()
output.config(state=DISABLED)
view_btn.config(command=pip_view)
# View function
def pip_view():
global output
ls_out = str(sp.getoutput(f"{execc} list"))
output.pack(fill='x', expand=1, pady=5, padx=5)
output.config(state=NORMAL)
output.delete(1.0, END)
output.insert(1.0, ls_out)
output.config(state=DISABLED)
view_btn.config(command=hideView)
# hide pip
def hidePip():
global output, inputs
output.pack_forget()
output.config(state=DISABLED)
inputs.config(state=DISABLED)
install_btn.config(command=install)
# execute pip
def exec_pip(e):
global output
exec_out = str(sp.getoutput(f"{execc} install {inputs.get()}"))
output.pack(fill='x', expand=1, pady=5, padx=5)
output.config(state=NORMAL)
output.delete(1.0, END)
output.insert(1.0, exec_out)
output.config(state=DISABLED)
install_btn.config(command=hidePip)
print(exec_out)
# install function
def install():
inputs.config(state=NORMAL)
inputs.bind("<Return>", exec_pip)
# Hide help
def hideHelp():
output.pack_forget()
output.config(state=NORMAL)
output.delete(1.0, END)
output.config(state=DISABLED)
help_btn.config(command=getHelp)
# Help function
def getHelp():
output.pack(fill='x', expand=1, pady=5, padx=5)
output.config(state=NORMAL)
output.insert(1.0, help_text)
output.config(state=DISABLED)
help_btn.config(command=hideHelp)
# Install button
install_btn = Button(frames, bg='#808080', text='Install', bd=0, fg='white', command=install)
install_btn.configure(highlightthickness=0, font=('Consolas', 18))
install_btn.config(activebackground='#808080', activeforeground='#1a1a1a')
install_btn.grid(row=0, column=0, ipady=1, ipadx=1, sticky='w', padx=8)
# Help button
help_btn = Button(frames, bg='#808080', text='Help', bd=0, fg='white', command=getHelp)
help_btn.configure(highlightthickness=0, font=('Consolas', 18))
help_btn.config(activebackground='#808080', activeforeground='#1a1a1a')
help_btn.grid(row=0, column=1, ipady=1, ipadx=1, sticky='e', padx=8)
# View button
view_btn = Button(frames, bg='#808080', text='View', bd=0, fg='white', command=pip_view)
view_btn.configure(highlightthickness=0, font=('Consolas', 18))
view_btn.config(activebackground='#808080', activeforeground='#1a1a1a')
view_btn.grid(row=0, column=3, ipady=1, ipadx=1, sticky='e', padx=8)
# Execute command
exec_btn = Button(frames, bg='#808080', text='PIP', bd=0, fg='white', command=execWpip)
exec_btn.configure(highlightthickness=0, font=('Consolas', 18))
exec_btn.config(activebackground='#808080', activeforeground='#1a1a1a')
exec_btn.grid(row=0, column=4, ipady=1, ipadx=1, sticky='e', padx=8)
# Output
output = Text(root, bg='#3d3d3d', bd=0, font=('Arab', 14), selectforeground='white')
output.config(highlightthickness=0, selectbackground='#3d3d3d', fg='white', state=DISABLED, wrap=WORD)
# Mainloop
if __name__ == "__main__":
try:
root.mainloop()
except EOFError: pass
except KeyboardInterrupt: pass