-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoast.py
50 lines (40 loc) · 2.06 KB
/
toast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from win11toast import toast
from PIL import Image, ImageTk
import pyperclip
def show_clipboard_notification_windows(cropped_image, extracted_text):
"""Shows a toast notification with an option to open the text editor."""
def handle_click(event):
action = event.get('arguments', 'http:')[5:] #ignore 'http:' prefix; workaround for win11toast
if action == '1':
text_file = "extracted_text.txt"
os.startfile(text_file)
elif action == '2':
image_file = "screenshot.png"
cropped_image.save(image_file)
os.startfile(image_file)
buttons = [
{'activationType': 'protocol', 'arguments': 'http:1', 'content': 'Open Text Editor'},
{'activationType': 'protocol', 'arguments': 'http:2', 'content': 'View Image'}
]
toast('Text copied to clipboard', extracted_text, on_click=handle_click, buttons=buttons)
def show_notification_windows(cropped_image, extracted_text):
"""Shows a toast notification with an option to open the text editor."""
def handle_click(event):
action = event.get('arguments', 'http:')[5:] #ignore 'http:' prefix; workaround for win11toast
if action == '1':
text_file = "extracted_text.txt"
os.startfile(text_file)
elif action == '2':
image_file = "screenshot.png"
cropped_image.save(image_file)
os.startfile(image_file)
elif action == '3':
pyperclip.copy(extracted_text)
print("Text copied to clipboard.")
buttons = [
{'activationType': 'protocol', 'arguments': 'http:1', 'content': 'Open Text Editor'},
{'activationType': 'protocol', 'arguments': 'http:2', 'content': 'View Image'},
{'activationType': 'protocol', 'arguments': 'http:3', 'content': 'Copy to Clipboard'}
]
toast('Text copied to clipboard', extracted_text, on_click=handle_click, buttons=buttons)