update csv export and added fixed mesh axis drawing

This commit is contained in:
ykcheungab
2026-07-15 14:25:03 +08:00
parent 3d1509df9d
commit 87ac152907
11 changed files with 578 additions and 35 deletions
+30 -21
View File
@@ -22,12 +22,13 @@ class TeeStream:
class WidgetLogHandler:
"""Mirror print output into a QPlainTextEdit with a live status line at the bottom."""
"""Mirror print output into a QPlainTextEdit with pinned status lines at the bottom."""
def __init__(self, widget: QPlainTextEdit):
self.widget = widget
self.buf = ""
self._has_status_line = False
self._status_text: str | None = None
self._status_block_count = 0
def write(self, text: str):
self.buf += text
@@ -42,34 +43,42 @@ class WidgetLogHandler:
self.buf = ""
def set_status_line(self, text: str) -> None:
"""Update the pinned bottom line (FPS / forces) without scrolling the log."""
"""Update pinned bottom status (supports multi-line) without scrolling away."""
text = text.rstrip("\n")
if self._has_status_line:
cursor = QTextCursor(self.widget.document().lastBlock())
cursor.select(QTextCursor.BlockUnderCursor)
cursor.insertText(text)
else:
self.widget.appendPlainText(text)
self._has_status_line = True
self._remove_status_blocks()
self.widget.appendPlainText(text)
self._status_text = text
self._status_block_count = max(1, text.count("\n") + 1)
scrollbar = self.widget.verticalScrollBar()
scrollbar.setValue(scrollbar.maximum())
def clear_status_line(self) -> None:
if not self._has_status_line:
self._remove_status_blocks()
self._status_text = None
self._status_block_count = 0
def _remove_status_blocks(self) -> None:
if self._status_block_count <= 0:
return
cursor = QTextCursor(self.widget.document().lastBlock())
cursor.select(QTextCursor.BlockUnderCursor)
doc = self.widget.document()
end = QTextCursor(doc)
end.movePosition(QTextCursor.End)
start = QTextCursor(doc)
start.movePosition(QTextCursor.End)
for _ in range(self._status_block_count):
start.movePosition(QTextCursor.StartOfBlock)
if start.position() > 0:
start.movePosition(QTextCursor.Left)
cursor = QTextCursor(doc)
cursor.setPosition(start.position())
cursor.setPosition(end.position(), QTextCursor.KeepAnchor)
cursor.removeSelectedText()
self._has_status_line = False
self._status_block_count = 0
def _append_log_line(self, line: str) -> None:
status = None
if self._has_status_line:
status = self.widget.document().lastBlock().text()
cursor = QTextCursor(self.widget.document().lastBlock())
cursor.select(QTextCursor.BlockUnderCursor)
cursor.removeSelectedText()
self._has_status_line = False
status = self._status_text
if status is not None:
self.clear_status_line()
self.widget.appendPlainText(line)
if status is not None:
self.set_status_line(status)