Clipboardbuffers.py: Difference between revisions
From Lucca's Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
import time | import time | ||
import pyperclip | import pyperclip | ||
import pyautogui | import pyautogui as pg | ||
import pickle | import pickle | ||
import tkinter as tk | |||
#pg.prompt(text="deez nuts?", title="deez nutz!", default="deez nars") | |||
def dumpClipboardBufferToFile(): | def dumpClipboardBufferToFile(): | ||
| Line 29: | Line 31: | ||
def inputbox(inputBuffer): | def inputbox(inputBuffer): | ||
inputText = "No Input Given Yet" | inputText = "No Input Given Yet" | ||
window = tk.Tk() | |||
textbox = | textbox = tk.Text(window) | ||
textbox.pack() | textbox.pack() | ||
textbox.insert(0, clipboardBuffer[inputBuffer]) | textbox.insert(0.0, clipboardBuffer[inputBuffer]) | ||
textbox.focus_set() | textbox.focus_set() | ||
def entry_select_all(event): | |||
event.widget.select_range(0.0, 'end') | |||
event.widget.icursor('end') | |||
return 'break' | |||
def entry_ctrl_backspace(event): | |||
end_idx = textbox.index(tk.INSERT) | |||
start_idx = textbox.get().rfind(" ", None, end_idx) | |||
textbox.selection_range(start_idx, end_idx) | |||
def onclick(pos): | def onclick(pos): | ||
nonlocal inputText | nonlocal inputText | ||
inputText = textbox.get() | inputText = textbox.get(0.0, 'end') | ||
global clipboardBuffer | global clipboardBuffer | ||
clipboardBuffer[inputBuffer] = inputText | clipboardBuffer[inputBuffer] = inputText | ||
print(f"Clipboard buffer {inputBuffer} was set to: {inputText}") | print(f"Clipboard buffer {inputBuffer} was set to: {inputText}") | ||
window.destroy() | |||
b = Button( | b = tk.Button(window, text="OK", width=10, command=onclick) | ||
b.pack() | b.pack() | ||
textbox.bind('<Return>', onclick) | textbox.bind('<Return>', onclick) | ||
mainloop() | textbox.bind('<Control-BackSpace>', entry_ctrl_backspace) | ||
textbox.bind('<Control-Key-a>', entry_select_all) | |||
window.mainloop() | |||
print(clipboardBuffer) | print(clipboardBuffer) | ||
dumpClipboardBufferToFile() | dumpClipboardBufferToFile() | ||
| Line 54: | Line 66: | ||
def copyToBuffer(inputBuffer): | def copyToBuffer(inputBuffer): | ||
global clipboardBuffer | global clipboardBuffer | ||
clipboardBuffer[inputBuffer] = pyperclip.paste() | clipboardBuffer[inputBuffer] = pyperclip.paste() | ||
dumpClipboardBufferToFile() | dumpClipboardBufferToFile() | ||
Revision as of 01:18, 12 December 2024
import sys import os import time import pyperclip import pyautogui as pg import pickle import tkinter as tk
- pg.prompt(text="deez nuts?", title="deez nutz!", default="deez nars")
def dumpClipboardBufferToFile():
global clipboardBuffer
with open("clipboardBufferData.pk", 'wb') as fi:
pickle.dump(clipboardBuffer, fi)
def getClipboardBufferFromFile():
global clipboardBuffer
with open("clipboardBufferData.pk", 'rb') as fi:
clipboardBuffer = pickle.load(fi)
- scriptFolder = (os.path.dirname(__file__))
clipboardBuffer = [] clipboardBuffer = ["No value in this clipboard buffer" for i in range(10)]
- check if pickle file exists, if not, then create one
if os.path.isfile("clipboardBufferData.pk"):
getClipboardBufferFromFile()
else:
dumpClipboardBufferToFile()
def inputbox(inputBuffer):
inputText = "No Input Given Yet"
window = tk.Tk()
textbox = tk.Text(window)
textbox.pack()
textbox.insert(0.0, clipboardBuffer[inputBuffer])
textbox.focus_set()
def entry_select_all(event):
event.widget.select_range(0.0, 'end')
event.widget.icursor('end')
return 'break'
def entry_ctrl_backspace(event):
end_idx = textbox.index(tk.INSERT)
start_idx = textbox.get().rfind(" ", None, end_idx)
textbox.selection_range(start_idx, end_idx)
def onclick(pos):
nonlocal inputText
inputText = textbox.get(0.0, 'end')
global clipboardBuffer
clipboardBuffer[inputBuffer] = inputText
print(f"Clipboard buffer {inputBuffer} was set to: {inputText}")
window.destroy()
b = tk.Button(window, text="OK", width=10, command=onclick)
b.pack()
textbox.bind('<Return>', onclick)
textbox.bind('<Control-BackSpace>', entry_ctrl_backspace)
textbox.bind('<Control-Key-a>', entry_select_all)
window.mainloop()
print(clipboardBuffer)
dumpClipboardBufferToFile()
return (inputText)
def typeBuffer(inputBuffer):
global clipboardBuffer pyautogui.write(clipboardBuffer[inputBuffer])
def copyToBuffer(inputBuffer):
global clipboardBuffer clipboardBuffer[inputBuffer] = pyperclip.paste() dumpClipboardBufferToFile()
if sys.argv[1] == "paste":
typeBuffer(int(sys.argv[2]))
if sys.argv[1] == "copy":
copyToBuffer(int(sys.argv[2]))
if sys.argv[1] == "edit":
inputbox(int(sys.argv[2]))