129 lines
No EOL
4.2 KiB
Python
129 lines
No EOL
4.2 KiB
Python
import PySimpleGUI as sg
|
|
import datetime
|
|
import barcode
|
|
import pyperclip
|
|
import keyboard
|
|
from PIL import ImageGrab
|
|
from pytesseract import pytesseract
|
|
# First the window layout in 2 columns
|
|
|
|
#You must remove Tesserect for PYinstaller
|
|
path_to_tesseract = r"C:\Users\30783009\AppData\Local\Programs\Tesseract-OCR\tesseract.exe"
|
|
|
|
rules = [[sg.Text("All scans copy output to clipboard:")]]
|
|
barker = [
|
|
[
|
|
sg.Text("Make Barcode:"),
|
|
sg.In(size=(25, 10), enable_events=True, key="-mkbox-",),
|
|
sg.Button(button_text="Encode", enable_events=True, key="-GO-"),
|
|
],
|
|
]
|
|
newlot = [
|
|
[
|
|
sg.Text("Lot Pull:"),
|
|
sg.Input(size=(25, 10), enable_events=True, key="pull"),
|
|
sg.Button(button_text="Extract", enable_events=True, bind_return_key = True, key="noop"),
|
|
],
|
|
]
|
|
# ----- Full layout -----
|
|
layout = [
|
|
[sg.Column(rules, justification="Left")],
|
|
[sg.Column(barker, justification="Right")],
|
|
[sg.Column(newlot, justification="Right")],
|
|
]
|
|
|
|
window = sg.Window("Scanner Tool", layout)
|
|
arrrg = "404barcodenotfound"
|
|
#Functionality
|
|
def clippy(sluggers):
|
|
pyperclip.copy(sluggers)
|
|
pyperclip.paste()
|
|
def clippyB(mrpaperclip):
|
|
pyperclip.copy(mrpaperclip)
|
|
pyperclip.paste()
|
|
keyboard.press_and_release("backspace")
|
|
keyboard.press_and_release("backspace")
|
|
def readpicture():
|
|
try:
|
|
foo = ImageGrab.grabclipboard()
|
|
pytesseract.tesseract_cmd = path_to_tesseract
|
|
pitty = pytesseract.image_to_string(foo)
|
|
foofighter = str(pitty)
|
|
clippy(foofighter)
|
|
print(foofighter)
|
|
return foofighter
|
|
except:
|
|
print("I don't think you have a picture on your clipboard.\nTry using [windows]+[shift]+[s] to take a screen grab that I can read.\n -Best Regards, The AI")
|
|
def Bark(): #I make barcodes
|
|
ean = barcode.get('code128', arrrg,)
|
|
ean.save("Pybar")
|
|
def longboifile(code): #I log what is done.
|
|
LOG = open("Loggy_Mclogface.log", "at")
|
|
LOG.write(str(code) + "||" + str(datetime.datetime.now()) + "\n")
|
|
def newt():
|
|
lot = arrg.rsplit("|")
|
|
#print(str(lot[0]))
|
|
longboifile(lot[1])
|
|
print(str(lot[1]))
|
|
clippy(str(lot[1]))
|
|
def log():
|
|
maxleggy = len(arrg)
|
|
point1 = arrg[maxleggy-1]
|
|
point2 = arrg[maxleggy-2]
|
|
point3 = arrg[0]
|
|
point4 = arrg[1]
|
|
parse = arrg.strip(point1+point2+point3+point4)
|
|
print(parse)
|
|
longboifile(parse)
|
|
clippy(parse)
|
|
def lep():
|
|
maxleggy = len(arrg)
|
|
point1 = arrg[maxleggy-1]
|
|
point2 = arrg[maxleggy-2]
|
|
parse = arrg.strip(arrg[0])
|
|
parses = arrg.strip("+H435")
|
|
fparse = parses.strip(point1+point2)
|
|
print(fparse)
|
|
longboifile(fparse)
|
|
clippy(fparse)
|
|
def longcode(code):
|
|
lenth = len(code)
|
|
print(code[26:lenth])
|
|
clippy(code[26:lenth])
|
|
keyboard.add_hotkey(hotkey="h+f", callback=clippyB, args=["211698"])
|
|
keyboard.add_hotkey(hotkey="t+g", callback=clippyB, args=["263611"])
|
|
keyboard.add_hotkey(hotkey="ctrl+m+e", callback=clippyB, args=["230302"])
|
|
keyboard.add_hotkey(hotkey="u+e", callback=clippyB, args=["259047"])
|
|
keyboard.add_hotkey(hotkey="r+n", callback=clippyB, args=["228606"])
|
|
keyboard.add_hotkey(hotkey="f+d", callback=clippyB, args=["486513284"])
|
|
keyboard.add_hotkey(hotkey="a+d", callback=clippyB, args=["46985 ENTERPRISE CT\nSTE A-100\nWIXOM MI, 48393"])
|
|
while True:
|
|
event, values = window.read()
|
|
if event == "Exit" or event == sg.WIN_CLOSED:
|
|
break
|
|
if event == "-GO-":
|
|
arrrg = values["-mkbox-"]
|
|
Bark()
|
|
clippy(arrrg)
|
|
longboifile(arrrg)
|
|
if event == "noop":
|
|
arrg = values["pull"]
|
|
if "" == arrg:
|
|
pass
|
|
elif "line" in arrg:
|
|
print("==========NEW=LINE=======================")
|
|
elif "yank" in arrg or "Yank" in arrg:
|
|
readpicture()
|
|
elif "+H435" in arrg:
|
|
lep()
|
|
elif "010" in arrg[0:3]:
|
|
longcode(arrg)
|
|
elif "|" in arrg:
|
|
arrg = values["pull"]
|
|
newt()
|
|
longboifile(arrg)
|
|
else:
|
|
log()
|
|
element = window["pull"]
|
|
element.update("")
|
|
window.close() |