diff --git a/CHANGELOG.md b/CHANGELOG.md index a4600d0..ebe2782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog # +## Version 3.3.0 ## + +🛠️ Bug fixes: + +* Tests only: `qthelpers.close_widgets_and_quit` now ignores deleted widgets + +💥 Changes: + +* `dataset.ImageChoiceItem` and `dataset.ButtonItem`: added `size` argument to set the icon size + ## Version 3.2.0 ## 🛠️ Bug fixes: diff --git a/guidata/__init__.py b/guidata/__init__.py index 966282f..8fdea8e 100644 --- a/guidata/__init__.py +++ b/guidata/__init__.py @@ -8,7 +8,7 @@ and application development tools for Qt. """ -__version__ = "3.2.0" +__version__ = "3.3.0" # Dear (Debian, RPM, ...) package makers, please feel free to customize the diff --git a/guidata/dataset/dataitems.py b/guidata/dataset/dataitems.py index 886d077..3552372 100644 --- a/guidata/dataset/dataitems.py +++ b/guidata/dataset/dataitems.py @@ -737,6 +737,7 @@ class ChoiceItem(DataItem): check: if False, value is not checked (optional, default=True) radio: if True, shows radio buttons instead of a combo box (default is False) + size: size (optional) of the combo box or button widget (for radio buttons) """ def __init__( @@ -747,6 +748,7 @@ def __init__( help: str = "", check: bool = True, radio: bool = False, + size: tuple[int, int] | None = None, ) -> None: _choices_data: Any if isinstance(choices, Callable): @@ -762,6 +764,7 @@ def __init__( super().__init__(label, default=default, help=help, check=check) self.set_prop("data", choices=_choices_data) self.set_prop("display", radio=radio) + self.set_prop("display", size=size) def _normalize_choice( self, idx: int, choice_tuple: tuple[Any, ...] @@ -1011,6 +1014,7 @@ class ButtonItem(DataItem): default: default value passed to the callback (optional) help: text shown in button's tooltip (optional) check: if False, value is not checked (optional, default=True) + size: size (optional) of the button widget The value of this item is unspecified but is passed to the callback along with the whole dataset. The value is assigned the callback`s return value. @@ -1024,10 +1028,12 @@ def __init__( default: Any | None = None, help: str = "", check: bool = True, + size: tuple[int, int] | None = None, ) -> None: super().__init__(label, default=default, help=help, check=check) self.set_prop("display", callback=callback) self.set_prop("display", icon=icon) + self.set_prop("display", size=size) def serialize( self, diff --git a/guidata/dataset/qtitemwidgets.py b/guidata/dataset/qtitemwidgets.py index a75597d..3aa4836 100644 --- a/guidata/dataset/qtitemwidgets.py +++ b/guidata/dataset/qtitemwidgets.py @@ -27,7 +27,7 @@ import numpy from qtpy.compat import getexistingdirectory -from qtpy.QtCore import Qt +from qtpy.QtCore import QSize, Qt from qtpy.QtGui import QColor, QIcon, QPixmap from qtpy.QtWidgets import ( QAbstractButton, @@ -899,6 +899,7 @@ def __init__( super().__init__(item, parent_layout) self._first_call = True self.is_radio = item.get_prop_value("display", "radio") + self.image_size = item.get_prop_value("display", "size", None) self.store = self.item.get_prop("display", "store", None) if self.is_radio: self.group = QGroupBox() @@ -908,6 +909,9 @@ def __init__( self._buttons: list[QAbstractButton] = [] else: self.combobox = self.group = QComboBox() + if self.image_size is not None: + width, height = self.image_size + self.combobox.setIconSize(QSize(width, height)) self.combobox.setToolTip(item.get_help()) self.combobox.currentIndexChanged.connect(self.index_changed) # type:ignore @@ -933,6 +937,9 @@ def initialize_widget(self) -> None: for key, lbl, img in _choices: if self.is_radio: button = QRadioButton(lbl, self.group) + if self.image_size is not None: + width, height = self.image_size + button.setIconSize(QSize(width, height)) if img: if isinstance(img, str): if not osp.isfile(img): @@ -1228,6 +1235,10 @@ def __init__( _label = self.item.get_prop_value("display", "label") self.button = self.group = QPushButton(_label) self.button.setToolTip(item.get_help()) + image_size = item.get_prop_value("display", "size", None) + if image_size is not None: + width, height = image_size + self.button.setIconSize(QSize(width, height)) _icon = self.item.get_prop_value("display", "icon") if _icon is not None: if isinstance(_icon, str): diff --git a/guidata/tests/dataset/test_all_features.py b/guidata/tests/dataset/test_all_features.py index 117c2ed..f6671d9 100644 --- a/guidata/tests/dataset/test_all_features.py +++ b/guidata/tests/dataset/test_all_features.py @@ -104,11 +104,12 @@ class Parameters(gds.DataSet): [ ("rect", "first choice", "gif.png"), ("ell", "second choice", "txt.png"), - ("qcq", "third choice", "file.png"), + ("qcq", "third choice", "html.png"), ], ) .set_pos(col=1) .set_prop("display", icon="file.png") + .set_prop("display", size=(32, 32)) ) mchoice3 = gds.MultipleChoiceItem( "MC type 3", [str(i) for i in range(10)]