Skip to content

Commit 7ef880e

Browse files
committed
Spin: Remove return icon
1 parent 8f3968d commit 7ef880e

File tree

1 file changed

+11
-131
lines changed

1 file changed

+11
-131
lines changed

Orange/widgets/gui.py

Lines changed: 11 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -294,49 +294,6 @@ def setLayout(widget, layout):
294294
widget.setLayout(layout)
295295

296296

297-
def _enterButton(parent, control, placeholder=True):
298-
"""
299-
Utility function that returns a button with a symbol for "Enter" and
300-
optionally a placeholder to show when the enter button is hidden. Both
301-
are inserted into the parent's layout, if it has one. If placeholder is
302-
constructed it is shown and the button is hidden.
303-
304-
The height of the button is the same as the height of the widget passed
305-
as argument `control`.
306-
307-
:param parent: parent widget into which the button is inserted
308-
:type parent: PyQt4.QtGui.QWidget
309-
:param control: a widget for determining the height of the button
310-
:type control: PyQt4.QtGui.QWidget
311-
:param placeholder: a flag telling whether to construct a placeholder
312-
(default: True)
313-
:type placeholder: bool
314-
:return: a tuple with a button and a place holder (or `None`)
315-
:rtype: PyQt4.QtGui.QToolButton or tuple
316-
"""
317-
global _enter_icon
318-
if not _enter_icon:
319-
_enter_icon = QtGui.QIcon(
320-
os.path.dirname(__file__) + "/icons/Dlg_enter.png")
321-
button = QtGui.QPushButton(parent)
322-
button.setAutoDefault(True)
323-
button.setDefault(True)
324-
height = control.sizeHint().height()
325-
button.setFixedSize(height, height)
326-
button.setIcon(_enter_icon)
327-
if parent.layout() is not None:
328-
parent.layout().addWidget(button)
329-
if placeholder:
330-
button.hide()
331-
holder = QtGui.QWidget(parent)
332-
holder.setFixedSize(height, height)
333-
if parent.layout() is not None:
334-
parent.layout().addWidget(holder)
335-
else:
336-
holder = None
337-
return button, holder
338-
339-
340297
def _addSpace(widget, space):
341298
"""
342299
A helper function that adds space into the widget, if requested.
@@ -530,26 +487,11 @@ def label(widget, master, label, labelWidth=None, box=None,
530487
class SpinBoxWFocusOut(QtGui.QSpinBox):
531488
"""
532489
A class derived from QtGui.QSpinBox, which postpones the synchronization
533-
of the control's value with the master's attribute until the user presses
534-
Enter or clicks an icon that appears beside the spin box when the value
535-
is changed.
490+
of the control's value with the master's attribute until the control looses
491+
focus or user presses Tab when the value has changed.
536492
537493
The class overloads :obj:`onChange` event handler to show the commit button,
538494
and :obj:`onEnter` to commit the change when enter is pressed.
539-
540-
.. attribute:: enterButton
541-
542-
A widget (usually an icon) that is shown when the value is changed.
543-
544-
.. attribute:: placeHolder
545-
546-
A placeholder which is shown when the button is hidden
547-
548-
.. attribute:: inSetValue
549-
550-
A flag that is set when the value is being changed through
551-
:obj:`setValue` to prevent the programmatic changes from showing the
552-
commit button.
553495
"""
554496

555497
def __init__(self, minv, maxv, step, parent=None):
@@ -567,51 +509,15 @@ def __init__(self, minv, maxv, step, parent=None):
567509
super().__init__(parent)
568510
self.setRange(minv, maxv)
569511
self.setSingleStep(step)
570-
self.inSetValue = False
571-
self.enterButton = None
572-
self.placeHolder = None
573-
574-
def onChange(self, _):
575-
"""
576-
Hides the place holder and shows the commit button unless
577-
:obj:`inSetValue` is set.
578-
"""
579-
if not self.inSetValue:
580-
self.placeHolder.hide()
581-
self.enterButton.show()
582512

583513
def onEnter(self):
584514
"""
585-
If the commit button is visible, the overload event handler commits
586-
the change by calling the appropriate callbacks. It also hides the
587-
commit button and shows the placeHolder.
588-
"""
589-
if self.enterButton.isVisible():
590-
self.enterButton.hide()
591-
self.placeHolder.show()
592-
if self.cback:
593-
self.cback(int(str(self.text())))
594-
if self.cfunc:
595-
self.cfunc()
596-
597-
# doesn't work: it's probably LineEdit's focusOut that we should
598-
# (but can't) catch
599-
def focusOutEvent(self, *e):
600-
"""
601-
This handler was intended to catch the focus out event and reintepret
602-
it as if enter was pressed. It does not work, though.
515+
Commits the change by calling the appropriate callbacks.
603516
"""
604-
super().focusOutEvent(*e)
605-
if self.enterButton and self.enterButton.isVisible():
606-
self.onEnter()
607-
608-
def setValue(self, value):
609-
"""
610-
Set the :obj:`inSetValue` flag and call the inherited method.
611-
"""
612-
self.inSetValue = True
613-
super().setValue(value)
614-
self.inSetValue = False
517+
if self.cback:
518+
self.cback(int(str(self.text())))
519+
if self.cfunc:
520+
self.cfunc()
615521

616522

617523
class DoubleSpinBoxWFocusOut(QtGui.QDoubleSpinBox):
@@ -623,35 +529,12 @@ def __init__(self, minv, maxv, step, parent):
623529
self.setDecimals(math.ceil(-math.log10(step)))
624530
self.setRange(minv, maxv)
625531
self.setSingleStep(step)
626-
self.inSetValue = False
627-
self.enterButton = None
628-
self.placeHolder = None
629-
630-
def onChange(self, _):
631-
if not self.inSetValue:
632-
self.placeHolder.hide()
633-
self.enterButton.show()
634532

635533
def onEnter(self):
636-
if self.enterButton.isVisible():
637-
self.enterButton.hide()
638-
self.placeHolder.show()
639-
if self.cback:
640-
self.cback(float(str(self.text()).replace(",", ".")))
641-
if self.cfunc:
642-
self.cfunc()
643-
644-
# doesn't work: it's probably LineEdit's focusOut that we should
645-
# (and can't) catch
646-
def focusOutEvent(self, *e):
647-
super().focusOutEvent(*e)
648-
if self.enterButton and self.enterButton.isVisible():
649-
self.onEnter()
650-
651-
def setValue(self, value):
652-
self.inSetValue = True
653-
super().setValue(value)
654-
self.inSetValue = False
534+
if self.cback:
535+
self.cback(float(str(self.text()).replace(",", ".")))
536+
if self.cfunc:
537+
self.cfunc()
655538

656539

657540
def spin(widget, master, value, minv, maxv, step=1, box=None, label=None,
@@ -773,10 +656,7 @@ def spin(widget, master, value, minv, maxv, step=1, box=None, label=None,
773656
cbox.disables = [sbox]
774657
cbox.makeConsistent()
775658
if callback and callbackOnReturn:
776-
sbox.enterButton, sbox.placeHolder = _enterButton(bi, sbox)
777-
sbox.valueChanged[str].connect(sbox.onChange)
778659
sbox.editingFinished.connect(sbox.onEnter)
779-
sbox.enterButton.clicked.connect(sbox.onEnter)
780660
if hasattr(sbox, "upButton"):
781661
sbox.upButton().clicked.connect(
782662
lambda c=sbox.editor(): c.setFocus())

0 commit comments

Comments
 (0)