Skip to content

Commit bc6673f

Browse files
authored
Merge pull request #1609 from VesnaT/line_edit
gui: Remove return icon
2 parents 58ccf38 + 7ef880e commit bc6673f

File tree

2 files changed

+22
-187
lines changed

2 files changed

+22
-187
lines changed

Orange/widgets/data/owpaintdata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,13 +824,13 @@ def _init_ui(self):
824824
hbox = gui.hBox(namesBox, margin=0, spacing=0)
825825
gui.lineEdit(hbox, self, "attr1", "Variable X: ",
826826
controlWidth=80, orientation=Qt.Horizontal,
827-
enterPlaceholder=True, callback=self._attr_name_changed)
828-
gui.separator(hbox, 18)
827+
callback=self._attr_name_changed)
828+
gui.separator(hbox, 21)
829829
hbox = gui.hBox(namesBox, margin=0, spacing=0)
830830
attr2 = gui.lineEdit(hbox, self, "attr2", "Variable Y: ",
831831
controlWidth=80, orientation=Qt.Horizontal,
832-
enterPlaceholder=True,
833832
callback=self._attr_name_changed)
833+
gui.separator(hbox)
834834
gui.checkBox(hbox, self, "hasAttr2", '', disables=attr2,
835835
labelWidth=0,
836836
callback=self.set_dimensions)

Orange/widgets/gui.py

Lines changed: 19 additions & 184 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.
603-
"""
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.
515+
Commits the change by calling the appropriate callbacks.
611516
"""
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())
@@ -878,25 +758,10 @@ class LineEditWFocusOut(QtGui.QLineEdit):
878758
"""
879759
A class derived from QtGui.QLineEdit, which postpones the synchronization
880760
of the control's value with the master's attribute until the user leaves
881-
the line edit, presses Enter or clicks an icon that appears beside the
882-
line edit when the value is changed.
761+
the line edit or presses Tab when the value is changed.
883762
884763
The class also allows specifying a callback function for focus-in event.
885764
886-
.. attribute:: enterButton
887-
888-
A widget (usually an icon) that is shown when the value is changed.
889-
890-
.. attribute:: placeHolder
891-
892-
A placeholder which is shown when the button is hidden
893-
894-
.. attribute:: inSetValue
895-
896-
A flag that is set when the value is being changed through
897-
:obj:`setValue` to prevent the programmatic changes from showing the
898-
commit button.
899-
900765
.. attribute:: callback
901766
902767
Callback that is called when the change is confirmed
@@ -906,41 +771,19 @@ class LineEditWFocusOut(QtGui.QLineEdit):
906771
Callback that is called on the focus-in event
907772
"""
908773

909-
def __init__(self, parent, callback, focusInCallback=None,
910-
placeholder=False):
774+
def __init__(self, parent, callback, focusInCallback=None):
911775
super().__init__(parent)
912776
if parent.layout() is not None:
913777
parent.layout().addWidget(self)
914778
self.callback = callback
915779
self.focusInCallback = focusInCallback
916-
self.enterButton, self.placeHolder = \
917-
_enterButton(parent, self, placeholder)
918-
self.enterButton.clicked.connect(self.returnPressedHandler)
919-
self.textChanged[str].connect(self.markChanged)
920780
self.returnPressed.connect(self.returnPressedHandler)
921781

922-
def markChanged(self, *_):
923-
if self.placeHolder:
924-
self.placeHolder.hide()
925-
self.enterButton.show()
926-
927-
def markUnchanged(self, *_):
928-
self.enterButton.hide()
929-
if self.placeHolder:
930-
self.placeHolder.show()
931-
932782
def returnPressedHandler(self):
933-
if self.enterButton.isVisible():
934-
self.markUnchanged()
935-
if hasattr(self, "cback") and self.cback:
936-
self.cback(self.text())
937-
if self.callback:
938-
self.callback()
939-
940-
def setText(self, t):
941-
super().setText(t)
942-
if self.enterButton:
943-
self.markUnchanged()
783+
if hasattr(self, "cback") and self.cback:
784+
self.cback(self.text())
785+
if self.callback:
786+
self.callback()
944787

945788
def focusOutEvent(self, *e):
946789
super().focusOutEvent(*e)
@@ -955,8 +798,7 @@ def focusInEvent(self, *e):
955798
def lineEdit(widget, master, value, label=None, labelWidth=None,
956799
orientation=Qt.Vertical, box=None, callback=None,
957800
valueType=str, validator=None, controlWidth=None,
958-
callbackOnType=False, focusInCallback=None,
959-
enterPlaceholder=False, **misc):
801+
callbackOnType=False, focusInCallback=None, **misc):
960802
"""
961803
Insert a line edit.
962804
@@ -990,10 +832,6 @@ def lineEdit(widget, master, value, label=None, labelWidth=None,
990832
:param focusInCallback: a function that is called when the line edit
991833
receives focus
992834
:type focusInCallback: function
993-
:param enterPlaceholder: if set to `True`, space of appropriate width is
994-
left empty to the right for the icon that shows that the value is
995-
changed but has not been committed yet
996-
:type enterPlaceholder: bool
997835
:rtype: PyQt4.QtGui.QLineEdit or a box
998836
"""
999837
if box or label:
@@ -1008,7 +846,6 @@ def lineEdit(widget, master, value, label=None, labelWidth=None,
1008846
baseClass = misc.pop("baseClass", None)
1009847
if baseClass:
1010848
ledit = baseClass(b)
1011-
ledit.enterButton = None
1012849
if b is not widget:
1013850
b.layout().addWidget(ledit)
1014851
elif focusInCallback or callback and not callbackOnType:
@@ -1018,11 +855,9 @@ def lineEdit(widget, master, value, label=None, labelWidth=None,
1018855
b = outer
1019856
else:
1020857
outer = b
1021-
ledit = LineEditWFocusOut(outer, callback, focusInCallback,
1022-
enterPlaceholder)
858+
ledit = LineEditWFocusOut(outer, callback, focusInCallback)
1023859
else:
1024860
ledit = QtGui.QLineEdit(b)
1025-
ledit.enterButton = None
1026861
if b is not widget:
1027862
b.layout().addWidget(ledit)
1028863

0 commit comments

Comments
 (0)