Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas VINCENT <[email protected]>
  • Loading branch information
vallsv and t20100 committed Dec 15, 2023
1 parent 157c878 commit d530575
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
12 changes: 6 additions & 6 deletions src/silx/gui/widgets/FloatEdit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
53 changes: 24 additions & 29 deletions src/silx/gui/widgets/test/test_floatedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,63 +26,58 @@
__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):
floatEdit.setValue(1.5)
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)
b = floatEdit.width()
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

0 comments on commit d530575

Please sign in to comment.