-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (61 loc) · 2.37 KB
/
main.py
File metadata and controls
76 lines (61 loc) · 2.37 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import tkinter as tk
from tkinter import filedialog, messagebox
import ui
import ocr_engine
import text_processor
import os
def main():
root = tk.Tk()
# Components
processor = text_processor.TextProcessor()
# Callback when OCR gets text
def on_ocr_result(raw_text):
final_text = processor.process_text(raw_text)
if final_text:
# Update UI on main thread
root.after(0, app_ui.append_text, final_text)
# Callback to get capture region
def get_capture_region():
# If focus box is hidden, maybe capture full screen?
# For now, let's enforce using the box or default to full main screen if hidden?
# PRD says "Focus Box". If hidden, maybe we shouldn't capture.
# But for UX, if hidden, we could assume "Select a region"
# Let's rely on the module logic: if hidden/small, it skips.
# But we need to make sure the user knows to open it.
return app_ui.get_focus_geometry()
# Callbacks for UI buttons
def start_capture():
# Check if focus box is visible?
# If not, maybe show warning or auto-show it.
# For now, just start.
if app_ui.focus_box.state() == 'withdrawn':
app_ui.toggle_focus()
ocr.start()
def stop_capture():
ocr.stop()
processor.reset() # Optional: reset deduplication state on stop?
def save_content(text):
if not text.strip():
messagebox.showinfo("Info", "Nothing to save.")
return
file_path = filedialog.asksaveasfilename(
defaultextension=".txt",
filetypes=[("Text files", "*.txt"), ("Markdown", "*.md"), ("All files", "*.*")]
)
if file_path:
try:
with open(file_path, "w", encoding="utf-8") as f:
f.write(text)
messagebox.showinfo("Success", f"Saved to {file_path}")
except Exception as e:
messagebox.showerror("Error", f"Failed to save: {e}")
app_ui = ui.VisionTextUI(root, start_capture, stop_capture, save_content)
ocr = ocr_engine.OCREngine(on_ocr_result, get_capture_region)
# Handle close
def on_closing():
ocr.stop()
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()
if __name__ == "__main__":
main()