Skip to content

Commit

Permalink
Gave the QLineEdit widget a parent in _make_text_entry method in orde…
Browse files Browse the repository at this point in the history
…r to spark a focusOutEvent when a OK button is clicked in the unittests.
  • Loading branch information
pbrod committed Nov 24, 2021
1 parent 7090b82 commit 7fd3f89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
23 changes: 12 additions & 11 deletions traitsui/qt4/range_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def init(self, parent):
widget.
"""
self._init_with_factory_defaults()
self.control = self._make_control()
self.control = self._make_control(parent)
self._do_layout(self.control)

def _init_with_factory_defaults(self):
Expand All @@ -96,7 +96,7 @@ def _init_with_factory_defaults(self):
self.sync_value(factory.low_name, "low", "from")
self.sync_value(factory.high_name, "high", "from")

def _make_control(self):
def _make_control(self, parent):
raise NotImplementedError

def _do_layout(self, control):
Expand All @@ -112,15 +112,16 @@ def _clip(self, fvalue, low, high):

return fvalue

def _make_text_entry(self, fvalue_text):
def _make_text_entry(self, control, fvalue_text):

update_object_on_enter = self.update_object_on_enter

class TextCtrl(QtGui.QLineEdit):
def focusOutEvent(self, event):
update_object_on_enter()
super(TextCtrl, self).focusOutEvent(event)

text = TextCtrl(fvalue_text)
text = TextCtrl(fvalue_text, control)

if self.factory.enter_set:
# text.editingFinished.connect(self.update_object_on_enter)
Expand Down Expand Up @@ -233,7 +234,7 @@ class SimpleSliderEditor(BaseRangeEditor):
# Trait definitions: See BaseRangeEditor
# -------------------------------------------------------------------------

def _make_control(self):
def _make_control(self, parent):

low, high = self._get_current_range()
fvalue = self._clip(self.value, low, high)
Expand All @@ -245,7 +246,7 @@ def _make_control(self):
control.label_lo = self._make_label_low(low, width)
control.slider = self._make_slider(fvalue)
control.label_hi = self._make_label_high(high, width)
control.text = self._make_text_entry(fvalue_text)
control.text = self._make_text_entry(control, fvalue_text)
return control

@staticmethod
Expand Down Expand Up @@ -401,7 +402,7 @@ def init(self, parent):
self._do_layout(self.control)

def _make_control(self, parent):
control = super()._make_control()
control = super()._make_control(parent)
low, high = self._get_current_range()

control.button_lo = self._make_button_low(low)
Expand Down Expand Up @@ -565,7 +566,7 @@ class SimpleSpinEditor(BaseRangeEditor):
#: Step value for the spinner
step = Any(1)

def _make_control(self):
def _make_control(self, parent):

low, high = self._get_current_range()
fvalue = self._clip(self.value, low, high)
Expand All @@ -590,7 +591,7 @@ def keyPressEvent(self, event):
spin_up_or_down(-scale)

control = Control()
control.text = self._make_text_entry(fvalue_text)
control.text = self._make_text_entry(control, fvalue_text)
control.button_lo = self._make_button_low(fvalue)
control.button_hi = self._make_button_high(fvalue)
return control
Expand Down Expand Up @@ -670,14 +671,14 @@ class RangeTextEditor(BaseRangeEditor):
the background of the field changes color to indicate an error.
"""

def _make_control(self):
def _make_control(self, parent):

low, high = self._get_current_range()
fvalue = self._clip(self.value, low, high)
fvalue_text = self.string_value(fvalue)

control = QtGui.QWidget()
control.text = self._make_text_entry(fvalue_text)
control.text = self._make_text_entry(control, fvalue_text)
return control

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def displayed_text_qobject(widget):


def mouse_click_qwidget(control, delay):
"""Performs a mouce click on a Qt widget.
"""Performs a mouse click on a Qt widget.
Parameters
----------
Expand All @@ -114,6 +114,7 @@ def mouse_click_qwidget(control, delay):
# for QAbstractButtons we do not use QTest.mouseClick as it assumes the
# center of the widget as the location to be clicked, which may be
# incorrect. For QAbstractButtons we can simply call their click method.

if isinstance(control, QtGui.QAbstractButton):
if delay > 0:
QTest.qSleep(delay)
Expand Down

0 comments on commit 7fd3f89

Please sign in to comment.