From 670a2d9f8c0703d2f93527ebe370a6cf288e5359 Mon Sep 17 00:00:00 2001 From: Daniel Dybing Date: Fri, 23 Jan 2026 21:29:16 +0100 Subject: [PATCH] ui: move graphics and color controls to right sidebar --- src/teletext/ui.py | 67 ++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/teletext/ui.py b/src/teletext/ui.py index 7147280..de3e57f 100644 --- a/src/teletext/ui.py +++ b/src/teletext/ui.py @@ -183,14 +183,31 @@ class MainWindow(QMainWindow): center_layout.addLayout(top_bar) - # Color Shortcuts - color_layout = QHBoxLayout() + # Middle Layout (Canvas + Right Sidebar) + middle_layout = QHBoxLayout() + center_layout.addLayout(middle_layout, 1) + # Canvas + self.canvas = TeletextCanvas() + self.canvas.cursorChanged.connect(self.on_cursor_changed) + middle_layout.addWidget(self.canvas, 1) # Expand + + # Right Sidebar + right_sidebar = QWidget() + right_sidebar.setFixedWidth(160) + right_layout = QVBoxLayout(right_sidebar) + right_layout.setContentsMargins(5, 0, 0, 0) + middle_layout.addWidget(right_sidebar) + + # Color Shortcuts # Graphics Mode Toggle self.chk_graphics = QCheckBox("Graphics") self.chk_graphics.setToolTip("If checked, inserts Graphics Color codes (e.g. Red Graphics 0x11) instead of Alpha (0x01)") - color_layout.addWidget(self.chk_graphics) + right_layout.addWidget(self.chk_graphics) + colors_grid = QGridLayout() + colors_grid.setSpacing(5) + colors = [ ("Black", 0x00, "#000000"), ("Red", 0x01, "#FF0000"), @@ -202,9 +219,10 @@ class MainWindow(QMainWindow): ("White", 0x07, "#FFFFFF"), ] + row, col = 0, 0 for name, code, hex_color in colors: btn = QPushButton(name) - btn.setFixedSize(60, 30) # Fixed size for uniformity + btn.setFixedSize(60, 30) # Common style style = f"background-color: {hex_color}; font-weight: bold; border: 1px solid #555; border-radius: 3px;" @@ -220,20 +238,25 @@ class MainWindow(QMainWindow): # Use separate method to handle graphics check btn.clicked.connect(lambda checked, c=code: self.insert_color(c)) - color_layout.addWidget(btn) + colors_grid.addWidget(btn, row, col) + + col += 1 + if col > 1: + col = 0 + row += 1 + + right_layout.addLayout(colors_grid) # Mosaics Button btn_mosaic = QPushButton("Mosaics...") btn_mosaic.clicked.connect(self.open_mosaic_dialog) - color_layout.addWidget(btn_mosaic) - - color_layout.addStretch() - center_layout.addLayout(color_layout) + right_layout.addWidget(btn_mosaic) + + right_layout.addSpacing(10) # Background Controls - bg_layout = QHBoxLayout() bg_label = QLabel("Background:") - bg_layout.addWidget(bg_label) + right_layout.addWidget(bg_label) # New Background (0x1D) btn_new_bg = QPushButton("New BG") @@ -241,7 +264,7 @@ class MainWindow(QMainWindow): btn_new_bg.setStyleSheet("background-color: #CCCCCC; color: black; font-weight: bold; border: 1px solid #555; border-radius: 3px;") btn_new_bg.setToolTip("Sets the current foreground color as the new background color (0x1D)") btn_new_bg.clicked.connect(lambda: self.insert_char(0x1D)) - bg_layout.addWidget(btn_new_bg) + right_layout.addWidget(btn_new_bg) # Black Background (0x1C) btn_black_bg = QPushButton("Black BG") @@ -249,15 +272,13 @@ class MainWindow(QMainWindow): btn_black_bg.setStyleSheet("background-color: black; color: white; font-weight: bold; border: 1px solid #555; border-radius: 3px;") btn_black_bg.setToolTip("Resets the background color to Black (0x1C)") btn_black_bg.clicked.connect(lambda: self.insert_char(0x1C)) - bg_layout.addWidget(btn_black_bg) + right_layout.addWidget(btn_black_bg) - bg_layout.addStretch() - center_layout.addLayout(bg_layout) + right_layout.addSpacing(10) # Graphics Control - gfx_ctrl_layout = QHBoxLayout() gfx_ctrl_label = QLabel("Graphics Control:") - gfx_ctrl_layout.addWidget(gfx_ctrl_label) + right_layout.addWidget(gfx_ctrl_label) # Hold Graphics (0x1E) btn_hold = QPushButton("Hold Gfx") @@ -265,7 +286,7 @@ class MainWindow(QMainWindow): btn_hold.setStyleSheet("background-color: #CCCCCC; color: black; font-weight: bold; border: 1px solid #555; border-radius: 3px;") btn_hold.setToolTip("Hold Graphics (0x1E): Displays the last graphic char in place of subsequent control codes.") btn_hold.clicked.connect(lambda: self.insert_char(0x1E)) - gfx_ctrl_layout.addWidget(btn_hold) + right_layout.addWidget(btn_hold) # Release Graphics (0x1F) btn_release = QPushButton("Release Gfx") @@ -273,15 +294,9 @@ class MainWindow(QMainWindow): btn_release.setStyleSheet("background-color: #CCCCCC; color: black; font-weight: bold; border: 1px solid #555; border-radius: 3px;") btn_release.setToolTip("Release Graphics (0x1F): Ends the 'Hold Graphics' effect.") btn_release.clicked.connect(lambda: self.insert_char(0x1F)) - gfx_ctrl_layout.addWidget(btn_release) + right_layout.addWidget(btn_release) - gfx_ctrl_layout.addStretch() - center_layout.addLayout(gfx_ctrl_layout) - - # Canvas - self.canvas = TeletextCanvas() - self.canvas.cursorChanged.connect(self.on_cursor_changed) - center_layout.addWidget(self.canvas, 1) # Expand + right_layout.addStretch() self.layout.addLayout(center_layout, 1)