Techpad

ProgramList 12

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