-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
307 lines (263 loc) · 11 KB
/
main.py
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# required modules
import tkinter as tk
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
import os,sys
from PIL import Image, ImageTk
from pathlib import Path
# App: RoyalManager - Termux Packages Manager
# Creator: Raunak Raj
# Version: 1.1(beta)
print('''
App: RoyalManager
Creator: Raunak Raj
Version: 1.1(beta)
''')
ASSETS_PATH = Path(__file__).resolve().parent / "assets"
class aboutApp(tk.Tk):
def __init__(self):
super().__init__()
#window setup
self.geometry('280x320')
self.title('About RoyalManager')
self.resizable(False, False)
self.config(bg="#fff")
self.style = ttk.Style(self)
self.style.configure(
'label1.TLabel',
background="#fff",
foreground="#000",
font=("Tahoma Bold",20)
)
self.style.configure(
'label2.TLabel',
background="#fff",
foreground="#000",
font=("Tahoma Bold",9)
)
self.style.configure(
'aboutxt.TLabel',
background="#fff",
foreground="#1f1f1f",
font=("Tahoma",11)
)
self.style.configure(
'copyrightxt.TLabel',
background="#313131",
foreground="#fff",
font=("Tahoma Bold",11)
)
self.add_logo_img()
self.label1 = ttk.Label(self,text="RoyalManager",style="label1.TLabel",justify=tk.CENTER)
self.label1.pack(side="top")
self.label2 = ttk.Label(self,text="Version: 1.1(beta)",style="label2.TLabel",justify=tk.CENTER)
self.label2.pack()
self.abtxt = '''
GUI based termux packages
manager for termux desktop,
developed by Raunak Raj.
'''
self.aboutxt = ttk.Label(self,text=self.abtxt,style="aboutxt.TLabel",justify=tk.CENTER)
self.aboutxt.pack(padx=5,pady=5)
self.copyrightxt = ttk.Label(self,text="Copyright © 2022 Raunak Raj",style="copyrightxt.TLabel",justify=tk.CENTER)
self.copyrightxt.pack(side="bottom",anchor="s",pady=5,padx=5)
def add_logo_img(self):
self.canvas1 = tk.Canvas(self, width = 150, height = 135,background="#fff",bd=0,highlightthickness=0)
self.canvas1.pack()
self.img1 = ImageTk.PhotoImage(Image.open(ASSETS_PATH / "img2.png"),master=self.canvas1)
self.canvas1.create_image(75, 67, image=self.img1)
class MainApp(tk.Tk):
def __init__(self):
super().__init__()
#window setup
self.geometry('300x285')
self.title('RoyalManager')
self.resizable(False, False)
self.logo = ImageTk.PhotoImage(Image.open(ASSETS_PATH / "app_icon.png"))
self.iconphoto(False, self.logo)
self.style = ttk.Style(self)
self.style.configure(
'Inp1.TEntry',
fieldbackground="#fff",
foreground="#000",
borderwidth=1,
font=("Verdana",18)
)
self.style.configure(
'Search_btn.TButton',
background="#56e8e8",
foreground="#fff",
borderwidth=1,
font=("Verdana",12),
focusthickness=3,
focuscolor="none"
)
self.style.map('Search_btn.TButton', background=[('active','#86f7f7')])
self.style.configure(
'inst_btn.TButton',
background="#0dd51e",
foreground="#fff",
borderwidth=1,
font=("Verdana",12),
focusthickness=3,
focuscolor="none"
)
self.style.map('inst_btn.TButton', background=[('active','#51f55f')])
self.style.configure(
'uninst_btn.TButton',
background="#fe0000",
foreground="#fff",
borderwidth=1,
font=("Verdana",12),
focusthickness=3,
focuscolor="none"
)
self.style.map('uninst_btn.TButton', background=[('active','#f55c5c')])
# menubar
menubar = tk.Menu(
self,
bg="#090909",
fg="#fff",
activebackground="#242424",
activeforeground="#fff",
borderwidth=0,
activeborderwidth=0,
font=("Tahoma",12)
)
self.config(menu=menubar,bg="#fff")
# action menu
action_menu = tk.Menu(menubar,tearoff=0,bg="#090909",fg="#fff",activebackground="#242424",activeforeground="#fff",borderwidth=0,activeborderwidth=0,font=("Tahoma",12))
# menu items of Action menu
action_menu.add_command(label='Update Mirrors',command=self.update_mirrors)
action_menu.add_command(label='Upgrade Packages',command=self.upgrade_pkg)
action_menu.add_command(label='Clean Cache',command=self.clean_cache)
action_menu.add_command(label='Autoremove Cache Packages',command=self.autorm_cache_pkg)
action_menu.add_separator()
# Exit menu item
action_menu.add_command(label='Exit',command=self.destroy)
menubar.add_cascade(label="Actions",menu = action_menu)
# help menu
help_menu = tk.Menu(menubar,tearoff=0,bg="#090909",fg="#fff",activebackground="#242424",activeforeground="#fff",borderwidth=0,activeborderwidth=0,font=("Tahoma",13))
self.abouticon = ImageTk.PhotoImage(Image.open(ASSETS_PATH / "about.png"))
# menu items of Help menu
help_menu.add_command(label='About',image=self.abouticon,compound="left",command=self.about)
menubar.add_cascade(label="Help",menu=help_menu)
# main label
main_label = ttk.Label(
self,
text="Welcome to Pkg Manager",
background="#fff",
foreground="#000",
font=("Verdana", '15')
)
main_label.place(x=20,y=7)
# entry box
self.pkg_nme_var = tk.StringVar()
pkg_nme = ttk.Entry(self,style="Inp1.TEntry",textvar=self.pkg_nme_var)
pkg_nme.place(x=15,y=47,height=25)
pkg_nme.insert(0, "Enter package name...")
filter_btn = ttk.Button(self,text="Search",style="Search_btn.TButton",command=self.search_pkg)
filter_btn.place(x=188,y=45)
self.terminal_area = ScrolledText(self,state="disabled",height=10,width=35,bg="black",fg="#08c614",insertbackground="#08c614",selectbackground="#fff")
self.terminal_area.place(x=15,y=85)
self.install_btn = ttk.Button(self,text="Install",style="inst_btn.TButton",command=self.install_pkg)
self.install_btn.place_forget()
self.uninstall_btn = ttk.Button(self,text="Uninstall",style="uninst_btn.TButton",command=self.uninstall_pkg)
self.uninstall_btn.place_forget()
def update_mirrors(self):
cmd = "apt-get update"
p = os.popen(cmd)
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",p.read())
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
def upgrade_pkg(self):
cmd="apt-get upgrade -y"
p = os.popen(cmd)
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",p.read())
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
def clean_cache(self):
cmd='apt-get clean && apt-get autoclean'
p = os.popen(cmd)
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",p.read())
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
def autorm_cache_pkg(self):
cmd="apt-get autoremove -y"
p = os.popen(cmd)
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",p.read())
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
def search_pkg(self):
rest_keyword=["ls","la"]
if self.pkg_nme_var.get() in rest_keyword:
showwarning("Bad Pkg Name","Please enter correct package name, not any command.")
else:
cmd=f"apt show {self.pkg_nme_var.get()}"
p = os.popen(cmd)
p1 = os.popen("pkg list-installed").read()
output = p.read()
if self.pkg_nme_var.get() in p1:
print(output)
self.uninstall_btn.place_forget()
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",output)
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
self.uninstall_btn.place(x=20,y=250)
elif self.pkg_nme_var.get() not in p1:
if output == '':
print(f"\n\nNo any package with name : {self.pkg_nme_var.get()}")
self.uninstall_btn.place_forget()
self.install_btn.place_forget()
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",f"No any package with name : {self.pkg_nme_var.get()}")
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
else:
print(output)
self.uninstall_btn.place_forget()
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",output)
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
self.install_btn.place(x=20,y=250)
def install_pkg(self):
cmd = f"apt install -y {self.pkg_nme_var.get()}"
p = os.popen(cmd)
output = p.read()
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",output)
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
self.install_btn.place_forget()
self.uninstall_btn.place(x=20,y=250)
def uninstall_pkg(self):
cmd = f"apt purge -y {self.pkg_nme_var.get()}"
p = os.popen(cmd)
output = p.read()
self.terminal_area["state"] = "normal"
self.terminal_area.delete(0.1,"end")
self.terminal_area.insert("end",output)
self.terminal_area.see("end")
self.terminal_area["state"] = "disabled"
self.uninstall_btn.place_forget()
self.install_btn.place(x=20,y=250)
def about(self):
aboutapp = aboutApp()
aboutapp.mainloop
if __name__ == "__main__":
app = MainApp()
app.mainloop()