diff --git a/core/functions/result_handler.py b/core/functions/result_handler.py index 4d98b53..a84b6ec 100644 --- a/core/functions/result_handler.py +++ b/core/functions/result_handler.py @@ -3,8 +3,18 @@ import json import csv import os import time +import dataclasses from typing import Any, Dict, List + +class _InferenceResultEncoder(json.JSONEncoder): + """將 dataclass 推論結果物件轉為可序列化的 dict。""" + def default(self, o): + if dataclasses.is_dataclass(o) and not isinstance(o, type): + return dataclasses.asdict(o) + return super().default(o) + + class ResultSerializer: """ Serializes inference results into various formats. @@ -12,8 +22,10 @@ class ResultSerializer: def to_json(self, data: Dict[str, Any]) -> str: """ Serializes data to a JSON string. + Dataclass objects (ObjectDetectionResult, ClassificationResult, etc.) + are automatically converted to dicts via _InferenceResultEncoder. """ - return json.dumps(data, indent=2) + return json.dumps(data, indent=2, cls=_InferenceResultEncoder) def to_csv(self, data: List[Dict[str, Any]], fieldnames: List[str]) -> str: """ diff --git a/main.py b/main.py index 623238c..4615529 100644 --- a/main.py +++ b/main.py @@ -233,10 +233,10 @@ class SingleInstance: def setup_application(): """Initialize and configure the QApplication.""" - # Enable high DPI support BEFORE creating QApplication - QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) - QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) - + # High DPI attributes must be set before QApplication is created. + # They are set in main() before the first QApplication instantiation. + # Do NOT set them here — QApplication already exists at this point. + # Create QApplication if it doesn't exist if not QApplication.instance(): app = QApplication(sys.argv) diff --git a/ui/dialogs/deployment.py b/ui/dialogs/deployment.py index efd3544..13cd1f9 100644 --- a/ui/dialogs/deployment.py +++ b/ui/dialogs/deployment.py @@ -1163,22 +1163,22 @@ Stage Configurations: def update_terminal_output(self, terminal_text: str): """Update the terminal output display with new text.""" try: - # Use append() instead of setPlainText() for better performance and no truncation self.terminal_output_display.append(terminal_text.rstrip('\n')) - + # Auto-scroll to bottom scrollbar = self.terminal_output_display.verticalScrollBar() scrollbar.setValue(scrollbar.maximum()) - - # Optional: Limit total lines to prevent excessive memory usage - # Only trim if we have way too many lines (e.g., > 1000) + + # Limit total lines to prevent excessive memory usage. + # Use toPlainText/setPlainText to avoid QTextCursor cross-thread warnings. document = self.terminal_output_display.document() if document.lineCount() > 1000: - cursor = self.terminal_output_display.textCursor() - cursor.movePosition(cursor.Start) - cursor.movePosition(cursor.Down, cursor.KeepAnchor, 200) # Select first 200 lines - cursor.removeSelectedText() - + lines = self.terminal_output_display.toPlainText().split('\n') + trimmed = '\n'.join(lines[-800:]) # Keep last 800 lines + self.terminal_output_display.setPlainText(trimmed) + # Restore scroll to bottom after setPlainText resets it + scrollbar.setValue(scrollbar.maximum()) + except Exception as e: print(f"Error updating terminal output: {e}")