From d530575c4fcc044d3ccc9d0ae81f6e0f7381025a Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 15 Dec 2023 13:21:10 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Thomas VINCENT --- src/silx/gui/widgets/FloatEdit.py | 12 ++--- src/silx/gui/widgets/test/test_floatedit.py | 53 ++++++++++----------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/silx/gui/widgets/FloatEdit.py b/src/silx/gui/widgets/FloatEdit.py index 0ccb0673e1..f9d7331f81 100644 --- a/src/silx/gui/widgets/FloatEdit.py +++ b/src/silx/gui/widgets/FloatEdit.py @@ -39,9 +39,8 @@ class FloatEdit(qt.QLineEdit): The value can be modified with :meth:`value` and :meth:`setValue`. The property :meth:`widgetResizable` allow to change the default - behaviour in order to automatically resize the widhet to avoid - to scroll to see the whole value. You still can enforce your own - minimum width with :meth:`setMinimumWidth`. + behaviour in order to automatically resize the widget to the displayed value. + Use :meth:`setMinimumWidth` to enforce the minimum width. :param parent: Parent of the widget :param value: The value to set the QLineEdit to. @@ -93,14 +92,15 @@ def __textChanged(self, text: str): def widgetResizable(self) -> bool: """ - Returns wether the widget auto resize itself based on it's content + Returns whether or not the widget auto resizes itself based on it's content """ return self.__widgetResizable def setWidgetResizable(self, resizable: bool): """ - If true, the widget will automatically resize itself in order to avoid - to scroll to see it's content where they can be avoided, or to take + If true, the widget will automatically resize itself to its displayed content. + + This avoids to have to scroll to see the widget's content, and allow to take advantage of extra space. """ if self.__widgetResizable == resizable: diff --git a/src/silx/gui/widgets/test/test_floatedit.py b/src/silx/gui/widgets/test/test_floatedit.py index b78658a842..57a652242b 100644 --- a/src/silx/gui/widgets/test/test_floatedit.py +++ b/src/silx/gui/widgets/test/test_floatedit.py @@ -26,36 +26,28 @@ __license__ = "MIT" import pytest -import weakref from silx.gui import qt from silx.gui.widgets.FloatEdit import FloatEdit @pytest.fixture -def floatEdit(qapp, qapp_utils): - widget = FloatEdit() - widget.setAttribute(qt.Qt.WA_DeleteOnClose) - yield widget - widget.close() - ref = weakref.ref(widget) - widget = None - qapp_utils.qWaitForDestroy(ref) +def floatEdit(qWidgetFactory): + proxy = qWidgetFactory(FloatEdit) + yield proxy @pytest.fixture -def holder(qapp, qapp_utils): - widget = qt.QWidget() - qt.QHBoxLayout(widget) - widget.setAttribute(qt.Qt.WA_DeleteOnClose) - yield widget - widget.close() - ref = weakref.ref(widget) - widget = None - qapp_utils.qWaitForDestroy(ref) +def floatEditHolder(qapp, qapp_utils, qWidgetFactory, floatEdit): + proxy = qWidgetFactory(qt.QWidget) + holder = proxy.__repr__.__self__ + layout = qt.QHBoxLayout(holder) + layout.addStretch() + layout.addWidget(floatEdit.__repr__.__self__) + yield proxy def test_show(qapp_utils, floatEdit): - qapp_utils.qWaitForWindowExposed(floatEdit) + pass def test_value(floatEdit): @@ -63,11 +55,8 @@ def test_value(floatEdit): assert floatEdit.value() == 1.5 -def test_no_widgetresize(qapp_utils, holder, floatEdit): - holder.layout().addWidget(floatEdit) - holder.resize(100, 100) - holder.show() - qapp_utils.qWaitForWindowExposed(holder) +def test_no_widgetresize(qapp_utils, floatEditHolder, floatEdit): + floatEditHolder.resize(50, 50) floatEdit.setValue(123) a = floatEdit.width() floatEdit.setValue(123456789123456789.123456789123456789) @@ -75,14 +64,20 @@ def test_no_widgetresize(qapp_utils, holder, floatEdit): assert b == a -def test_widgetresize(qapp_utils, holder, floatEdit): - holder.layout().addWidget(floatEdit) - holder.resize(100, 100) - holder.show() - qapp_utils.qWaitForWindowExposed(holder) +def test_widgetresize(qapp_utils, floatEditHolder, floatEdit): + floatEditHolder.resize(50, 50) floatEdit.setWidgetResizable(True) + # Initial floatEdit.setValue(123) + qapp_utils.qWait() a = floatEdit.width() + # Grow floatEdit.setValue(123456789123456789.123456789123456789) + qapp_utils.qWait() b = floatEdit.width() + # Shrink + floatEdit.setValue(123) + qapp_utils.qWait() + c = floatEdit.width() assert b > a + assert a <= c < b