Skip to content

Commit 979ff23

Browse files
authored
Pre1.0
1 parent f9903eb commit 979ff23

File tree

5 files changed

+155
-13
lines changed

5 files changed

+155
-13
lines changed

SYSTEM_LANG_FR.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"TaskManager": "Gestionnaire des Tâches",
1919
"TaskKill": "Fin de Tâche",
2020
"TaskName": "Nom de la tâche",
21-
"MemoryUsage": "Utilisation de mémoire",
21+
"MemoryUsage": "Utilisation de la mémoire",
2222
"ProcessorUsage": "Utilisation du processeur"
2323
}
2424
}

boot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def increment_progress():
134134
except:
135135
ThrowBSOD(window, corrupted_key("WIN_HEIGHT"))
136136

137-
window.geometry(f"{WIN_WIDTH}x{WIN_HEIGHT}")
137+
window.geometry(f"{WIN_WIDTH}x{WIN_HEIGHT}+100+100")
138138

139139
# Window BG for loading
140140
try:

general_data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"last_connected_user": "user",
3-
"version": "Alpha0.18"
3+
"version": "Pre1.0"
44
}

main.py

+150-9
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def compute_password(entry_name: str, window: tk.Tk):
303303
# ------------------ SETUP NAVBAR ------------------
304304
setup_topbar(window, globals()["REGISTRY"])
305305
setup_navbar(window, globals()["REGISTRY"], user)
306+
setup_desktop(window, globals()["REGISTRY"], user)
306307
else:
307308
incorrect_password_label = tk.Label(
308309
window,
@@ -319,7 +320,7 @@ def compute_password(entry_name: str, window: tk.Tk):
319320
def get_userdata(window, user, REGISTRY):
320321
try:
321322
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",
323324
"r",
324325
encoding="utf-8"
325326
)
@@ -417,7 +418,6 @@ def setup_navbar(window, REGISTRY, user):
417418
# If we already did the app OR it is not in the user's taskbar
418419
if app.software_dir in done_apps or app.software_dir not in user_taskbar:
419420
continue
420-
print("Loaded", app.software_dir)
421421

422422
globals()["app_tkimages_" + str(iterations)] = \
423423
ImageTk.PhotoImage(
@@ -453,7 +453,7 @@ def setup_navbar(window, REGISTRY, user):
453453

454454
if app.software_dir in startup_apps:
455455
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)
457457

458458
done_apps.append(app.software_dir)
459459

@@ -614,6 +614,115 @@ def set_battery_string():
614614
height = navbar_size // 4
615615
)
616616

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+
617726
def launched_app(app, min_size, max_size, event):
618727
"""
619728
Attributes a frame to the app, and launches it.
@@ -1065,7 +1174,7 @@ def kill_task(task, row):
10651174
globals()["frame_task_manager_MAIN"],
10661175
text = TRANSLATIONS["ACOS_MENU"]["MemoryUsage"] + " :\n" +\
10671176
str(round(process.memory_info().rss / 1024 ** 2, 2))\
1068-
+ f"MBs ({process.memory_percent()})"
1177+
+ f"MBs"
10691178
)
10701179
column2.grid(row=0, column=2)
10711180

@@ -1333,6 +1442,9 @@ def user_setup():
13331442
json.dump(general_data, general_data_file, indent=4)
13341443
general_data_file.close()
13351444

1445+
# Creation of the desktop
1446+
os.mkdir("ROOT/" + REGISTRY["USERS_FOLDER"] + "/" + username + f"/_desktop")
1447+
13361448
del globals()["password_salt"]
13371449
del globals()["password"]
13381450

@@ -1425,26 +1537,44 @@ def validate_pfp(path=None):
14251537
Validates the profile picture :
14261538
Copies it into the correct folder.
14271539
"""
1428-
global username
1429-
global pfp_path
1430-
global pfp_name
1540+
nonlocal username
1541+
nonlocal pfp_path
1542+
nonlocal pfp_name
14311543
if path not in (None, ""):
14321544
pfp_path = path
14331545
else:
14341546
pfp_path = "assets/ACOS_Logo.png"
14351547

14361548
pfp_name = pfp_path.split("/")[-1]
14371549
try:
1550+
if username == "":
1551+
raise Exception # Going to the except
14381552
os.mkdir("ROOT/" + REGISTRY["USERS_FOLDER"] + "/" + username + "/.userdata/")
14391553
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/")
14411560
try:
14421561
shutil.copyfile(
14431562
pfp_path,
14441563
"ROOT/" + REGISTRY["USERS_FOLDER"] + "/" + username + "/.userdata/" + pfp_name
14451564
)
14461565
except Exception as e:
1447-
ThrowBSOD(window, "Unable to copy profile picture.\nError : " + 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.\nError : " + str(e))
14481578

14491579
# Launches the next user creation part : The password
14501580
blend_tools.blend_colors_in(
@@ -1641,3 +1771,14 @@ def end_text_blend():
16411771

16421772
window.after(3000, start_text_blend, "Let's create a new user.")
16431773
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

registry.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@
3737
"NOTIFICATION_STAYING_TIME": 5000,
3838
"DATETIME_FORMAT": "%d/%m/%Y %H:%M:%S",
3939
"SPACING_BETWEEN_TOPBAR_ELEMENTS": 10,
40-
"TOPBAR_POSITION_ON_TOP": true
40+
"TOPBAR_POSITION_ON_TOP": true,
41+
"DESKTOP_FONT": ["Helvetica", 12]
4142
}

0 commit comments

Comments
 (0)