Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import time
- import tkinter as tk
- from tkinter import messagebox as mb
- import keyboard
- import ast
- from threading import Thread
- import base64
- DARK_SYSTEM_APPS = open("T:/TechOS/Virtual/Settings/DARK_SYSTEM_APPS.set", "r").read()
- ACCENT_COLOR = open("T:/TechOS/Virtual/Settings/ACCENT_COLOR.set", "r").read()
- def color_variant(hex_color, brightness_offset=1):
- """ takes a color like #87c95f and produces a lighter or darker variant """
- if len(hex_color) != 7:
- raise Exception("Passed %s into color_variant(), needs to be in #87c95f format." % hex_color)
- rgb_hex = [hex_color[x:x+2] for x in [1, 3, 5]]
- new_rgb_int = [int(hex_value, 16) + brightness_offset for hex_value in rgb_hex]
- new_rgb_int = [min([255, max([0, i])]) for i in new_rgb_int] # make sure new values are between 0 and 255
- # hex() produces "0x88", we want just "88"
- return "#" + "".join(["{:02x}".format(i) for i in new_rgb_int])
- BLACK_ACCENT_COLOR = color_variant(ACCENT_COLOR, -200)
- DIM_ACCENT_COLOR = color_variant(ACCENT_COLOR, -20)
- DARK_ACCENT_COLOR = color_variant(ACCENT_COLOR, -10)
- LIGHT_ACCENT_COLOR = color_variant(ACCENT_COLOR, 10)
- BRIGHT_ACCENT_COLOR = color_variant(ACCENT_COLOR, 20)
- WHITE_ACCENT_COLOR = color_variant(ACCENT_COLOR, 200)
- global_bg_color = "white"
- global_fg_color = "black"
- global_ac_bg_color = "lightgray"
- global_sp_bg_color = WHITE_ACCENT_COLOR
- if DARK_SYSTEM_APPS == "True":
- global_bg_color = "gray12"
- global_fg_color = "gray90"
- global_ac_bg_color = "gray20"
- global_sp_bg_color = BLACK_ACCENT_COLOR
- _root = frame3
- frame3.config(bg=global_bg_color)
- def pin(name):
- with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
- pinnedprogramnames = f.read().splitlines(False)
- if not name in pinnedprogramnames:
- pinnedprogramnames.append(name)
- newnames = "\n".join(pinnedprogramnames)
- with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
- f.write(newnames)
- else:
- unpin(name)
- refreshpm()
- def unpin(name):
- with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
- pinnedprogramnames = f.read().splitlines(False)
- pinnedprogramnames.remove(name)
- newnames = "\n".join(pinnedprogramnames)
- with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
- f.write(newnames)
- refreshpm()
- def unpin_soft(name):
- with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
- pinnedprogramnames = f.read().splitlines(False)
- pinnedprogramnames.remove(name)
- newnames = "\n".join(pinnedprogramnames)
- with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
- f.write(newnames)
- infofolder = os.listdir("T:/ProgramData/Info")
- infofiles = [file for file in infofolder if file.endswith('.info') and not file.endswith('ProgramList.info')]
- programnames = []
- for file in infofiles:
- programnames.append(os.path.basename(file)[:-5])
- with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
- pinnedprogramnames = f.read().splitlines(False)
- currentletter = "#"
- bottombf = tk.Frame(_root, bg=global_bg_color, bd=0)
- bottombf.pack(anchor='sw', side='left', fill='y')
- content = tk.Frame(_root, bg=global_bg_color, bd=0)
- content.pack_propagate(0)
- content.pack(anchor='ne', side='left', expand=True, fill='both')
- canvas = tk.Canvas(content, bg=global_bg_color, bd=0, highlightthickness=0)
- scrollbar = tk.Scrollbar(_root, orient="vertical", command=canvas.yview, troughcolor=global_bg_color, width=12, bd=0)
- buttonsframe = tk.Frame(canvas, bd=0, bg=global_bg_color, highlightcolor='white', highlightthickness=0, pady=10)
- searchframe = tk.Frame(_root, bd=0, bg=global_bg_color, highlightthickness=0, width=50)
- searchframe.pack(anchor='ne', side='left', expand=True, fill='both')
- searchframe.pack_propagate(0)
- buttonsframe.bind(
- "<Configure>",
- lambda e: canvas.configure(
- scrollregion=canvas.bbox("all")
- )
- )
- canvas.create_window((0, 0), window=buttonsframe, anchor="nw")
- canvas.configure(yscrollcommand=scrollbar.set)
- def _on_mousewheel(event):
- ysi = 1
- for i in range(3):
- canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
- ysi += 1
- canvas.config(yscrollincrement=ysi)
- root.update()
- time.sleep(0.01)
- for i in range(4):
- canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
- root.update()
- time.sleep(0.01)
- for i in range(3):
- canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
- ysi -= 1
- canvas.config(yscrollincrement=ysi)
- root.update()
- time.sleep(0.01)
- canvas.config(yscrollincrement=1)
- canvas.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- if not len(pinnedprogramnames) == 0:
- tk.Label(buttonsframe, text="\nPinned", bg=global_bg_color, fg=global_fg_color, font=(None, 11, "bold")).pack(anchor='nw', padx=5, pady=5)
- for name in pinnedprogramnames:
- if os.path.exists(f"T:/ProgramData/Info/{name}.info"):
- if len(name) > 30:
- shortname = name[:28] + "..."
- else:
- shortname = name
- tempbutton = tk.Button(buttonsframe, text=shortname, command=lambda name=name: startprogram(name), bg=global_bg_color, activebackground=global_ac_bg_color, bd=0, fg=global_fg_color, activeforeground=global_fg_color)
- try:
- with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
- infolist = ast.literal_eval(f.read())
- tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
- tempbutton.config(image=tempbutton.image, compound="left", text=f" {tempbutton['text']}")
- except SyntaxError or NameError:
- pass
- tempbutton.pack(anchor='nw', padx=5)
- tempbutton.bind("<Button-3>", lambda e, name=name: unpin(name))
- else:
- unpin_soft(name)
- if not programnames[0][0].isalpha():
- tk.Label(buttonsframe, text="\n" + currentletter, bg=global_bg_color, fg=global_fg_color, font=(None, 11, "bold")).pack(anchor='nw', padx=5, pady=5)
- else:
- pass
- for name in programnames:
- if len(name) > 30:
- shortname = name[:28] + "..."
- else:
- shortname = name
- if name[0].isalpha() and not name[0].upper() == currentletter:
- currentletter = name[0].upper()
- tk.Label(buttonsframe, text="\n" + currentletter, bg=global_bg_color, fg=global_fg_color, font=(None, 11, "bold")).pack(anchor='nw', padx=5, pady=5)
- tempbutton = tk.Button(buttonsframe, text=shortname, command=lambda name=name: startprogram(name), bg=global_bg_color, activebackground=global_ac_bg_color, bd=0, fg=global_fg_color, activeforeground=global_fg_color)
- try:
- with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
- infolist = ast.literal_eval(f.read())
- tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
- tempbutton.config(image=tempbutton.image, compound="left", text=f" {tempbutton['text']}")
- except SyntaxError or NameError:
- pass
- tempbutton.pack(anchor='nw', padx=5)
- tempbutton.bind("<Button-3>", lambda e, name=name: pin(name))
- for child in canvas.winfo_children():
- child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- for child in buttonsframe.winfo_children():
- child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- scrollbar.update()
- canvas.pack(side='left', expand=True, fill='both')
- scrollbar.pack(side="right", fill="y", anchor='e')
- class EntryWithPlaceholder(tk.Entry):
- def __init__(self, master=None, placeholder="PLACEHOLDER", color='grey', **kwargs):
- super().__init__(master)
- self.config(kwargs)
- self.placeholder = placeholder
- self.placeholder_color = color
- self.default_fg_color = self['fg']
- self.bind("<FocusIn>", self.foc_in)
- self.bind("<FocusOut>", self.foc_out)
- self.put_placeholder()
- def put_placeholder(self):
- self.insert(0, self.placeholder)
- self['fg'] = self.placeholder_color
- def foc_in(self, *args):
- if self['fg'] == self.placeholder_color:
- self.delete('0', 'end')
- self['fg'] = self.default_fg_color
- def foc_out(self, *args):
- if not self.get():
- self.put_placeholder()
- def search(text):
- shortnames = {"cmd": "Commands", "mail": "TechMail", "email": "TechMail", "gmail": "TechMail", "documents": "Files", "pictures": "Files", "images": "Files", "buus": "Commands", "audio": "Music Player", "sound": "Music Player", "art": "Pixedit", "draw": "Pixedit", "drawing": "Pixedit", "pen": "Pixedit", "brush": "Pixedit", "task manager": "Processes", "resources": "Processes", "tasks": "Processes", "utilization": "Processes", "notepad": "TechNotes", "techedit": "TechNotes", "word": "TechNotes", "wordpad": "TechNotes", "text": "TechNotes", "text editor": "TechNotes", "apps": "TechStore", "app store": "TechStore"}
- exactmatches = []
- replacematches = []
- startmatches = []
- betweenmatches = []
- if text.lower() in shortnames:
- replacematches.append(shortnames[text.lower()])
- for name in programnames:
- if text.lower() == name.lower():
- exactmatches.append(name)
- elif name.lower().startswith(text.lower()):
- startmatches.append(name)
- elif text.lower() in name.lower():
- betweenmatches.append(name)
- else:
- pass
- def checkforprograms(name, path):
- nonlocal exactmatches
- nonlocal startmatches
- nonlocal betweenmatches
- for item in os.listdir(path):
- if os.path.isdir(os.path.join(path, item)) and not item == "$RECYCLE.BIN":
- try:
- checkforprograms(name, os.path.join(path, item))
- except PermissionError:
- pass
- else:
- if item.endswith(".teb") and item.lower()[:-4] == name.lower():
- exactmatches.append(os.path.join(path, item))
- elif item.lower().startswith(name.lower()) and item.endswith(".teb"):
- startmatches.append(os.path.join(path, item))
- elif name.lower() in item.lower() and item.endswith(".teb"):
- betweenmatches.append(os.path.join(path, item))
- else:
- pass
- else:
- pass
- checkforprograms(text, "T:\\")
- matches = exactmatches + replacematches + startmatches + betweenmatches
- return matches
- searchbox = EntryWithPlaceholder(searchframe, placeholder="Search apps...", bd=0, highlightcolor=ACCENT_COLOR, highlightthickness=2, highlightbackground="lightgray")
- searchbox.pack(fill='x', padx=10, pady=10)
- resultsbox = tk.Frame(searchframe, bd=0, bg=global_bg_color, padx=10)
- resultsbox.pack(expand=True, fill='both')
- searchbox.bind("<Return>", lambda e: resultsbox.winfo_children()[0].invoke())
- def focus_search(e):
- searchbox.delete(0, 'end')
- searchbox.focus()
- searchbox.update()
- searchbox.insert(0, e.char)
- searchresults()
- def start_focusable(e):
- searchframe.unbind("<Key>")
- searchframe.bind("<KeyRelease>", focus_search)
- searchframe.bind("<Key>", start_focusable)
- searchframe.focus()
- searchframe.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- resultsbox.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- def searchresults():
- global base64
- if not searchbox.get() == "":
- list = search(searchbox.get())
- for child in resultsbox.winfo_children():
- child.destroy()
- if len(list) > 0:
- if len(list) > 20:
- tk.Label(resultsbox, text='To show all results, try making your search term more specific', bg=global_bg_color, fg=global_fg_color, wraplength=200).pack()
- for name in list[:20]:
- if len(name) > 30:
- shortname = name[:28] + "..."
- else:
- shortname = name
- _tempbutton = tk.Button(resultsbox, text=shortname, command=lambda name=name: startprogram(name),
- bg=global_bg_color, activebackground=global_ac_bg_color, bd=0, fg=global_fg_color,
- activeforeground=global_fg_color)
- try:
- try:
- with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
- infolist = ast.literal_eval(f.read())
- _tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
- _tempbutton.config(image=_tempbutton.image, compound="left", text=f" {_tempbutton['text']}")
- except SyntaxError or NameError:
- pass
- except OSError:
- try:
- with open(name, "r") as f:
- program = f.read()
- infosection = program.split("TEBinicco(\u00a7IN)")[1].split("(\u00a7IC)")[0]
- info = ast.literal_eval(base64.decodebytes(infosection.encode("ascii")).decode('ascii'))
- icon = program.split("(\u00a7IC)")[1].split("(\u00a7CO)")[0]
- if len(info['TITLE']) > 30:
- shortname = info['TITLE'][:28] + "..."
- else:
- shortname = info['TITLE']
- _tempbutton.image = tk.PhotoImage(data=icon)
- _tempbutton.config(image=_tempbutton.image, compound="left", text=f" {shortname}", command=lambda name=os.path.basename(name): startprogram(name))
- except:
- pass
- _tempbutton.pack(anchor='nw')
- else:
- for name in list:
- if len(name) > 30:
- shortname = name[:28] + "..."
- else:
- shortname = name
- _tempbutton = tk.Button(resultsbox, text=shortname, command=lambda name=name: startprogram(name),
- bg=global_bg_color, activebackground=global_ac_bg_color, bd=0, fg=global_fg_color,
- activeforeground=global_fg_color)
- try:
- try:
- with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
- infolist = ast.literal_eval(f.read())
- _tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
- _tempbutton.config(image=_tempbutton.image, compound="left", text=f" {_tempbutton['text']}")
- except SyntaxError or NameError:
- pass
- except OSError:
- try:
- with open(name, "r") as f:
- program = f.read()
- infosection = program.split("TEBinicco(\u00a7IN)")[1].split("(\u00a7IC)")[0]
- info = ast.literal_eval(base64.decodebytes(infosection.encode("ascii")).decode('ascii'))
- icon = program.split("(\u00a7IC)")[1].split("(\u00a7CO)")[0]
- if len(info['TITLE']) > 30:
- shortname = info['TITLE'][:28] + "..."
- else:
- shortname = info['TITLE']
- _tempbutton.image = tk.PhotoImage(data=icon)
- _tempbutton.config(image=_tempbutton.image, compound="left", text=f" {shortname}", command=lambda name=os.path.basename(name): startprogram(name))
- except:
- pass
- _tempbutton.pack(anchor='nw')
- else:
- tk.Label(resultsbox, text='No results found', bg=global_bg_color, fg=global_fg_color).pack()
- else:
- for child in resultsbox.winfo_children():
- child.destroy()
- searchbox.bind('<KeyRelease>', lambda e: searchresults())
- def restarttechos():
- keyboard.remove_all_hotkeys()
- root.destroy()
- exec(compile(open("T:/TechOS/Virtual/TechOS.py", "rb").read(), "T:/TechOS/Virtual/TechOS.py", 'exec'), {})
- sys.exit()
- def updatetechos():
- global mb
- if mb.askyesno("Update TechOS?","This process might take a while!") == True:
- root.destroy()
- exec(compile(open("T:/TechOS/Virtual/Update.py", "rb").read(), "T:/TechOS/Virtual/Update.py", 'exec'), {})
- sys.exit()
- else:
- pass
- def exit():
- exitsure = mb.askyesno("Exit TechOS Virtual", "Are you sure you want to exit TechOS?")
- if exitsure:
- root.destroy()
- sys.exit()
- else:
- pass
- exitbutton = tk.Button(bottombf, text=" Exit", command=exit, bg=global_bg_color, bd=0, fg=global_fg_color, activeforeground=ACCENT_COLOR, activebackground=global_sp_bg_color)
- exitbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
- restartbutton = tk.Button(bottombf, text=" Restart", command=restarttechos, bg=global_bg_color, bd=0, fg=global_fg_color, activeforeground=ACCENT_COLOR, activebackground=global_sp_bg_color)
- restartbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
- if updateavailable == True:
- updatebutton = tk.Button(bottombf, text=" Update", command=updatetechos, bg=global_bg_color, bd=0, fg=global_fg_color, activeforeground=ACCENT_COLOR, activebackground=global_sp_bg_color)
- updatebutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
- else:
- pass
- settingsbutton = tk.Button(bottombf, text=" Settings", command=lambda: startprogram("Settings"), bg=global_bg_color, bd=0, fg=global_fg_color, activeforeground=ACCENT_COLOR, activebackground=global_sp_bg_color)
- settingsbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
- descshown = False
- def showdesc():
- exitbutton.config(compound="left")
- restartbutton.config(compound="left")
- settingsbutton.config(compound="left")
- menubutton.config(compound="left")
- try:
- updatebutton.config(compound="left")
- except:
- pass
- def hidedesc():
- exitbutton.config(compound="none")
- restartbutton.config(compound="none")
- settingsbutton.config(compound="none")
- menubutton.config(compound="none")
- try:
- updatebutton.config(compound="none")
- except:
- pass
- def toggledesc():
- global descshown
- if descshown == True:
- hidedesc()
- descshown = False
- else:
- showdesc()
- descshown = True
- menubutton = tk.Button(bottombf, text=" Programs", command=toggledesc, bg=global_bg_color, bd=0, fg=global_fg_color, activeforeground=ACCENT_COLOR, activebackground=global_sp_bg_color)
- menubutton.pack(side='top', anchor='nw', padx=5, pady=5)
- if DARK_SYSTEM_APPS == "True":
- exitbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/ExitWhite.png")
- exitbutton.config(image=exitbutton.image)
- restartbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/RestartWhite.png")
- restartbutton.config(image=restartbutton.image)
- try:
- updatebutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/UpdateWhite.png")
- updatebutton.config(image=updatebutton.image)
- except:
- pass
- settingsbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/SettingsWhite.png")
- settingsbutton.config(image=settingsbutton.image)
- menubutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/MenuWhite.png")
- menubutton.config(image=menubutton.image)
- else:
- exitbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/ExitBlack.png")
- exitbutton.config(image=exitbutton.image)
- restartbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/RestartBlack.png")
- restartbutton.config(image=restartbutton.image)
- try:
- updatebutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/UpdateBlack.png")
- updatebutton.config(image=updatebutton.image)
- except:
- pass
- settingsbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/SettingsBlack.png")
- settingsbutton.config(image=settingsbutton.image)
- menubutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/MenuBlack.png")
- menubutton.config(image=menubutton.image)
- def _system_memorysaver():
- from threading import Thread
- def _system_checkexistence():
- import time
- import sys
- if frame3.winfo_exists():
- pass
- else:
- sys.exit()
- time.sleep(1)
- _system_checkexistence()
- Thread(target=_system_checkexistence, daemon=True).start()
- _system_memorysaver()
Add Comment
Please, Sign In to add comment