Clipboardbuffers.py: Difference between revisions

From Lucca's Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
import os
import sys
import sys
import os
from threading import Event
import time
from PyHotKey import Key, keyboard
import pyperclip
keyboard.suppress_hotkey = True
import pyautogui as pg
from tkinter import *
from PyHotKey import Key, keyboard
import pickle
import tkinter as tk


scriptFolder = (os.path.dirname(__file__))
#pg.prompt(text="deez nuts?", title="deez nutz!", default="deez nars")


clipboardBuffer = []
def dumpClipboardBufferToFile():
clipboardBuffer = ["No value in this clipboard buffer" for i in range(10)]
    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)


def inputbox(inputBuffer):
#scriptFolder = (os.path.dirname(__file__))
    inputText = "No Input Given Yet"
clipboardBuffer = []
    master = Tk()
clipboardBuffer = ["No value in this clipboard buffer" for i in range(10)]
    textbox = Entry(master)
    textbox.pack()
    textbox.focus_set()


    def onclick(pos):
#check if pickle file exists, if not, then create one
        nonlocal inputText
if os.path.isfile("clipboardBufferData.pk"):
        inputText = textbox.get()
    getClipboardBufferFromFile()
        global clipboardBuffer
else:
        clipboardBuffer[inputBuffer] = inputText
    dumpClipboardBufferToFile()
        print(f"Clipboard buffer {inputBuffer} was set to: {inputText}")
        master.destroy()


    b = Button(master, text="OK", width=10, command=onclick)
def inputbox(inputBuffer):
    b.pack()
    inputText = "No Input Given Yet"
    textbox.bind('<Return>', onclick)
    window = tk.Tk()
    mainloop()
    window.title('clipboardbuffers')
    print(clipboardBuffer)
    textbox = tk.Entry(window, width=400)
    return (inputText)
    textbox.pack()
 
    textbox.insert(0, clipboardBuffer[inputBuffer])
def typeBuffer(inputBuffer):
    textbox.focus_set()
    keyboard.type("\b"+clipboardBuffer[inputBuffer])
    def entry_select_all(event):
 
        event.widget.select_range(0, 'end')
#Hotkeys go here!!#
        event.widget.icursor('end')
for x in [1,2,3,4,5,6,7,8,9]:
        return 'break'
    keyboard.register_hotkey([Key.cmd, Key.shift, str(x)], None, inputbox, x) #windows key + 1,2,3,4,5,6,7,8,9,etc
    def entry_ctrl_backspace(event):
    keyboard.register_hotkey([Key.cmd, str(x)], None, typeBuffer, x)  #windows key + 1,2,3,4,5,6,7,8,9,etc [https://pynput.readthedocs.io/en/latest/keyboard.html]
        end_idx = textbox.index(tk.INSERT)
#Hotkeys go here!!#
        start_idx = textbox.get().rfind(" ", None, end_idx)
 
        textbox.selection_range(start_idx, end_idx)
 
    def onclick(pos):
print(keyboard.hotkeys)
        nonlocal inputText
import threading
        inputText = textbox.get()
 
        global clipboardBuffer
event = threading.Event()
        clipboardBuffer[inputBuffer] = inputText
event.wait()
        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('<KP_Enter>', 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])
    keyboard.type(clipboardBuffer[inputBuffer])
def copyToBuffer(inputBuffer):
    global clipboardBuffer
    clip = pyperclip.paste()
    clipboardBuffer[inputBuffer] = clip
    print(clipboardBuffer[inputBuffer])
    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]))

Latest revision as of 05:48, 12 December 2024

import sys import os import time import pyperclip import pyautogui as pg from PyHotKey import Key, keyboard import pickle import tkinter as tk

  1. 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)
  1. scriptFolder = (os.path.dirname(__file__))

clipboardBuffer = [] clipboardBuffer = ["No value in this clipboard buffer" for i in range(10)]

  1. 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()
   window.title('clipboardbuffers')
   textbox = tk.Entry(window, width=400)
   textbox.pack()
   textbox.insert(0, clipboardBuffer[inputBuffer])
   textbox.focus_set()
   def entry_select_all(event):
       event.widget.select_range(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()
       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('<KP_Enter>', 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
  1. pyautogui.write(clipboardBuffer[inputBuffer])
   keyboard.type(clipboardBuffer[inputBuffer])

def copyToBuffer(inputBuffer):

   global clipboardBuffer
   clip = pyperclip.paste()
   clipboardBuffer[inputBuffer] = clip
   print(clipboardBuffer[inputBuffer])
   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]))