32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
import tkinter as tk
|
|
import time
|
|
from . import data
|
|
from src import sendkeys
|
|
|
|
|
|
def clipboard_poll(app: tk) -> None:
|
|
data.log.debug('clipboard thread started')
|
|
text = None # Last clipboard entry
|
|
old_trade = None # This is the last trade, not the last clipboard entry
|
|
while True:
|
|
try:
|
|
new_text = app.clipboard_get()
|
|
except tk.TclError:
|
|
new_text = None
|
|
if text and new_text != text:
|
|
data.log.info(new_text)
|
|
text = new_text
|
|
res_prefix = data.re_clipboard_prefix.search(text)
|
|
if res_prefix:
|
|
data.log.info(f'User: {res_prefix["user"]}')
|
|
res = data.re_clipboard.search(text)
|
|
if old_trade != text: # Don't send old trade again. Happnes sometimes if clipboard is used by other tools and restored
|
|
sendkeys.send_text(text)
|
|
old_trade = text
|
|
else:
|
|
data.log.info(f'Didn\'t send. Clipboard "{text}" already sent.')
|
|
if res:
|
|
trade = data.Trade.by_regex_result(res)
|
|
data.log.info(trade)
|
|
time.sleep(0.2)
|