Skip to content

Commit d530575

Browse files
vallsvt20100
andcommitted
Apply suggestions from code review
Co-authored-by: Thomas VINCENT <[email protected]>
1 parent 157c878 commit d530575

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

src/silx/gui/widgets/FloatEdit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ class FloatEdit(qt.QLineEdit):
3939
The value can be modified with :meth:`value` and :meth:`setValue`.
4040
4141
The property :meth:`widgetResizable` allow to change the default
42-
behaviour in order to automatically resize the widhet to avoid
43-
to scroll to see the whole value. You still can enforce your own
44-
minimum width with :meth:`setMinimumWidth`.
42+
behaviour in order to automatically resize the widget to the displayed value.
43+
Use :meth:`setMinimumWidth` to enforce the minimum width.
4544
4645
:param parent: Parent of the widget
4746
:param value: The value to set the QLineEdit to.
@@ -93,14 +92,15 @@ def __textChanged(self, text: str):
9392

9493
def widgetResizable(self) -> bool:
9594
"""
96-
Returns wether the widget auto resize itself based on it's content
95+
Returns whether or not the widget auto resizes itself based on it's content
9796
"""
9897
return self.__widgetResizable
9998

10099
def setWidgetResizable(self, resizable: bool):
101100
"""
102-
If true, the widget will automatically resize itself in order to avoid
103-
to scroll to see it's content where they can be avoided, or to take
101+
If true, the widget will automatically resize itself to its displayed content.
102+
103+
This avoids to have to scroll to see the widget's content, and allow to take
104104
advantage of extra space.
105105
"""
106106
if self.__widgetResizable == resizable:

src/silx/gui/widgets/test/test_floatedit.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,63 +26,58 @@
2626
__license__ = "MIT"
2727

2828
import pytest
29-
import weakref
3029
from silx.gui import qt
3130
from silx.gui.widgets.FloatEdit import FloatEdit
3231

3332

3433
@pytest.fixture
35-
def floatEdit(qapp, qapp_utils):
36-
widget = FloatEdit()
37-
widget.setAttribute(qt.Qt.WA_DeleteOnClose)
38-
yield widget
39-
widget.close()
40-
ref = weakref.ref(widget)
41-
widget = None
42-
qapp_utils.qWaitForDestroy(ref)
34+
def floatEdit(qWidgetFactory):
35+
proxy = qWidgetFactory(FloatEdit)
36+
yield proxy
4337

4438

4539
@pytest.fixture
46-
def holder(qapp, qapp_utils):
47-
widget = qt.QWidget()
48-
qt.QHBoxLayout(widget)
49-
widget.setAttribute(qt.Qt.WA_DeleteOnClose)
50-
yield widget
51-
widget.close()
52-
ref = weakref.ref(widget)
53-
widget = None
54-
qapp_utils.qWaitForDestroy(ref)
40+
def floatEditHolder(qapp, qapp_utils, qWidgetFactory, floatEdit):
41+
proxy = qWidgetFactory(qt.QWidget)
42+
holder = proxy.__repr__.__self__
43+
layout = qt.QHBoxLayout(holder)
44+
layout.addStretch()
45+
layout.addWidget(floatEdit.__repr__.__self__)
46+
yield proxy
5547

5648

5749
def test_show(qapp_utils, floatEdit):
58-
qapp_utils.qWaitForWindowExposed(floatEdit)
50+
pass
5951

6052

6153
def test_value(floatEdit):
6254
floatEdit.setValue(1.5)
6355
assert floatEdit.value() == 1.5
6456

6557

66-
def test_no_widgetresize(qapp_utils, holder, floatEdit):
67-
holder.layout().addWidget(floatEdit)
68-
holder.resize(100, 100)
69-
holder.show()
70-
qapp_utils.qWaitForWindowExposed(holder)
58+
def test_no_widgetresize(qapp_utils, floatEditHolder, floatEdit):
59+
floatEditHolder.resize(50, 50)
7160
floatEdit.setValue(123)
7261
a = floatEdit.width()
7362
floatEdit.setValue(123456789123456789.123456789123456789)
7463
b = floatEdit.width()
7564
assert b == a
7665

7766

78-
def test_widgetresize(qapp_utils, holder, floatEdit):
79-
holder.layout().addWidget(floatEdit)
80-
holder.resize(100, 100)
81-
holder.show()
82-
qapp_utils.qWaitForWindowExposed(holder)
67+
def test_widgetresize(qapp_utils, floatEditHolder, floatEdit):
68+
floatEditHolder.resize(50, 50)
8369
floatEdit.setWidgetResizable(True)
70+
# Initial
8471
floatEdit.setValue(123)
72+
qapp_utils.qWait()
8573
a = floatEdit.width()
74+
# Grow
8675
floatEdit.setValue(123456789123456789.123456789123456789)
76+
qapp_utils.qWait()
8777
b = floatEdit.width()
78+
# Shrink
79+
floatEdit.setValue(123)
80+
qapp_utils.qWait()
81+
c = floatEdit.width()
8882
assert b > a
83+
assert a <= c < b

0 commit comments

Comments
 (0)