-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
5255 lines (4837 loc) · 291 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from tkinter import *
import urllib
from urllib import request
from PIL import Image, ImageTk
from tkinter import messagebox
from tkinter import ttk
import sv_ttk as sv
import os
import requests
from ctypes import windll
import subprocess
import webbrowser
import json
import ctypes
import sys
import threading
import time
import re
def firsttimewindow():
global firsttime
firsttime = Toplevel()
firsttime.overrideredirect(True)
app_width = 1024
app_height = 512
screenwidth = firsttime.winfo_screenwidth()
screenheight = firsttime.winfo_screenheight()
x = (screenwidth / 2) - (app_width / 2)
y = (screenheight / 2) - (app_height / 2)
firsttime.geometry(f'{app_width}x{app_height}+{int(x)}+{int(y)}')
firsttime.mainloop()
def nointernetwindow(x):
if x == "mainsplash":
mainsplash.withdraw()
elif x == "main":
main.withdraw()
noint = Toplevel()
noint.overrideredirect(True)
app_width = 1024
app_height = 512
screenwidth = noint.winfo_screenwidth()
screenheight = noint.winfo_screenheight()
noint.attributes("-alpha", 1)
x = (screenwidth / 2) - (app_width / 2)
y = (screenheight / 2) - (app_height / 2)
noint.geometry(f'{app_width}x{app_height}+{int(x)}+{int(y)}')
bg_image1 = ImageTk.PhotoImage(Image.open(r"images\noconnection.png"))
label2 = Label(noint, image=bg_image1)
label2.pack()
noint.bind("<Button-1>", lambda e: noint.destroy())
noint.bind("<Button-3>", lambda e: intcheckapp(x))
noint.mainloop()
def intcheckapp(x):
def internet_stat(url="https://www.google.com/", timeout=3):
try:
r = requests.head(url=url, timeout=timeout)
return True
except requests.exceptions.ConnectionError as e:
return False
net_stat = internet_stat()
if net_stat == False:
nointernetwindow(x)
elif net_stat == True:
if x == "mainsplash":
mainsplash.deiconify()
elif x == "main":
main.deiconify()
def themecheck():
with open("theme.json", "r") as file:
global mode
data = json.load(file)
mode = data["mode"]
with open("settings.json", "r") as x:
data = json.load(x)
global autoupdateval
autoupdateval=data["autoupdate"]
themecheck()
global is_on
if mode == "light":
is_on = True
elif mode == "dark":
is_on = False
mainsplash = Tk()
sv.set_theme(mode)
mainsplash.overrideredirect(True)
app_width = 1024
app_height = 512
screenwidth = mainsplash.winfo_screenwidth()
screenheight = mainsplash.winfo_screenheight()
mainsplash.attributes("-alpha", 1)
x = (screenwidth / 2) - (app_width / 2)
y = (screenheight / 2) - (app_height / 2)
mainsplash.geometry(f'{app_width}x{app_height}+{int(x)}+{int(y)}')
if mode == "dark":
bg_image = ImageTk.PhotoImage(Image.open(r"images\softhub load dark.png"))
label1 = Label(mainsplash, image=bg_image)
label1.pack()
elif mode == "light":
bg_image = ImageTk.PhotoImage(Image.open(r"images\softhub load light.png"))
label1 = Label(mainsplash, image=bg_image)
label1.pack()
#intcheckapp("mainsplash")
def checkpack(packtype):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
if packtype == "🌐 Winget":
packages = str(subprocess.run(["winget", "list", "--source", "winget"], check=True, capture_output=True,startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW))
return packages
def set_appwindow(mainWindow): # to display the window icon on the taskbar,
# even when using main.overrideredirect(True)
# Some WindowsOS styles, required for task bar integration
GWL_EXSTYLE = -20
WS_EX_APPWINDOW = 0x00040000
WS_EX_TOOLWINDOW = 0x00000080
# Magic
hwnd = windll.user32.GetParent(mainWindow.winfo_id())
stylew = windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
stylew = stylew & ~WS_EX_TOOLWINDOW
stylew = stylew | WS_EX_APPWINDOW
res = windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, stylew)
mainWindow.wm_withdraw()
mainWindow.after(10, lambda: mainWindow.wm_deiconify())
def minimize_me():
main.attributes("-alpha",0) # so you can't see the window when is minimized
main.minimized = True
main.bind("<FocusIn>",deminimize)
def fake_func(event):
return None
def deminimize(event):
main.focus()
main.attributes("-alpha",1) # so you can see the window when is not minimized
if main.minimized == True:
main.minimized = False
main.bind("<FocusIn>",fake_func)
def deminimzewhenappinstalled():
main.focus()
main.attributes("-alpha", 1) # so you can see the window when is not minimized
if main.minimized == True:
main.minimized = False
def maximize_me():
if main.maximized == False: # if the window was not maximized
main.normal_size = main.geometry()
expand_button.config(text=" 🗗 ")
main.geometry(f"{main.winfo_screenwidth()}x{main.winfo_screenheight()}+0+0")
main.maximized = not main.maximized
# maximized
else: # if the window was maximized
expand_button.config(text=" ◻ ")
main.geometry(main.normal_size)
main.maximized = not main.maximized
# not maximized
def changex_on_hovering(event):
global close_button
close_button['bg'] = 'red'
def returnx_to_normalstate(event):
global close_button
themecheck()
if mode =="dark":
close_button['bg'] = '#1c1c1c'
elif mode =="light":
close_button['bg'] = '#fafafa'
def change_size_on_hovering(event):
global expand_button
expand_button['bg'] = '#999999'
def return_size_on_hovering(event):
global expand_button
themecheck()
if mode =="dark":
expand_button['bg'] = '#1c1c1c'
if mode =="light":
expand_button['bg'] = '#fafafa'
def changem_size_on_hovering(event):
global minimize_button
minimize_button['bg'] = '#999999'
def returnm_size_on_hovering(event):
global minimize_button
themecheck()
if mode =="dark":
minimize_button['bg'] = '#1c1c1c'
if mode =="light":
minimize_button['bg'] = '#fafafa'
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def autoupdate():
if autoupdateval == 1:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
x=subprocess.run(["winget", "upgrade"], capture_output=True, text=True,startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW)
app_names = re.findall(r'^\s*(.+?)\s{2,}', x.stdout, flags=re.MULTILINE)
app_names = app_names[2:-1]
for i in app_names:
subprocess.run(["winget", "upgrade", i],stderr=subprocess.PIPE,startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW)
def mainwindow():
global close_button
global expand_button
global minimize_button
global main
main = Toplevel()
threading.Thread(target=autoupdate).start()
main.tk.call('wm', 'iconphoto', main._w, ImageTk.PhotoImage(file='images\softhub.ico'))
mainsplash.withdraw()
screenwidth = main.winfo_screenwidth()
screenheight = main.winfo_screenheight()
app_height = int(screenheight) - 48
main.geometry(f'{screenwidth}x{app_height}+0+0')
main.title("Softhub")
main.attributes("-alpha", 1)
main.overrideredirect(True)
main.minimized = False
main.maximized = False
title_bar = Frame(main, relief='groove', bd=0.5, highlightthickness=0)
close_button = Button(title_bar, text=' ✕ ', command=lambda: main.destroy(), padx=2, pady=7, font=("calibri", 13),
bd=0, highlightthickness=0)
expand_button = Button(title_bar, text=' ◻ ', command=lambda:maximize_me(), padx=2, pady=7, bd=0,
font=("calibri", 13), highlightthickness=0)
minimize_button = Button(title_bar, text=' — ', command=lambda:minimize_me(), padx=2, pady=7, bd=0,
font=("calibri", 13), highlightthickness=0)
title_bar_title = Label(title_bar, text="Softhub", bd=0, font=("helvetica", 14),
highlightthickness=0)
searchdark = PhotoImage(file=r"images\searchdark.png")
searchdark = searchdark.subsample(11,11)
searchlight = PhotoImage(file=r"images\searchlight.png")
searchlight = searchlight.subsample(11,11)
# pack the widgets
title_bar.pack(fill=X)
close_button.pack(side=RIGHT, ipadx=7, ipady=1)
expand_button.pack(side=RIGHT, ipadx=7, ipady=1)
minimize_button.pack(side=RIGHT, ipadx=7, ipady=1)
appicon = PhotoImage(file=r"images\softhuḃicon.png")
appicon = appicon.subsample(6, 6)
label = Label(title_bar, image=appicon)
label.pack(side=LEFT)
title_bar_title.pack(side=LEFT, padx=10)
def checkallpack():
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#winget apps check
winpack = str(subprocess.run(["winget", "list", "--source", "winget"], check=True, capture_output=True,startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW))
allpack=winpack
installedapplist=[]
def instwindow():
def set_appwindow(mainWindow): # to display the window icon on the taskbar,
# even when using main.overrideredirect(True)
# Some WindowsOS styles, required for task bar integration
GWL_EXSTYLE = -20
WS_EX_APPWINDOW = 0x00040000
WS_EX_TOOLWINDOW = 0x00000080
# Magic
hwnd = windll.user32.GetParent(mainWindow.winfo_id())
stylew = windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
stylew = stylew & ~WS_EX_TOOLWINDOW
stylew = stylew | WS_EX_APPWINDOW
res = windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, stylew)
mainWindow.wm_withdraw()
mainWindow.after(10, lambda: mainWindow.wm_deiconify())
def minimize_me():
instwin.attributes("-alpha",0) # so you can't see the window when is minimized
instwin.minimized = True
instwin.bind("<FocusIn>",deminimize)
def fake_func(event):
return None
def deminimize(event):
instwin.focus()
instwin.attributes("-alpha",1) # so you can see the window when is not minimized
if instwin.minimized == True:
instwin.minimized = False
instwin.bind("<FocusIn>",fake_func)
def deminimzewhenappinstalled():
instwin.focus()
instwin.attributes("-alpha", 1) # so you can see the window when is not minimized
if instwin.minimized == True:
instwin.minimized = False
def maximize_me():
if instwin.maximized == False: # if the window was not maximized
instwin.normal_size = instwin.geometry()
expand_button.config(text=" 🗗 ")
instwin.geometry(f"{instwin.winfo_screenwidth()}x{instwin.winfo_screenheight()}+0+0")
instwin.maximized = not instwin.maximized
# maximized
else: # if the window was maximized
expand_button.config(text=" ◻ ")
instwin.geometry(instwin.normal_size)
instwin.maximized = not instwin.maximized
# not maximized
global instwin
instwin = Toplevel()
instwin.tk.call('wm', 'iconphoto', instwin._w, ImageTk.PhotoImage(file='images\softhub.ico'))
main.withdraw()
screenwidth = instwin.winfo_screenwidth()
screenheight = instwin.winfo_screenheight()
app_height = int(screenheight) - 48
instwin.geometry(f'{screenwidth}x{app_height}+0+0')
instwin.title("Softhub")
instwin.attributes("-alpha", 1)
instwin.overrideredirect(True)
instwin.minimized = False
instwin.maximized = False
title_bar = Frame(instwin, relief='groove', bd=0.5, highlightthickness=0)
close_button = Button(title_bar, text=' ✕ ',command=lambda:[instwin.destroy(),main.destroy()], padx=2, pady=7, font=("calibri", 13),
bd=0, highlightthickness=0)
expand_button = Button(title_bar, text=' ◻ ', command=lambda:maximize_me(), padx=2, pady=7, bd=0,
font=("calibri", 13), highlightthickness=0)
minimize_button = Button(title_bar, text=' — ', command=lambda:minimize_me(), padx=2, pady=7, bd=0,
font=("calibri", 13), highlightthickness=0)
title_bar_title = Label(title_bar, text="Softhub", bd=0, font=("helvetica", 14),
highlightthickness=0)
explore_button = ttk.Button(title_bar, text="Explore",width=15,command=lambda: [instwinremove(),updwinremove()])
installed_button = ttk.Button(title_bar, text="Installed",width=15,command=lambda:[instwinremove(),updwinremove(),instwindow()])
Update_button = ttk.Button(title_bar, text="Updates",width=15,command=lambda: [instwinremove(),updwinremove(),Updwindow()])
explore_button.place(relx=0.45,rely=0.15)
installed_button.place(relx=0.33,rely=0.15)
Update_button.place(relx=0.57,rely=0.15)
# pack the widgets
title_bar.pack(fill=X)
close_button.pack(side=RIGHT, ipadx=7, ipady=1)
expand_button.pack(side=RIGHT, ipadx=7, ipady=1)
minimize_button.pack(side=RIGHT, ipadx=7, ipady=1)
appicon = PhotoImage(file=r"images\softhuḃicon.png")
appicon = appicon.subsample(6, 6)
label = Label(title_bar, image=appicon)
label.pack(side=LEFT)
title_bar_title.pack(side=LEFT, padx=10)
sidebar2= Frame(instwin, height=28, relief='groove', bd=0.5, highlightthickness=0)
sidebar2.pack(side='top', fill='both')
status = ttk.Label(sidebar2, text="v.0.7.Alpha", font=("Segou UI variable", 10))
status.place(relx=0.92, rely=0.1)
quote = ttk.Label(sidebar2, text="Simplifying software management", font=("Segou UI variable", 10))
quote.place(relx=0.435, rely=0.1)
headinglabel = ttk.Label(instwin,text="Installed Apps", font=("Segou UI variable", 20))
headinglabel.pack(anchor=CENTER, pady=10)
on = PhotoImage(file=r"images\darkicon.png")
on = on.subsample(5, 5)
off = PhotoImage(file=r"images\lighticon.png")
off = off.subsample(5, 5)
def switch():
global is_on
global mode
if is_on == True:
is_on = False
mode = "dark"
with open("theme.json", "w") as file:
data = {"mode": mode}
json.dump(data, file)
sv.set_theme("dark")
theme.config(image=on)
searchbutton.config(image=searchdark)
label.update()
else:
is_on = True
mode = "light"
with open("theme.json", "w") as file:
data = {"mode": mode}
json.dump(data, file)
sv.set_theme("light")
theme.config(image=off)
searchbutton.config(image=searchlight)
label.update()
theme = ttk.Button(title_bar, image=on, padding=0,command=lambda: switch())
theme.place(relx=0.79, rely=0.125)
if mode == "light":
theme.config(image=off)
elif mode == "dark":
theme.config(image=on)
def openlink():
webbrowser.open_new("https://github.com/ACExSWAROOP")
abouticon = PhotoImage(file=r"images\about.png")
abouticon = abouticon.subsample(22, 22)
aboutbutton = ttk.Button(title_bar, image=abouticon, padding=0, command=lambda: openlink())
aboutbutton.place(relx=0.1, rely=0.15)
settingsicon= PhotoImage(file=r"images\settings.png")
settingsicon = settingsicon.subsample(18, 18)
settingsbutton = ttk.Button(title_bar, image=settingsicon, padding=0, command=lambda: settingswindow())
settingsbutton.place(relx=0.84, rely=0.075)
close_button.bind('<Enter>', changex_on_hovering)
close_button.bind('<Leave>', returnx_to_normalstate)
expand_button.bind('<Enter>', change_size_on_hovering)
expand_button.bind('<Leave>', return_size_on_hovering)
minimize_button.bind('<Enter>', changem_size_on_hovering)
minimize_button.bind('<Leave>', returnm_size_on_hovering)
# main frame
window = Frame(instwin, highlightthickness=0)
window.pack(expand=1, fill=BOTH)
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
try:
clr()
intcheckapp("instwin")
result = str(subprocess.run(["winget","list","--source","winget"], capture_output=True, startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW))
start = result.index("Name")
end = result.index("stderr=b'')")
result = result[start:end]
result = result.strip().split("\\r\\n")
for line in result[2:]:
items = line.split()
if len(items)==3:
appname = items[0:1]
app_id = items[1]
elif len(items)==4:
appname = items[0:2]
app_id = items[2]
elif len(items)==5:
appname = items[0:3]
app_id = items[3]
elif len(items)==6:
appname = items[0:4]
app_id = items[4]
elif len(items)==7:
appname = items[0:5]
app_id = items[5]
elif len(items)==8:
appname = items[0:6]
app_id = items[6]
elif len(items)==9:
appname = items[0:7]
app_id = items[7]
elif len(items)==10:
appname = items[0:8]
app_id = items[8]
elif len(items)==11:
appname = items[0:9]
app_id = items[9]
elif len(items)==12:
appname = items[0:10]
app_id = items[10]
elif len(items)==13:
appname = items[0:11]
app_id = items[11]
elif len(items)==14:
appname = items[0:12]
app_id = items[12]
elif len(items)==15:
appname = items[0:13]
app_id = items[13]
elif len(items)==16:
appname = items[0:14]
app_id = items[14]
elif len(items)==17:
appname = items[0:15]
app_id = items[15]
apps.append([appname,app_id])
apps.pop()
except NameError:
pass
except ValueError:
pass
def update_app(app_id):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.run(["winget","update","--id" ,app_id ,"--include-unknown"], check=True, capture_output=True, startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW)
def uninstall_app(app_id):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.run(["winget","uninstall","--id" ,app_id], check=True, capture_output=True, startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW)
canvas = Canvas(window)
canvas.pack(side="left", fill="both", expand=True)
# Create a scrollbar for the canvas
scrollbar = ttk.Scrollbar(window, orient="vertical", command=canvas.yview)
scrollbar.pack(side="right", fill="y")
# Configure the canvas to use the scrollbar
canvas.configure(yscrollcommand=scrollbar.set)
canvas.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))
# Create a frame inside the canvas to hold the app entries
app_frame = Frame(canvas)
canvas.create_window((0, 0), window=app_frame, anchor="nw")
for idx, app in enumerate(apps, start=1):
app_name = app[0]
app_id = app[1]
# Create a frame for each app entry
entry_frame = Frame(app_frame)
entry_frame.pack(anchor="w", padx=10, pady=5)
# Create the serial number label
serial_label = ttk.Label(entry_frame, text=f"{idx}.")
serial_label.pack(side="left", padx=(0, 10))
# Create the app name label
app_label = ttk.Label(entry_frame, text=app_name)
app_label.pack(side="left")
# Create the update button
update_button = ttk.Button(entry_frame, text="Update", command=lambda id=app_id: update_app(id))
update_button.pack(side="left", padx=10)
# Create the uninstall button
uninstall_button = ttk.Button(entry_frame, text="Uninstall", command=lambda id=app_id: uninstall_app(id))
uninstall_button.pack(side="left")
app_frame.bind("<MouseWheel>", lambda event: canvas.yview_scroll(-1*(event.delta//120), "units"))
window.bind("<MouseWheel>", lambda event: canvas.yview_scroll(-1*(event.delta//120), "units"))
instwin.bind("<MouseWheel>", lambda event: canvas.yview_scroll(-1*(event.delta//120), "units"))
# some settings
instwin.bind("<FocusIn>", deminimize) # to view the window by clicking on the window icon on the taskbar
instwin.after(10, lambda: set_appwindow(instwin)) # to see the icon on the task bar
instwin.mainloop()
def Updwindow():
def set_appwindow(mainWindow): # to display the window icon on the taskbar,
# even when using main.overrideredirect(True)
# Some WindowsOS styles, required for task bar integration
GWL_EXSTYLE = -20
WS_EX_APPWINDOW = 0x00040000
WS_EX_TOOLWINDOW = 0x00000080
# Magic
hwnd = windll.user32.GetParent(mainWindow.winfo_id())
stylew = windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
stylew = stylew & ~WS_EX_TOOLWINDOW
stylew = stylew | WS_EX_APPWINDOW
res = windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, stylew)
mainWindow.wm_withdraw()
mainWindow.after(10, lambda: mainWindow.wm_deiconify())
def minimize_me():
updwin.attributes("-alpha",0) # so you can't see the window when is minimized
updwin.minimized = True
updwin.bind("<FocusIn>",deminimize)
def fake_func(event):
return None
def deminimize(event):
updwin.focus()
updwin.attributes("-alpha",1) # so you can see the window when is not minimized
if updwin.minimized == True:
updwin.minimized = False
updwin.bind("<FocusIn>",fake_func)
def deminimzewhenappinstalled():
updwin.focus()
updwin.attributes("-alpha", 1) # so you can see the window when is not minimized
if updwin.minimized == True:
updwin.minimized = False
def maximize_me():
if updwin.maximized == False: # if the window was not maximized
updwin.normal_size = updwin.geometry()
expand_button.config(text=" 🗗 ")
updwin.geometry(f"{updwin.winfo_screenwidth()}x{updwin.winfo_screenheight()}+0+0")
updwin.maximized = not updwin.maximized
# maximized
else: # if the window was maximized
expand_button.config(text=" ◻ ")
updwin.geometry(updwin.normal_size)
updwin.maximized = not updwin.maximized
# not maximized
global updwin
updwin = Toplevel()
updwin.tk.call('wm', 'iconphoto', updwin._w, ImageTk.PhotoImage(file='images\softhub.ico'))
main.withdraw()
screenwidth = updwin.winfo_screenwidth()
screenheight = updwin.winfo_screenheight()
app_height = int(screenheight) - 48
updwin.geometry(f'{screenwidth}x{app_height}+0+0')
updwin.title("Softhub")
updwin.attributes("-alpha", 1)
updwin.overrideredirect(True)
updwin.minimized = False
updwin.maximized = False
title_bar = Frame(updwin, relief='groove', bd=0.5, highlightthickness=0)
close_button = Button(title_bar, text=' ✕ ', command=lambda:[updwin.destroy(),main.destroy()], padx=2, pady=7, font=("calibri", 13),
bd=0, highlightthickness=0)
expand_button = Button(title_bar, text=' ◻ ', command=lambda:maximize_me(), padx=2, pady=7, bd=0,
font=("calibri", 13), highlightthickness=0)
minimize_button = Button(title_bar, text=' — ', command=lambda:minimize_me(), padx=2, pady=7, bd=0,
font=("calibri", 13), highlightthickness=0)
title_bar_title = Label(title_bar, text="Softhub", bd=0, font=("helvetica", 14),
highlightthickness=0)
explore_button = ttk.Button(title_bar, text="Explore",width=15,command=lambda: [instwinremove(),updwinremove()])
installed_button = ttk.Button(title_bar, text="Installed",width=15,command=lambda:[instwinremove(),updwinremove(),instwindow()])
Update_button = ttk.Button(title_bar, text="Updates",width=15,command=lambda: [instwinremove(),updwinremove(),Updwindow()])
close_button.bind('<Enter>', changex_on_hovering)
close_button.bind('<Leave>', returnx_to_normalstate)
expand_button.bind('<Enter>', change_size_on_hovering)
expand_button.bind('<Leave>', return_size_on_hovering)
minimize_button.bind('<Enter>', changem_size_on_hovering)
minimize_button.bind('<Leave>', returnm_size_on_hovering)
explore_button.place(relx=0.45,rely=0.15)
installed_button.place(relx=0.33,rely=0.15)
Update_button.place(relx=0.57,rely=0.15)
# pack the widgets
title_bar.pack(fill=X)
close_button.pack(side=RIGHT, ipadx=7, ipady=1)
expand_button.pack(side=RIGHT, ipadx=7, ipady=1)
minimize_button.pack(side=RIGHT, ipadx=7, ipady=1)
appicon = PhotoImage(file=r"images\softhuḃicon.png")
appicon = appicon.subsample(6, 6)
label = Label(title_bar, image=appicon)
label.pack(side=LEFT)
title_bar_title.pack(side=LEFT, padx=10)
sidebar2= Frame(updwin, height=28, relief='groove', bd=0.5, highlightthickness=0)
sidebar2.pack(side='top', fill='both')
status = ttk.Label(sidebar2, text="v.0.7.Alpha", font=("Segou UI variable", 10))
status.place(relx=0.92, rely=0.1)
quote = ttk.Label(sidebar2, text="Simplifying software management", font=("Segou UI variable", 10))
quote.place(relx=0.435, rely=0.1)
headinglabel = ttk.Label(updwin,text="Update Apps", font=("Segou UI variable", 20))
headinglabel.pack(anchor=CENTER, pady=10)
on = PhotoImage(file=r"images\darkicon.png")
on = on.subsample(5, 5)
off = PhotoImage(file=r"images\lighticon.png")
off = off.subsample(5, 5)
def switch():
global is_on
global mode
if is_on == True:
theme.config(image=on)
searchbutton.config(image=searchdark)
is_on = False
mode = "dark"
with open("theme.json", "w") as file:
data = {"mode": mode}
json.dump(data, file)
sv.set_theme("dark")
label.update()
else:
theme.config(image=off)
searchbutton.config(image=searchlight)
is_on = True
mode = "light"
with open("theme.json", "w") as file:
data = {"mode": mode}
json.dump(data, file)
sv.set_theme("light")
label.update()
theme = ttk.Button(title_bar, image=on, padding=0,command=lambda: switch())
theme.place(relx=0.79, rely=0.125)
if mode == "light":
theme.config(image=off)
elif mode == "dark":
theme.config(image=on)
def openlink():
webbrowser.open_new("https://github.com/ACExSWAROOP")
abouticon = PhotoImage(file=r"images\about.png")
abouticon = abouticon.subsample(22, 22)
aboutbutton = ttk.Button(title_bar, image=abouticon, padding=0, command=lambda: openlink())
aboutbutton.place(relx=0.1, rely=0.15)
settingsicon= PhotoImage(file=r"images\settings.png")
settingsicon = settingsicon.subsample(18, 18)
settingsbutton = ttk.Button(title_bar, image=settingsicon, padding=0, command=lambda: settingswindow())
settingsbutton.place(relx=0.84, rely=0.075)
# main frame
window = Frame(updwin, highlightthickness=0)
window.pack(expand=1, fill=BOTH)
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
try:
clr()
intcheckapp("updwin")
result = str(subprocess.run(["winget","update","--source","winget"], capture_output=True, startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW))
start = result.index("Name")
end = result.index("stderr=b'')")
result = result[start:end]
result = result.strip().split("\\r\\n")
for line in result[2:-1]:
items = line.split()
if len(items)==4:
appname = items[0:1]
app_id = items[1]
elif len(items)==5:
appname = items[0:2]
app_id = items[2]
elif len(items)==6:
appname = items[0:3]
app_id = items[3]
elif len(items)==7:
appname = items[0:4]
app_id = items[4]
elif len(items)==8:
appname = items[0:5]
app_id = items[5]
elif len(items)==9:
appname = items[0:6]
app_id = items[6]
elif len(items)==10:
appname = items[0:7]
app_id = items[7]
elif len(items)==11:
appname = items[0:8]
app_id = items[8]
elif len(items)==12:
appname = items[0:9]
app_id = items[9]
elif len(items)==13:
appname = items[0:10]
app_id = items[10]
elif len(items)==14:
appname = items[0:11]
app_id = items[11]
elif len(items)==15:
appname = items[0:12]
app_id = items[12]
elif len(items)==16:
appname = items[0:13]
app_id = items[13]
elif len(items)==17:
appname = items[0:14]
app_id = items[14]
apps.append([appname,app_id])
apps.pop()
except NameError:
pass
except ValueError:
pass
def update_app(app_id):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.run(["winget","update","--id" ,app_id ,"--include-unknown"], check=True, capture_output=True, startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NO_WINDOW)
canvas = Canvas(window)
canvas.pack(side="left", fill="both", expand=True)
# Create a scrollbar for the canvas
scrollbar = ttk.Scrollbar(window, orient="vertical", command=canvas.yview)
scrollbar.pack(side="right", fill="y")
# Configure the canvas to use the scrollbar
canvas.configure(yscrollcommand=scrollbar.set)
canvas.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))
# Create a frame inside the canvas to hold the app entries
app_frame = Frame(canvas)
canvas.create_window((0, 0), window=app_frame, anchor="nw")
for idx, app in enumerate(apps, start=1):
app_name = app[0]
app_id = app[1]
# Create a frame for each app entry
entry_frame = Frame(app_frame)
entry_frame.pack(anchor="w", padx=10, pady=5)
# Create the serial number label
serial_label = ttk.Label(entry_frame, text=f"{idx}.")
serial_label.pack(side="left", padx=(0, 10))
# Create the app name label
app_label = ttk.Label(entry_frame, text=app_name)
app_label.pack(side="left")
# Create the update button
update_button = ttk.Button(entry_frame, text="Update", command=lambda id=app_id: update_app(id))
update_button.pack(side="left", padx=10)
app_frame.bind("<MouseWheel>", lambda event: canvas.yview_scroll(-1*(event.delta//120), "units"))
window.bind("<MouseWheel>", lambda event: canvas.yview_scroll(-1*(event.delta//120), "units"))
updwin.bind("<MouseWheel>", lambda event: canvas.yview_scroll(-1*(event.delta//120), "units"))
# some settings
updwin.bind("<FocusIn>", deminimize) # to view the window by clicking on the window icon on the taskbar
updwin.after(10, lambda: set_appwindow(updwin)) # to see the icon on the task bar
updwin.mainloop()
def instwinremove():
try:
main.attributes("-alpha", 1)
main.deiconify()
instwin.destroy()
except NameError:
pass
def updwinremove():
try:
main.attributes("-alpha", 1)
main.deiconify()
updwin.destroy()
except NameError:
pass
explore_button = ttk.Button(title_bar, text="Explore",width=15,command=lambda: [instwinremove(),updwinremove()])
installed_button = ttk.Button(title_bar, text="Installed",width=15,command=lambda:[instwinremove(),updwinremove(),instwindow()])
Update_button = ttk.Button(title_bar, text="Updates",width=15,command=lambda: [instwinremove(),updwinremove(),Updwindow()])
explore_button.place(relx=0.45,rely=0.15)
installed_button.place(relx=0.33,rely=0.15)
Update_button.place(relx=0.57,rely=0.15)
# main frame
window = Frame(main, highlightthickness=0)
window.pack(expand=1, fill=BOTH)
def close():
settings.destroy()
def settingswindow():
def savedoptions():
try:
with open("settings.json", "r") as x:
data = json.load(x)
autoupdateval=data["autoupdate"]
if autoupdateval == 1:
autoupd.set(1)
except json.JSONDecodeError:
pass
global settings
settings = Toplevel()
settings.overrideredirect(True)
app_width = 512
app_height = 256
screenwidth = settings.winfo_screenwidth()
screenheight = settings.winfo_screenheight()
x = (screenwidth / 2) - (app_width / 2)
y = (screenheight / 2) - (app_height / 2)
settings.geometry(f'{app_width}x{app_height}+{int(x)}+{int(y)}')
main.bind("<Button-3>", lambda e: close())
settings.bind("<Button-3>", lambda e: close())
main.bind("<Button-1>", lambda e: close())
global autoupd
autoupd = IntVar()
def saveconfig():
checkvalues= {}
checkvalues["autoupdate"] = autoupd.get()
with open("settings.json", "w") as json_file:
json.dump(checkvalues, json_file)
pref =ttk.Label(settings,text="Settings", font=("Segou UI variable", 20))
atupdate = ttk.Checkbutton(settings,text="Enable Auto Update", variable=autoupd)
savebutton= ttk.Button(settings,text="Save",width=15,command=lambda: [saveconfig(),settings.destroy(),main.attributes("-alpha", 1)])
pref.place(relx=0.38,rely=0.15)
atupdate.place(relx=0.335,rely=0.3)
savebutton.place(relx=0.35,rely=0.8)
savedoptions()
settings.mainloop()
def selectcategory(x):
x=listbox.get(ACTIVE)
if x == "3D modeling and animation apps":
my_canvas.yview("moveto", 0)
elif x == '3D printing apps':
my_canvas.yview("moveto",0.00909090909090909)
elif x == '3D rendering apps':
my_canvas.yview("moveto",0.01818181818181818)
elif x == '3D scanning apps':
my_canvas.yview("moveto",0.02727272727272727)
elif x == 'Accounting and financial management apps':
my_canvas.yview("moveto",0.03636363636363636)
elif x == 'Audio recording and editing apps':
my_canvas.yview("moveto",0.045454545454545456)
elif x == 'Augmented reality content creation apps':
my_canvas.yview("moveto",0.05454545454545454)
elif x == 'Backup and recovery apps':
my_canvas.yview("moveto",0.06363636363636363)
elif x == 'Business apps' :
my_canvas.yview("moveto",0.07272727272727272)
elif x == 'CAD software':
my_canvas.yview("moveto",0.08181818181818182)
elif x == 'Cloud storage and syncing apps':
my_canvas.yview("moveto",0.09090909090909091)
elif x == 'Code editors':
my_canvas.yview("moveto",0.1)
elif x == 'Command line utilities':
my_canvas.yview("moveto",0.10909090909090909)
elif x == 'Communication apps':
my_canvas.yview("moveto",0.11818181818181818)
elif x == 'Creativity apps':
my_canvas.yview("moveto",0.12727272727272726)
elif x == 'Customer relationship management apps' :
my_canvas.yview("moveto",0.13636363636363635)
elif x == 'Data backup apps' :
my_canvas.yview("moveto",0.14545454545454545)
elif x == 'Data recovery apps':
my_canvas.yview("moveto",0.15454545454545454)
elif x == 'Database administration apps':
my_canvas.yview("moveto",0.16363636363636364)
elif x == 'Database design and development apps':
my_canvas.yview("moveto",0.17272727272727273)
elif x == 'Database management apps':
my_canvas.yview("moveto",0.18181818181818182)
elif x == 'Database modeling apps' :
my_canvas.yview("moveto",0.19090909090909092)
elif x == 'Database reporting apps':
my_canvas.yview("moveto",0.2)
elif x == 'Debugging tools' :
my_canvas.yview("moveto",0.20909090909090908)
elif x == 'Development apps' :
my_canvas.yview("moveto",0.21818181818181817)
elif x == 'Disk cleanup and management apps':
my_canvas.yview("moveto",0.22727272727272727)
elif x == 'Documents' :