Feature: Enhanced Editing, Hex Inspector, Color Shortcuts

- Enhanced Editing: Auto-create packets, Enter key support.
- Cursor: Fixed visibility (composition mode), click-to-move, immediate redraw.
- Hex Inspector: Added Hex Value display and input panel.
- Shortcuts: Added Color Insert buttons.
- Fixes: Resolved Hamming encoding for save, fixed duplicate spaces bug, fixed IndentationError.
This commit is contained in:
2025-12-28 21:57:44 +01:00
parent e2ed4dd1e2
commit 088ad1a320
6 changed files with 265 additions and 20 deletions

View File

@@ -1,7 +1,10 @@
import os
from PyQt6.QtWidgets import (QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QListWidget, QListWidgetItem, QComboBox, QLabel, QFileDialog, QMenuBar, QMenu, QMessageBox)
QListWidget, QListWidgetItem, QComboBox, QLabel, QLineEdit, QPushButton, QFileDialog, QMenuBar, QMenu, QMessageBox)
# ... (imports remain)
# ... (imports remain)
from PyQt6.QtGui import QAction, QKeyEvent
from PyQt6.QtCore import Qt
@@ -34,6 +37,19 @@ class MainWindow(QMainWindow):
self.page_list.itemClicked.connect(self.on_page_selected)
left_layout.addWidget(self.page_list)
# Hex Inspector
hex_layout = QVBoxLayout()
hex_label = QLabel("Hex Value:")
self.hex_input = QLineEdit()
self.hex_input.setMaxLength(2)
self.hex_input.setPlaceholderText("00")
self.hex_input.returnPressed.connect(self.on_hex_entered)
hex_layout.addWidget(hex_label)
hex_layout.addWidget(self.hex_input)
left_layout.addLayout(hex_layout)
left_layout.addStretch()
self.layout.addLayout(left_layout)
# Center Area Layout (Top Bar + Canvas)
@@ -51,8 +67,30 @@ class MainWindow(QMainWindow):
center_layout.addLayout(top_bar)
# Color Shortcuts
color_layout = QHBoxLayout()
colors = [
("Red", 0x01, "#FF0000"),
("Green", 0x02, "#00FF00"),
("Yellow", 0x03, "#FFFF00"),
("Blue", 0x04, "#0000FF"),
("Magenta", 0x05, "#FF00FF"),
("Cyan", 0x06, "#00FFFF"),
("White", 0x07, "#FFFFFF"),
]
for name, code, hex_color in colors:
btn = QPushButton(name)
btn.setStyleSheet(f"background-color: {hex_color}; font-weight: bold; color: black;")
btn.clicked.connect(lambda checked, c=code: self.insert_char(c))
color_layout.addWidget(btn)
color_layout.addStretch()
center_layout.addLayout(color_layout)
# Canvas
self.canvas = TeletextCanvas()
self.canvas.cursorChanged.connect(self.on_cursor_changed)
center_layout.addWidget(self.canvas, 1) # Expand
self.layout.addLayout(center_layout, 1)
@@ -164,6 +202,28 @@ class MainWindow(QMainWindow):
self.current_page = page
self.canvas.set_page(page)
self.canvas.setFocus()
def insert_char(self, char_code):
self.canvas.set_byte_at_cursor(char_code)
# Advance cursor
self.canvas.move_cursor(1, 0)
self.canvas.setFocus()
def on_cursor_changed(self, x, y, val):
self.hex_input.setText(f"{val:02X}")
def on_hex_entered(self):
text = self.hex_input.text()
try:
val = int(text, 16)
if 0 <= val <= 255:
# Update canvas input
# We can call handle_input with char, OR set byte directly.
# Direct byte set is safer for non-printable.
self.canvas.set_byte_at_cursor(val)
self.canvas.setFocus() # Return focus to canvas
except ValueError:
pass # Ignore invalid hex
# Input Handling (Editor Logic)
def keyPressEvent(self, event: QKeyEvent):
@@ -182,6 +242,10 @@ class MainWindow(QMainWindow):
self.canvas.move_cursor(-1, 0)
elif key == Qt.Key.Key_Right:
self.canvas.move_cursor(1, 0)
elif key == Qt.Key.Key_Return or key == Qt.Key.Key_Enter:
# Move to start of next line
self.canvas.cursor_x = 0
self.canvas.move_cursor(0, 1)
else:
# Typing
# Filter non-printable