Techpad

Commands 6

Mar 17th, 2021 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. import tkinter as tk
  2. import os
  3. try:
  4. import pyperclip
  5. except ModuleNotFoundError:
  6. os.system('pip install pyperclip')
  7. import pyperclip
  8.  
  9. _root = frame1
  10.  
  11. commandslist = [
  12. "CLEAR Syntax: (clear) Usage: clears the screen of all previous commands",
  13. "CLS Syntax: (cls) Usage: clears the screen of all previous commands\n"
  14. " (same as CLEAR)",
  15. "COLORS Syntax: (colors [color1] [color2]) Usage: changes the foreground and background color\n"
  16. " of the command interface",
  17. "HELP Syntax: (help) (help [command]) Usage: shows this menu, or gives information about\n"
  18. " a specific command",
  19. "PROMPT Syntax: (prompt [text]) Usage: changes the prompt text in the command line\n"
  20. " from '>' to a custom string",
  21. "RESET Syntax: (reset) Usage: clears the screen, shows startup text, and\n"
  22. " resets all settings to default",
  23. "RS Syntax: (rs) Usage: clears the screen, shows startup text, and\n"
  24. " resets all settings to default (same as RESET)",
  25. "START Syntax: (start [program name]) Usage: starts a program using Techpad SmartProgram,\n"
  26. " or creates window with given title if program\n"
  27. " does not exist",
  28. "VERSION Syntax: (version) Usage: displays the current version of TechOS"
  29. ]
  30.  
  31. def show(out):
  32. global output
  33. output.insert('end', f'\n{out}')
  34. output.see('end')
  35.  
  36. def command(e):
  37. global _input
  38. global show
  39. global output
  40. global prompt
  41. global commandslist
  42. cmd = _input.get()
  43. lcmd = cmd.lower()
  44. _input.delete(0, "end")
  45. params = cmd.split()
  46. lparams = lcmd.split()
  47. show(f"> {cmd}")
  48. if lparams[0] == 'start':
  49. if len(params) > 1:
  50. program = ' '.join([i for i in params[1:]])
  51. startprogram(program)
  52. else:
  53. show("Invalid syntax: Use (start [program name])")
  54. elif lcmd == "version":
  55. with open("T:/TechOS/Virtual/Info/Version.info", "r") as vf:
  56. version = f"TechOS version {vf.read()}"
  57. show(version)
  58. elif lcmd == "clear" or lcmd == "cls":
  59. output.delete(1.0, "end")
  60. elif lcmd == "reset" or lcmd == "rs":
  61. output.delete(1.0, "end")
  62. output.insert(1.0, "Commands v0.0\n")
  63. prompt.config(text='>')
  64. c1 = '#00afff'
  65. c2 = 'black'
  66. output.config(fg=c1, insertbackground=c1, selectbackground=c1, bg=c2, selectforeground=c2)
  67. prompt.config(bg=c2, fg=c1)
  68. _input.config(bg=c2, fg=c1, insertbackground=c1, selectbackground=c1, selectforeground=c2)
  69. elif lparams[0] == "prompt":
  70. if len(params) > 1:
  71. prompt.config(text=' '.join([i for i in params[1:]]))
  72. else:
  73. show("Invalid syntax: Use (prompt [text])")
  74. elif lparams[0] == "colors":
  75. if len(lparams) == 3:
  76. try:
  77. c1 = lparams[1]
  78. c2 = lparams[2]
  79. output.config(fg=c1, insertbackground=c1, selectbackground=c1, bg=c2, selectforeground=c2)
  80. prompt.config(bg=c2, fg=c1)
  81. _input.config(bg=c2, fg=c1, insertbackground=c1, selectbackground=c1, selectforeground=c2)
  82. except:
  83. show("Invalid colors: Use hexadecimal format or any valid color name.")
  84. else:
  85. show("Invalid syntax: Use (colors [color1] [color2])")
  86. elif lcmd == "help":
  87. show("Available commands:\n\n" + '\n\n'.join(i for i in commandslist))
  88. elif lparams[0] == "help":
  89. if len([i for i in commandslist if i.lower().startswith(lparams[1] + " ")]) == 0:
  90. show(f"That command doesn't exist: {lparams[1]}")
  91. else:
  92. show("\n" + ''.join([i for i in commandslist if i.lower().startswith(lparams[1] + ' ')]) + "\n")
  93. else:
  94. show(f"Invalid command: {params[0]}")
  95.  
  96. def copyselection(e):
  97. global output
  98. global pyperclip
  99. pyperclip.copy(output.selection_get())
  100.  
  101. output = tk.Text(_root, bg='black', fg='#00afff', insertbackground='#00afff', insertofftime=0, bd=0, selectbackground='#00afff', selectforeground='black', font='consolas 12', height=1)
  102. output.bind('<Key>', 'break')
  103. output.bind('<Button-3>', copyselection)
  104. output.pack(expand=True, fill='both')
  105. output.insert(1.0, "Commands v0.0\n")
  106. prompt = tk.Label(_root, bg='black', fg='#00afff', justify='left', text='>', font='consolas 10', pady=1)
  107. prompt.pack(side='left', anchor='sw')
  108. _input = tk.Entry(_root, bg='black', fg='#00afff', justify='left', bd=0, insertbackground='#00afff', selectbackground='#00afff', selectforeground='black', font='consolas 12')
  109. _input.pack(side='left', expand=True, fill='x', anchor='se')
  110. _input.bind('<Return>', command)
  111. _input.focus()
Add Comment
Please, Sign In to add comment