Advertisement
Techpad

ProgramList 11

Apr 14th, 2021
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.95 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. import ast
  8. from threading import Thread
  9.  
  10. DARK_SYSTEM_APPS = open("T:/TechOS/Virtual/Settings/DARK_SYSTEM_APPS.set", "r").read()
  11. ACCENT_COLOR = open("T:/TechOS/Virtual/Settings/ACCENT_COLOR.set", "r").read()
  12.  
  13. def color_variant(hex_color, brightness_offset=1):
  14. """ takes a color like #87c95f and produces a lighter or darker variant """
  15. if len(hex_color) != 7:
  16. raise Exception("Passed %s into color_variant(), needs to be in #87c95f format." % hex_color)
  17. rgb_hex = [hex_color[x:x+2] for x in [1, 3, 5]]
  18. new_rgb_int = [int(hex_value, 16) + brightness_offset for hex_value in rgb_hex]
  19. new_rgb_int = [min([255, max([0, i])]) for i in new_rgb_int] # make sure new values are between 0 and 255
  20. # hex() produces "0x88", we want just "88"
  21. return "#" + "".join(["{:02x}".format(i) for i in new_rgb_int])
  22.  
  23. BLACK_ACCENT_COLOR = color_variant(ACCENT_COLOR, -200)
  24. DIM_ACCENT_COLOR = color_variant(ACCENT_COLOR, -20)
  25. DARK_ACCENT_COLOR = color_variant(ACCENT_COLOR, -10)
  26. LIGHT_ACCENT_COLOR = color_variant(ACCENT_COLOR, 10)
  27. BRIGHT_ACCENT_COLOR = color_variant(ACCENT_COLOR, 20)
  28. WHITE_ACCENT_COLOR = color_variant(ACCENT_COLOR, 200)
  29.  
  30. global_bg_color = "white"
  31. global_fg_color = "black"
  32. global_ac_bg_color = "lightgray"
  33. global_sp_bg_color = WHITE_ACCENT_COLOR
  34.  
  35. if DARK_SYSTEM_APPS == "True":
  36. global_bg_color = "gray12"
  37. global_fg_color = "gray90"
  38. global_ac_bg_color = "gray20"
  39. global_sp_bg_color = BLACK_ACCENT_COLOR
  40.  
  41. _root = frame3
  42.  
  43. frame3.config(bg=global_bg_color)
  44.  
  45. def pin(name):
  46. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
  47. pinnedprogramnames = f.read().splitlines(False)
  48. if not name in pinnedprogramnames:
  49. pinnedprogramnames.append(name)
  50. newnames = "\n".join(pinnedprogramnames)
  51. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
  52. f.write(newnames)
  53. else:
  54. unpin(name)
  55. refreshpm()
  56.  
  57. def unpin(name):
  58. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
  59. pinnedprogramnames = f.read().splitlines(False)
  60. pinnedprogramnames.remove(name)
  61. newnames = "\n".join(pinnedprogramnames)
  62. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
  63. f.write(newnames)
  64. refreshpm()
  65.  
  66. def unpin_soft(name):
  67. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
  68. pinnedprogramnames = f.read().splitlines(False)
  69. pinnedprogramnames.remove(name)
  70. newnames = "\n".join(pinnedprogramnames)
  71. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "w") as f:
  72. f.write(newnames)
  73.  
  74. infofolder = os.listdir("T:/ProgramData/Info")
  75. infofiles = [file for file in infofolder if file.endswith('.info') and not file.endswith('ProgramList.info')]
  76. programnames = []
  77. for file in infofiles:
  78. programnames.append(os.path.basename(file)[:-5])
  79. with open("T:/TechOS/Virtual/Settings/PINNED_PROGRAMS.set", "r") as f:
  80. pinnedprogramnames = f.read().splitlines(False)
  81. currentletter = "#"
  82.  
  83. bottombf = tk.Frame(_root, bg=global_bg_color, bd=0)
  84. bottombf.pack(anchor='sw', side='left', fill='y')
  85. content = tk.Frame(_root, bg=global_bg_color, bd=0)
  86. content.pack_propagate(0)
  87. content.pack(anchor='ne', side='left', expand=True, fill='both')
  88. canvas = tk.Canvas(content, bg=global_bg_color, bd=0, highlightthickness=0)
  89. scrollbar = tk.Scrollbar(_root, orient="vertical", command=canvas.yview, troughcolor=global_bg_color, width=12, bd=0)
  90. buttonsframe = tk.Frame(canvas, bd=0, bg=global_bg_color, highlightcolor='white', highlightthickness=0, pady=10)
  91. searchframe = tk.Frame(_root, bd=0, bg=global_bg_color, highlightthickness=0, width=50)
  92. searchframe.pack(anchor='ne', side='left', expand=True, fill='both')
  93. searchframe.pack_propagate(0)
  94. buttonsframe.bind(
  95. "<Configure>",
  96. lambda e: canvas.configure(
  97. scrollregion=canvas.bbox("all")
  98. )
  99. )
  100. canvas.create_window((0, 0), window=buttonsframe, anchor="nw")
  101. canvas.configure(yscrollcommand=scrollbar.set)
  102. def _on_mousewheel(event):
  103. ysi = 1
  104. for i in range(3):
  105. canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
  106. ysi += 1
  107. canvas.config(yscrollincrement=ysi)
  108. root.update()
  109. time.sleep(0.01)
  110. for i in range(4):
  111. canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
  112. root.update()
  113. time.sleep(0.01)
  114. for i in range(3):
  115. canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
  116. ysi -= 1
  117. canvas.config(yscrollincrement=ysi)
  118. root.update()
  119. time.sleep(0.01)
  120. canvas.config(yscrollincrement=1)
  121. canvas.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  122.  
  123. if not len(pinnedprogramnames) == 0:
  124. tk.Label(buttonsframe, text="\nPinned", bg=global_bg_color, fg=global_fg_color, font=(None, 11, "bold")).pack(anchor='nw', padx=5, pady=5)
  125. for name in pinnedprogramnames:
  126. if os.path.exists(f"T:/ProgramData/Info/{name}.info"):
  127. if len(name) > 30:
  128. shortname = name[:28] + "..."
  129. else:
  130. shortname = name
  131. 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)
  132. try:
  133. with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
  134. infolist = ast.literal_eval(f.read())
  135. tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
  136. tempbutton.config(image=tempbutton.image, compound="left", text=f" {tempbutton['text']}")
  137. except SyntaxError or NameError:
  138. pass
  139. tempbutton.pack(anchor='nw', padx=5)
  140. tempbutton.bind("<Button-3>", lambda e, name=name: unpin(name))
  141. else:
  142. unpin_soft(name)
  143. if not programnames[0][0].isalpha():
  144. 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)
  145. else:
  146. pass
  147. for name in programnames:
  148. if len(name) > 30:
  149. shortname = name[:28] + "..."
  150. else:
  151. shortname = name
  152. if name[0].isalpha() and not name[0].upper() == currentletter:
  153. currentletter = name[0].upper()
  154. 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)
  155. 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)
  156. try:
  157. with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
  158. infolist = ast.literal_eval(f.read())
  159. tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
  160. tempbutton.config(image=tempbutton.image, compound="left", text=f" {tempbutton['text']}")
  161. except SyntaxError or NameError:
  162. pass
  163. tempbutton.pack(anchor='nw', padx=5)
  164. tempbutton.bind("<Button-3>", lambda e, name=name: pin(name))
  165.  
  166. for child in canvas.winfo_children():
  167. child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  168.  
  169. for child in buttonsframe.winfo_children():
  170. child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  171.  
  172. scrollbar.update()
  173. canvas.pack(side='left', expand=True, fill='both')
  174. scrollbar.pack(side="right", fill="y", anchor='e')
  175.  
  176. class EntryWithPlaceholder(tk.Entry):
  177. def __init__(self, master=None, placeholder="PLACEHOLDER", color='grey', **kwargs):
  178. super().__init__(master)
  179.  
  180. self.config(kwargs)
  181.  
  182. self.placeholder = placeholder
  183. self.placeholder_color = color
  184. self.default_fg_color = self['fg']
  185.  
  186. self.bind("<FocusIn>", self.foc_in)
  187. self.bind("<FocusOut>", self.foc_out)
  188.  
  189. self.put_placeholder()
  190.  
  191. def put_placeholder(self):
  192. self.insert(0, self.placeholder)
  193. self['fg'] = self.placeholder_color
  194.  
  195. def foc_in(self, *args):
  196. if self['fg'] == self.placeholder_color:
  197. self.delete('0', 'end')
  198. self['fg'] = self.default_fg_color
  199.  
  200. def foc_out(self, *args):
  201. if not self.get():
  202. self.put_placeholder()
  203.  
  204. def search(text):
  205. 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"}
  206. exactmatches = []
  207. replacematches = []
  208. startmatches = []
  209. betweenmatches = []
  210. if text.lower() in shortnames:
  211. replacematches.append(shortnames[text.lower()])
  212. for name in programnames:
  213. if text.lower() == name.lower():
  214. exactmatches.append(name)
  215. elif name.lower().startswith(text.lower()):
  216. startmatches.append(name)
  217. elif text.lower() in name.lower():
  218. betweenmatches.append(name)
  219. else:
  220. pass
  221. matches = exactmatches + replacematches + startmatches + betweenmatches
  222. return matches
  223.  
  224. searchbox = EntryWithPlaceholder(searchframe, placeholder="Search apps...", bd=0, highlightcolor=ACCENT_COLOR, highlightthickness=2, highlightbackground="lightgray")
  225. searchbox.pack(fill='x', padx=10, pady=10)
  226. resultsbox = tk.Frame(searchframe, bd=0, bg=global_bg_color, padx=10)
  227. resultsbox.pack(expand=True, fill='both')
  228.  
  229. searchbox.bind("<Return>", lambda e: resultsbox.winfo_children()[0].invoke())
  230.  
  231. def focus_search(e):
  232. searchbox.delete(0, 'end')
  233. searchbox.focus()
  234. searchbox.update()
  235. searchbox.insert(0, e.char)
  236. searchresults()
  237.  
  238. def start_focusable(e):
  239. searchframe.unbind("<Key>")
  240. searchframe.bind("<KeyRelease>", focus_search)
  241.  
  242. searchframe.bind("<Key>", start_focusable)
  243. searchframe.focus()
  244.  
  245. searchframe.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  246. resultsbox.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
  247.  
  248. def searchresults():
  249. if not searchbox.get() == "":
  250. list = search(searchbox.get())
  251. for child in resultsbox.winfo_children():
  252. child.destroy()
  253. if len(list) > 0:
  254. if len(list) > 20:
  255. 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()
  256. for name in list[:20]:
  257. if len(name) > 30:
  258. shortname = name[:28] + "..."
  259. else:
  260. shortname = name
  261. _tempbutton = tk.Button(resultsbox, text=shortname, command=lambda name=name: startprogram(name),
  262. bg=global_bg_color, activebackground=global_ac_bg_color, bd=0, fg=global_fg_color,
  263. activeforeground=global_fg_color)
  264. try:
  265. with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
  266. infolist = ast.literal_eval(f.read())
  267. _tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
  268. _tempbutton.config(image=_tempbutton.image, compound="left", text=f" {_tempbutton['text']}")
  269. except SyntaxError or NameError:
  270. pass
  271. _tempbutton.pack(anchor='nw')
  272. else:
  273. for name in list:
  274. if len(name) > 30:
  275. shortname = name[:28] + "..."
  276. else:
  277. shortname = name
  278. _tempbutton = tk.Button(resultsbox, text=shortname, command=lambda name=name: startprogram(name),
  279. bg=global_bg_color, activebackground=global_ac_bg_color, bd=0, fg=global_fg_color,
  280. activeforeground=global_fg_color)
  281. try:
  282. with open(f"T:/ProgramData/Info/{name}.info", "r") as f:
  283. infolist = ast.literal_eval(f.read())
  284. _tempbutton.image = tk.PhotoImage(file=infolist["ICONPATH"])
  285. _tempbutton.config(image=_tempbutton.image, compound="left", text=f" {_tempbutton['text']}")
  286. except SyntaxError or NameError:
  287. pass
  288. _tempbutton.pack(anchor='nw')
  289. else:
  290. tk.Label(resultsbox, text='No results found', bg=global_bg_color, fg=global_fg_color).pack()
  291. else:
  292. for child in resultsbox.winfo_children():
  293. child.destroy()
  294.  
  295. searchbox.bind('<KeyRelease>', lambda e: searchresults())
  296.  
  297. def restarttechos():
  298. keyboard.remove_all_hotkeys()
  299. root.destroy()
  300. exec(compile(open("T:/TechOS/Virtual/TechOS.py", "rb").read(), "T:/TechOS/Virtual/TechOS.py", 'exec'), {})
  301. sys.exit()
  302.  
  303. def updatetechos():
  304. global mb
  305. if mb.askyesno("Update TechOS?","This process might take a while!") == True:
  306. root.destroy()
  307. exec(compile(open("T:/TechOS/Virtual/Update.py", "rb").read(), "T:/TechOS/Virtual/Update.py", 'exec'), {})
  308. sys.exit()
  309. else:
  310. pass
  311.  
  312. def exit():
  313. exitsure = mb.askyesno("Exit TechOS Virtual", "Are you sure you want to exit TechOS?")
  314. if exitsure:
  315. root.destroy()
  316. sys.exit()
  317. else:
  318. pass
  319.  
  320. 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)
  321. exitbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  322. 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)
  323. restartbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  324. if updateavailable == True:
  325. 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)
  326. updatebutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  327. else:
  328. pass
  329. 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)
  330. settingsbutton.pack(side='bottom', anchor='sw', padx=5, pady=5)
  331.  
  332. descshown = False
  333.  
  334. def showdesc():
  335. exitbutton.config(compound="left")
  336. restartbutton.config(compound="left")
  337. settingsbutton.config(compound="left")
  338. menubutton.config(compound="left")
  339. try:
  340. updatebutton.config(compound="left")
  341. except:
  342. pass
  343.  
  344. def hidedesc():
  345. exitbutton.config(compound="none")
  346. restartbutton.config(compound="none")
  347. settingsbutton.config(compound="none")
  348. menubutton.config(compound="none")
  349. try:
  350. updatebutton.config(compound="none")
  351. except:
  352. pass
  353.  
  354. def toggledesc():
  355. global descshown
  356. if descshown == True:
  357. hidedesc()
  358. descshown = False
  359. else:
  360. showdesc()
  361. descshown = True
  362.  
  363. 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)
  364. menubutton.pack(side='top', anchor='nw', padx=5, pady=5)
  365.  
  366. if DARK_SYSTEM_APPS == "True":
  367. exitbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/ExitWhite.png")
  368. exitbutton.config(image=exitbutton.image)
  369. restartbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/RestartWhite.png")
  370. restartbutton.config(image=restartbutton.image)
  371. try:
  372. updatebutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/UpdateWhite.png")
  373. updatebutton.config(image=updatebutton.image)
  374. except:
  375. pass
  376. settingsbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/SettingsWhite.png")
  377. settingsbutton.config(image=settingsbutton.image)
  378. menubutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/MenuWhite.png")
  379. menubutton.config(image=menubutton.image)
  380. else:
  381. exitbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/ExitBlack.png")
  382. exitbutton.config(image=exitbutton.image)
  383. restartbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/RestartBlack.png")
  384. restartbutton.config(image=restartbutton.image)
  385. try:
  386. updatebutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/UpdateBlack.png")
  387. updatebutton.config(image=updatebutton.image)
  388. except:
  389. pass
  390. settingsbutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/SettingsBlack.png")
  391. settingsbutton.config(image=settingsbutton.image)
  392. menubutton.image = tk.PhotoImage(file="T:/TechOS/Virtual/Images/MenuBlack.png")
  393. menubutton.config(image=menubutton.image)
  394.  
  395. def _system_memorysaver():
  396. from threading import Thread
  397. def _system_checkexistence():
  398. import time
  399. import sys
  400. if frame3.winfo_exists():
  401. pass
  402. else:
  403. sys.exit()
  404. time.sleep(1)
  405. _system_checkexistence()
  406.  
  407. Thread(target=_system_checkexistence, daemon=True).start()
  408.  
  409. _system_memorysaver()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement