Advertisement
Techpad

ProgramList 10

Apr 3rd, 2021
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.22 KB | None | 0 0
  1. import os
  2. import sys
  3. import time
  4. import tkinter as tk
  5. from tkinter import messagebox as mb
  6. import keyboard
  7. from threading import Thread
  8.  
  9. DARK_SYSTEM_APPS = open("T:/TechOS/Virtual/Settings/DARK_SYSTEM_APPS.set", "r").read()
  10. ACCENT_COLOR = open("T:/TechOS/Virtual/Settings/ACCENT_COLOR.set", "r").read()
  11.  
  12. def color_variant(hex_color, brightness_offset=1):
  13. """ takes a color like #87c95f and produces a lighter or darker variant """
  14. if len(hex_color) != 7:
  15. raise Exception("Passed %s into color_variant(), needs to be in #87c95f format." % hex_color)
  16. rgb_hex = [hex_color[x:x+2] for x in [1, 3, 5]]
  17. new_rgb_int = [int(hex_value, 16) + brightness_offset for hex_value in rgb_hex]
  18. new_rgb_int = [min([255, max([0, i])]) for i in new_rgb_int] # make sure new values are between 0 and 255
  19. # hex() produces "0x88", we want just "88"
  20. return "#" + "".join(["{:02x}".format(i) for i in new_rgb_int])
  21.  
  22. BLACK_ACCENT_COLOR = color_variant(ACCENT_COLOR, -200)
  23. DIM_ACCENT_COLOR = color_variant(ACCENT_COLOR, -20)
  24. DARK_ACCENT_COLOR = color_variant(ACCENT_COLOR, -10)
  25. LIGHT_ACCENT_COLOR = color_variant(ACCENT_COLOR, 10)
  26. BRIGHT_ACCENT_COLOR = color_variant(ACCENT_COLOR, 20)
  27. WHITE_ACCENT_COLOR = color_variant(ACCENT_COLOR, 200)
  28.  
  29. global_bg_color = "white"
  30. global_fg_color = "black"
  31. global_ac_bg_color = "lightgray"
  32. global_sp_bg_color = WHITE_ACCENT_COLOR
  33.  
  34. if DARK_SYSTEM_APPS == "True":
  35. global_bg_color = "gray12"
  36. global_fg_color = "gray90"
  37. global_ac_bg_color = "gray20"
  38. global_sp_bg_color = BLACK_ACCENT_COLOR
  39.  
  40. _root = frame3
  41.  
  42. frame3.config(bg=global_bg_color)
  43.  
  44. def pin(name):
  45. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
  46. pinnedprogramnames = f.read().splitlines(False)
  47. if not name in pinnedprogramnames:
  48. pinnedprogramnames.append(name)
  49. newnames = "\n".join(pinnedprogramnames)
  50. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
  51. f.write(newnames)
  52. else:
  53. unpin(name)
  54. refreshpm()
  55.  
  56. def unpin(name):
  57. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
  58. pinnedprogramnames = f.read().splitlines(False)
  59. pinnedprogramnames.remove(name)
  60. newnames = "\n".join(pinnedprogramnames)
  61. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
  62. f.write(newnames)
  63. refreshpm()
  64.  
  65. infofolder = os.listdir("T:/ProgramData/Info")
  66. infofiles = [file for file in infofolder if file.endswith('.info') and not file.endswith('ProgramList.info')]
  67. programnames = []
  68. for file in infofiles:
  69. programnames.append(os.path.basename(file)[:-5])
  70. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
  71. pinnedprogramnames = f.read().splitlines(False)
  72. currentletter = "#"
  73.  
  74. content = tk.Frame(_root, bg=global_bg_color, bd=0)
  75. content.pack_propagate(0)
  76. content.pack(anchor='ne', side='right', expand=True, fill='both')
  77. canvas = tk.Canvas(content, bg=global_bg_color, bd=0, highlightthickness=0)
  78. scrollbar = tk.Scrollbar(content, orient="vertical", command=canvas.yview, troughcolor=global_bg_color, width=12, bd=0)
  79. buttonsframe = tk.Frame(canvas, bd=0, bg=global_bg_color, highlightcolor='white', highlightthickness=0, pady=10)
  80. buttonsframe.bind(
  81. "<Configure>",
  82. lambda e: canvas.configure(
  83. scrollregion=canvas.bbox("all")
  84. )
  85. )
  86. canvas.create_window((0, 0), window=buttonsframe, anchor="nw")
  87. canvas.configure(yscrollcommand=scrollbar.set)
  88. def _on_mousewheel(event):
  89. ysi = 1
  90. for i in range(3):
  91. canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
  92. ysi += 1
  93. canvas.config(yscrollincrement=ysi)
  94. root.update()
  95. time.sleep(0.01)
  96. for i in range(4):
  97. canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
  98. root.update()
  99. time.sleep(0.01)
  100. for i in range(3):
  101. canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
  102. ysi -= 1
  103. canvas.config(yscrollincrement=ysi)
  104. root.update()
  105. time.sleep(0.01)
  106. canvas.config(yscrollincrement=1)
  107. canvas.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  108. bottombf = tk.Frame(_root, bg=global_bg_color, bd=0)
  109. bottombf.pack(anchor='sw', side='right', fill='y')
  110.  
  111. if not len(pinnedprogramnames) == 0:
  112. tk.Label(buttonsframe, text="\nPinned", bg=global_bg_color, fg=global_fg_color, font=(None, 11, "bold")).pack(anchor='nw', padx=5, pady=5)
  113. for name in pinnedprogramnames:
  114. 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)
  115. tempbutton.pack(anchor='nw', padx=5)
  116. tempbutton.bind("<Button-3>", lambda e, name=name: unpin(name))
  117. if not programnames[0][0].isalpha():
  118. 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)
  119. else:
  120. pass
  121. for name in programnames:
  122. if name[0].isalpha() and not name[0].upper() == currentletter:
  123. currentletter = name[0].upper()
  124. 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)
  125. 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)
  126. tempbutton.pack(anchor='nw', padx=5)
  127. tempbutton.bind("<Button-3>", lambda e, name=name: pin(name))
  128.  
  129. for child in canvas.winfo_children():
  130. child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  131.  
  132. for child in buttonsframe.winfo_children():
  133. child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  134.  
  135. scrollbar.update()
  136. canvas.place(x=0, y=0, relwidth=1.0, relheight=1.0)
  137. scrollbar.pack(side="right", fill="y")
  138.  
  139. def restarttechos():
  140. keyboard.remove_all_hotkeys()
  141. root.destroy()
  142. exec(compile(open("T:/TechOS/Virtual/TechOS.py", "rb").read(), "T:/TechOS/Virtual/TechOS.py", 'exec'), {})
  143. sys.exit()
  144.  
  145. def updatetechos():
  146. global mb
  147. if mb.askyesno("Update TechOS?","This process might take a while!") == True:
  148. root.destroy()
  149. exec(compile(open("T:/TechOS/Virtual/Update.py", "rb").read(), "T:/TechOS/Virtual/Update.py", 'exec'), {})
  150. sys.exit()
  151. else:
  152. pass
  153.  
  154. def exit():
  155. exitsure = mb.askyesno("Exit TechOS Virtual", "Are you sure you want to exit TechOS?")
  156. if exitsure:
  157. root.destroy()
  158. sys.exit()
  159. else:
  160. pass
  161.  
  162. 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)
  163. exitbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  164. 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)
  165. restartbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  166. if updateavailable == True:
  167. 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)
  168. updatebutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  169. else:
  170. pass
  171. 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)
  172. settingsbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  173.  
  174. descshown = False
  175.  
  176. def showdesc():
  177. exitbutton.config(compound="left")
  178. restartbutton.config(compound="left")
  179. settingsbutton.config(compound="left")
  180. menubutton.config(compound="left")
  181. try:
  182. updatebutton.config(compound="left")
  183. except:
  184. pass
  185.  
  186. def hidedesc():
  187. exitbutton.config(compound="none")
  188. restartbutton.config(compound="none")
  189. settingsbutton.config(compound="none")
  190. menubutton.config(compound="none")
  191. try:
  192. updatebutton.config(compound="none")
  193. except:
  194. pass
  195.  
  196. def toggledesc():
  197. global descshown
  198. if descshown == True:
  199. hidedesc()
  200. descshown = False
  201. else:
  202. showdesc()
  203. descshown = True
  204.  
  205. 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)
  206. menubutton.pack(side='top', anchor='nw', padx=5, pady=5)
  207.  
  208. if DARK_SYSTEM_APPS == "True":
  209. exitbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/ExitWhite.png")
  210. exitbutton.config(image=exitbutton.image)
  211. restartbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/RestartWhite.png")
  212. restartbutton.config(image=restartbutton.image)
  213. try:
  214. updatebutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/UpdateWhite.png")
  215. updatebutton.config(image=updatebutton.image)
  216. except:
  217. pass
  218. settingsbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/SettingsWhite.png")
  219. settingsbutton.config(image=settingsbutton.image)
  220. menubutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/MenuWhite.png")
  221. menubutton.config(image=menubutton.image)
  222. else:
  223. exitbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/ExitBlack.png")
  224. exitbutton.config(image=exitbutton.image)
  225. restartbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/RestartBlack.png")
  226. restartbutton.config(image=restartbutton.image)
  227. try:
  228. updatebutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/UpdateBlack.png")
  229. updatebutton.config(image=updatebutton.image)
  230. except:
  231. pass
  232. settingsbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/SettingsBlack.png")
  233. settingsbutton.config(image=settingsbutton.image)
  234. menubutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/MenuBlack.png")
  235. menubutton.config(image=menubutton.image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement