Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI tuning for OCR #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions llama_assistant/llama_assistant_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
QVBoxLayout,
QMessageBox,
QSystemTrayIcon,
QRubberBand,
)
from PyQt5.QtCore import Qt, QPoint, QTimer, QSize, QRect
from PyQt5.QtCore import Qt, QTimer, QRect
from PyQt5.QtGui import (
QPixmap,
QPainter,
QDragEnterEvent,
QDropEvent,
QBitmap,
QTextCursor,
QFont,
QMouseEvent,
)

from llama_assistant import config
Expand Down Expand Up @@ -64,6 +63,24 @@ def __init__(self):
self.gen_mark_down = True
self.has_ocr_context = False

# Add drag-drop move support
self.setWindowFlags(Qt.FramelessWindowHint)
self.oldPos = None

def mousePressEvent(self, event: QMouseEvent):
if event.button() == Qt.LeftButton:
self.oldPos = event.globalPos()

def mouseMoveEvent(self, event: QMouseEvent):
if self.oldPos is not None:
delta = event.globalPos() - self.oldPos
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()

def mouseReleaseEvent(self, event: QMouseEvent):
if event.button() == Qt.LeftButton:
self.oldPos = None

def capture_screenshot(self):
self.hide()
self.screen_capture_widget.show()
Expand Down Expand Up @@ -219,6 +236,10 @@ def on_ask_with_ocr_context(self):
self.show()
self.screen_capture_widget.hide()
self.has_ocr_context = True
# Show the screenshot as reference image
if config.ocr_tmp_file.exists():
self.dropped_image = str(config.ocr_tmp_file)
self.show_image_thumbnail(self.dropped_image)

def on_submit(self):
message = self.ui_manager.input_field.toPlainText()
Expand All @@ -230,6 +251,7 @@ def on_submit(self):
self.clear_chat()
self.remove_image_thumbnail()
self.dropped_image = None
self.has_ocr_context = False

for file_path in self.dropped_files:
self.remove_file_thumbnail(self.file_containers[file_path], file_path)
Expand All @@ -239,7 +261,7 @@ def on_submit(self):
self.last_response = ""
self.gen_mark_down = True

if self.dropped_image:
if self.dropped_image and not self.has_ocr_context:
self.process_image_with_prompt(self.dropped_image, self.dropped_files, message)
self.dropped_image = None
self.remove_image_thumbnail()
Expand Down Expand Up @@ -560,6 +582,7 @@ def remove_image_thumbnail(self):
self.image_label.setParent(None)
self.image_label = None
self.dropped_image = None
self.has_ocr_context = False
self.ui_manager.input_field.setPlaceholderText("Ask me anything...")
self.setFixedHeight(self.height() - 110) # Decrease height after removing image

Expand Down
Loading