@@ -303,6 +303,7 @@ def compute_password(entry_name: str, window: tk.Tk):
303
303
# ------------------ SETUP NAVBAR ------------------
304
304
setup_topbar (window , globals ()["REGISTRY" ])
305
305
setup_navbar (window , globals ()["REGISTRY" ], user )
306
+ setup_desktop (window , globals ()["REGISTRY" ], user )
306
307
else :
307
308
incorrect_password_label = tk .Label (
308
309
window ,
@@ -319,7 +320,7 @@ def compute_password(entry_name: str, window: tk.Tk):
319
320
def get_userdata (window , user , REGISTRY ):
320
321
try :
321
322
userdata_file = open (
322
- f"ROOT/{ REGISTRY ['USERS_FOLDER' ]} /{ user } /{ REGISTRY ['USERDATA_NAME' ]} .json" ,
323
+ f"ROOT/{ REGISTRY ['USERS_FOLDER' ]} /{ globals ()[ ' user' ] } /{ REGISTRY ['USERDATA_NAME' ]} .json" ,
323
324
"r" ,
324
325
encoding = "utf-8"
325
326
)
@@ -417,7 +418,6 @@ def setup_navbar(window, REGISTRY, user):
417
418
# If we already did the app OR it is not in the user's taskbar
418
419
if app .software_dir in done_apps or app .software_dir not in user_taskbar :
419
420
continue
420
- print ("Loaded" , app .software_dir )
421
421
422
422
globals ()["app_tkimages_" + str (iterations )] = \
423
423
ImageTk .PhotoImage (
@@ -453,7 +453,7 @@ def setup_navbar(window, REGISTRY, user):
453
453
454
454
if app .software_dir in startup_apps :
455
455
globals ()["navbar_size" ] = navbar_size
456
- launched_app ( app , app .min_size , app .max_size , None )
456
+ window . after ( 1000 , launched_app , app , app .min_size , app .max_size , None )
457
457
458
458
done_apps .append (app .software_dir )
459
459
@@ -614,6 +614,115 @@ def set_battery_string():
614
614
height = navbar_size // 4
615
615
)
616
616
617
+ def setup_desktop (window , REGISTRY , user , lift_others :bool = False ):
618
+ """
619
+ Setups the user desktop.
620
+ """
621
+ desktop_files = os .listdir (f"ROOT/{ REGISTRY ['USERS_FOLDER' ]} /{ user } /_desktop/" )
622
+ globals ()["desktop" ] = tk .Frame (window , bg = REGISTRY ["MAIN_BG_COLOR" ][REGISTRY ["CURRENT_THEME" ]])
623
+
624
+ iterations = 0
625
+
626
+ def open_app (app , path , event ):
627
+ launched_app (app , app .min_size , app .max_size , event )
628
+ app .on_file_open (path )
629
+
630
+ # Splitting the files
631
+ for file in desktop_files :
632
+ # Getting file info
633
+ extension_raw = file .split ("." )[1 ]
634
+ if extension_raw == "png" :
635
+ extension_raw = "paintapp"
636
+ displayed_extension = extension_raw .upper ()
637
+ filename = file .split ("." )[0 ]
638
+
639
+ for i in dir (all_softwares ):
640
+ if i .startswith ("__" ): # If it is built-in, we just ignore it
641
+ continue
642
+ # We get the attributes of the folder module
643
+ item = getattr (all_softwares , i )
644
+ # We get the real code file
645
+ try :
646
+ app = getattr (item , i )
647
+
648
+ os .chdir ("ROOT/" + REGISTRY ["SOFTWARES_FOLDER" ] + "/"
649
+ + extension_raw + "/" )
650
+ if app .software_dir == extension_raw :
651
+ globals ()["desktop_" + extension_raw + "_icon_" + str (iterations )] = ImageTk .PhotoImage (
652
+ Image .open (app .app_icon ).resize ((REGISTRY ["NAVBAR_SIZE" ], REGISTRY ["NAVBAR_SIZE" ]))
653
+ )
654
+ os .chdir ("../../../" )
655
+ break
656
+ os .chdir ("../../../" )
657
+ except AttributeError :
658
+ continue
659
+
660
+ # Try to import the opening program
661
+ try :
662
+ importlib .import_module ("ROOT." + REGISTRY ["SOFTWARES_FOLDER" ] + "."
663
+ + extension_raw + "." + extension_raw )
664
+ except ModuleNotFoundError :
665
+ extension_raw = "settings"
666
+ importlib .import_module ("ROOT." + REGISTRY ["SOFTWARES_FOLDER" ] + "."
667
+ + extension_raw + "." + extension_raw )
668
+
669
+ # Displaying the file on the desktop, through a grid
670
+ try :
671
+ globals ()[f"desktop_{ filename } _icon" ] = tk .Label (
672
+ globals ()["desktop" ],
673
+ image = globals ()["desktop_" + extension_raw + "_icon_" + str (iterations )],
674
+ bg = REGISTRY ["MAIN_BG_COLOR" ][REGISTRY ["CURRENT_THEME" ]]
675
+ )
676
+ except KeyError :
677
+ globals ()[f"desktop_{ filename } _icon_" + str (iterations )] = tk .Label (
678
+ globals ()["desktop" ],
679
+ image = globals ()["ACOS_Menu_icon_" + str (iterations )],
680
+ bg = REGISTRY ["MAIN_BG_COLOR" ][REGISTRY ["CURRENT_THEME" ]]
681
+ )
682
+ if "DESKTOP_FONT" not in REGISTRY :
683
+ ThrowBSOD (window , corrupted_key ("DESKTOP_FONT" ))
684
+ globals ()[f"desktop_{ filename } _label" ] = tk .Label (
685
+ globals ()["desktop" ],
686
+ text = filename ,
687
+ bg = REGISTRY ["MAIN_BG_COLOR" ][REGISTRY ["CURRENT_THEME" ]],
688
+ fg = REGISTRY ["MAIN_FG_COLOR" ][REGISTRY ["CURRENT_THEME" ]],
689
+ font = tuple (REGISTRY ["DESKTOP_FONT" ])
690
+ )
691
+
692
+ # Binding the click to the app opening
693
+ path = "ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" + user + "/"
694
+ globals ()[f"desktop_{ filename } _label" ].bind ("<Button-1>" , partial (open_app , app ,
695
+ remove_suffix (path , path .endswith ("/" )) + "/_desktop/" + file ))
696
+ globals ()[f"desktop_{ filename } _icon" ].bind ("<Button-1>" , partial (open_app , app ,
697
+ remove_suffix (path , path .endswith ("/" )) + "/_desktop/" + file ))
698
+
699
+ globals ()[f"desktop_{ filename } _icon" ].grid (
700
+ row = iterations - (iterations // 4 * 4 ),
701
+ column = iterations // 4
702
+ )
703
+ globals ()[f"desktop_{ filename } _label" ].grid (
704
+ row = iterations - (iterations // 4 * 4 ) + 1 ,
705
+ column = iterations // 4
706
+ )
707
+
708
+ iterations += 2
709
+
710
+ globals ()["desktop" ].place (
711
+ x = REGISTRY ["NAVBAR_SIZE" ],
712
+ y = REGISTRY ["NAVBAR_SIZE" ] // 4 ,
713
+ width = window .winfo_width () - REGISTRY ["NAVBAR_SIZE" ],
714
+ height = window .winfo_height () - REGISTRY ["NAVBAR_SIZE" ] // 4
715
+ )
716
+
717
+ # Lifting the other apps if the desktop has been reset
718
+ if lift_others is True :
719
+ for variable in globals ():
720
+ if variable .startswith ("frame_" ):
721
+ try :
722
+ globals ()[variable ].lift ()
723
+ except Exception :
724
+ pass
725
+
617
726
def launched_app (app , min_size , max_size , event ):
618
727
"""
619
728
Attributes a frame to the app, and launches it.
@@ -1065,7 +1174,7 @@ def kill_task(task, row):
1065
1174
globals ()["frame_task_manager_MAIN" ],
1066
1175
text = TRANSLATIONS ["ACOS_MENU" ]["MemoryUsage" ] + " :\n " + \
1067
1176
str (round (process .memory_info ().rss / 1024 ** 2 , 2 ))\
1068
- + f"MBs ( { process . memory_percent () } ) "
1177
+ + f"MBs"
1069
1178
)
1070
1179
column2 .grid (row = 0 , column = 2 )
1071
1180
@@ -1333,6 +1442,9 @@ def user_setup():
1333
1442
json .dump (general_data , general_data_file , indent = 4 )
1334
1443
general_data_file .close ()
1335
1444
1445
+ # Creation of the desktop
1446
+ os .mkdir ("ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" + username + f"/_desktop" )
1447
+
1336
1448
del globals ()["password_salt" ]
1337
1449
del globals ()["password" ]
1338
1450
@@ -1425,26 +1537,44 @@ def validate_pfp(path=None):
1425
1537
Validates the profile picture :
1426
1538
Copies it into the correct folder.
1427
1539
"""
1428
- global username
1429
- global pfp_path
1430
- global pfp_name
1540
+ nonlocal username
1541
+ nonlocal pfp_path
1542
+ nonlocal pfp_name
1431
1543
if path not in (None , "" ):
1432
1544
pfp_path = path
1433
1545
else :
1434
1546
pfp_path = "assets/ACOS_Logo.png"
1435
1547
1436
1548
pfp_name = pfp_path .split ("/" )[- 1 ]
1437
1549
try :
1550
+ if username == "" :
1551
+ raise Exception # Going to the except
1438
1552
os .mkdir ("ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" + username + "/.userdata/" )
1439
1553
except :
1440
- pass
1554
+ folders_list = os .listdir ("ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" )
1555
+ try :
1556
+ folders_list .remove (".userdata" )
1557
+ except Exception :
1558
+ pass
1559
+ os .mkdir ("ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" + folders_list [0 ] + "/.userdata/" )
1441
1560
try :
1442
1561
shutil .copyfile (
1443
1562
pfp_path ,
1444
1563
"ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" + username + "/.userdata/" + pfp_name
1445
1564
)
1446
1565
except Exception as e :
1447
- ThrowBSOD (window , "Unable to copy profile picture.\n Error : " + str (e ))
1566
+ try :
1567
+ folders_list = os .listdir ("ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" )
1568
+ try :
1569
+ folders_list .remove (".userdata" )
1570
+ except Exception :
1571
+ pass
1572
+ shutil .copyfile (
1573
+ pfp_path ,
1574
+ "ROOT/" + REGISTRY ["USERS_FOLDER" ] + "/" + folders_list [0 ] + "/.userdata/" + pfp_name
1575
+ )
1576
+ except Exception :
1577
+ ThrowBSOD (window , "Unable to copy profile picture.\n Error : " + str (e ))
1448
1578
1449
1579
# Launches the next user creation part : The password
1450
1580
blend_tools .blend_colors_in (
@@ -1641,3 +1771,14 @@ def end_text_blend():
1641
1771
1642
1772
window .after (3000 , start_text_blend , "Let's create a new user." )
1643
1773
window .after (11000 , start_text_blend , "Select a new username." , display_username_entry )
1774
+
1775
+ def remove_suffix (variable : str , condition : bool = True , chars_amount : int = 1 ):
1776
+ """
1777
+ Removes the suffix of a string.
1778
+ Parameter 'variable' (str) : The text where the suffix has to be removed.
1779
+ Parameter 'chars_amount' (int) : Default : 1. Number of chars to remove.
1780
+ Parameter 'condition' (bool) : Default : True. Will only remove if the condition is True.
1781
+ """
1782
+ if condition is True : # If the condition is respected
1783
+ variable = variable [:- chars_amount ] # Suffix gets removed
1784
+ return variable
0 commit comments