Advertisement
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
- from threading import Thread
- 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()
- 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 = "#"
- content = tk.Frame(_root, bg=global_bg_color, bd=0)
- content.pack_propagate(0)
- content.pack(anchor='ne', side='right', expand=True, fill='both')
- canvas = tk.Canvas(content, bg=global_bg_color, bd=0, highlightthickness=0)
- scrollbar = tk.Scrollbar(content, 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)
- 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())
- bottombf = tk.Frame(_root, bg=global_bg_color, bd=0)
- bottombf.pack(anchor='sw', side='right', fill='y')
- 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:
- tempbutton = tk.Button(buttonsframe, text=name, 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)
- tempbutton.pack(anchor='nw', padx=5)
- tempbutton.bind("<Button-3>", lambda e, name=name: unpin(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 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=name, 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)
- 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.place(x=0, y=0, relwidth=1.0, relheight=1.0)
- scrollbar.pack(side="right", fill="y")
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement