diff --git a/angrmanagement/ui/dialogs/preferences.py b/angrmanagement/ui/dialogs/preferences.py index 24e4ef94e..b8593b8d7 100644 --- a/angrmanagement/ui/dialogs/preferences.py +++ b/angrmanagement/ui/dialogs/preferences.py @@ -1,5 +1,6 @@ import enum from datetime import datetime +from itertools import chain from bidict import bidict from PySide6.QtGui import QColor @@ -10,6 +11,7 @@ QDialog, QDialogButtonBox, QFrame, + QGridLayout, QGroupBox, QHBoxLayout, QLabel, @@ -32,6 +34,7 @@ from angrmanagement.ui.css import refresh_theme from angrmanagement.ui.widgets.qcolor_option import QColorOption from angrmanagement.ui.widgets.qfont_option import QFontOption +from angrmanagement.utils.layout import add_to_grid class Page(QWidget): @@ -223,17 +226,19 @@ def _init_widgets(self): page_layout.addLayout(log_format_layout) # Font options - self._font_options = [ - QFontOption("Application Font", "ui_default_font", self), - QFontOption("Tab View Font", "tabular_view_font", self), - QFontOption("Disassembly Font", "disasm_font", self), - QFontOption("SymExc Font", "symexec_font", self), - QFontOption("Code Font", "code_font", self), + fonts_group_box = QGroupBox("Fonts") + fonts_layout = QGridLayout() + fonts_group_box.setLayout(fonts_layout) + page_layout.addWidget(fonts_group_box) + entries = [ + ("Application Font", "ui_default_font"), + ("Tabular View Font", "tabular_view_font"), + ("Disassembly Font", "disasm_font"), + ("SymExc Font", "symexec_font"), + ("Code Font", "code_font"), ] - font_layout = QVBoxLayout() - for i in self._font_options: - font_layout.addWidget(i) - page_layout.addLayout(font_layout) + self._fonts_widgets = [(QLabel(f"{name}:"), QFontOption(key, self)) for name, key in entries] + add_to_grid(fonts_layout, 2, chain(*self._fonts_widgets)) page_layout.addStretch() @@ -241,8 +246,8 @@ def save_config(self): fmt = self.log_format_entry.currentText() if fmt: Conf.log_timestamp_format = self._fmt_map.get(fmt, fmt) - for i in self._font_options: - i.update() + for _, font_picker in self._fonts_widgets: + font_picker.update() class Preferences(QDialog): diff --git a/angrmanagement/ui/widgets/qfont_option.py b/angrmanagement/ui/widgets/qfont_option.py index 3166493c3..b99901f41 100644 --- a/angrmanagement/ui/widgets/qfont_option.py +++ b/angrmanagement/ui/widgets/qfont_option.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING -from PySide6.QtWidgets import QFontDialog, QHBoxLayout, QLabel, QPushButton, QWidget +from PySide6.QtWidgets import QFontDialog, QPushButton from angrmanagement.config import Conf @@ -8,45 +8,34 @@ from PySide6.QtGui import QFont -class QFontOption(QWidget): +class QFontOption(QPushButton): """ A widget used to allow users to change a font stored in Conf """ - def __init__(self, name: str, key: str, parent=None): + def __init__(self, config_key: str, parent=None): """ - :param name: The name of the font - :param key: The key of the font in Conf - :parent: The optional parent of this QWidget + :param key: Key of the font in Conf + :parent: Optional parent of this QWidget """ super().__init__(parent) - self.name: str = name - self._key = key - self.font: QFont = getattr(Conf, key) - layout = QHBoxLayout(self) - # Label - self.label = QLabel(parent=self) - layout.addWidget(self.label) - # Button - self.button = QPushButton("Change", parent=self) - self.button.released.connect(self._prompt) - layout.addWidget(self.button) - # Finish - self.setLayout(layout) + self._config_key = config_key + self.font: QFont = getattr(Conf, config_key) + self.released.connect(self._prompt) self._format() def update(self): """ Update Conf with the selected font """ - setattr(Conf, self._key, self.font) + setattr(Conf, self._config_key, self.font) def _format(self): """ Format the widget's UI elements """ - self.label.setText(f"{self.name}: {self.font.family()}") - self.label.setFont(self.font) # We do not ._sync.keep_synced this; it should update always + self.setText(f"{self.font.family()}, {self.font.pointSize()} pt") + self.setFont(self.font) # We do not ._sync.keep_synced this; it should update always def _prompt(self): """