本文整理汇总了Python中AnyQt.QtTest.QTest类的典型用法代码示例。如果您正苦于以下问题:Python QTest类的具体用法?Python QTest怎么用?Python QTest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_combo
def run_combo(cbox):
# type: (QComboBox) -> None
assert cbox.focusPolicy() & Qt.TabFocus
cbox.setFocus(Qt.TabFocusReason)
cbox.setCurrentIndex(-1)
for i in range(cbox.count()):
QTest.keyClick(cbox, Qt.Key_Down)
示例2: combobox_activate_index
def combobox_activate_index(cbox, index, delay=-1):
"""
Activate an item at `index` in a given combo box.
The item at index **must** be enabled and selectable.
Parameters
----------
cbox : QComboBox
index : int
delay : int
Run the event loop after the signals are emitted for `delay`
milliseconds (-1, the default, means no delay).
"""
assert 0 <= index < cbox.count()
model = cbox.model()
column = cbox.modelColumn()
root = cbox.rootModelIndex()
mindex = model.index(index, column, root)
assert mindex.flags() & Qt.ItemIsEnabled
cbox.setCurrentIndex(index)
text = cbox.currentText()
# QComboBox does not have an interface which would allow selecting
# the current item as if a user would. Only setCurrentIndex which
# does not emit the activated signals.
cbox.activated[int].emit(index)
cbox.activated[str].emit(text)
if delay >= 0:
QTest.qWait(delay)
示例3: combobox_run_through_all
def combobox_run_through_all(cbox, delay=-1, callback=None):
"""
Run through all items in a given combo box, simulating the user
focusing the combo box and pressing the Down arrow key activating
all the items on the way.
Unhandled exceptions from invoked PyQt slots/virtual function overrides
are captured and reraised.
Parameters
----------
cbox : QComboBox
delay : int
Run the event loop after the simulated key press (-1, the default,
means no delay)
callback : callable
A callback that will be executed after every item change. Takes no
parameters.
See Also
--------
QTest.keyClick
"""
assert cbox.focusPolicy() & Qt.TabFocus
cbox.setFocus(Qt.TabFocusReason)
cbox.setCurrentIndex(-1)
for i in range(cbox.count()):
with excepthook_catch() as exlist:
QTest.keyClick(cbox, Qt.Key_Down, delay=delay)
if callback:
callback()
if exlist:
raise exlist[0][1] from exlist[0][1]
示例4: hold_modifiers
def hold_modifiers(widget, modifiers):
# use some unexisting key
QTest.keyPress(widget, Qt.Key_F35, modifiers)
try:
yield
finally:
QTest.keyRelease(widget, Qt.Key_F35)
示例5: do_zoom_rect
def do_zoom_rect(self, invertX):
""" Test zooming with two clicks. """
self.send_signal("Data", self.iris)
vb = self.widget.curveplot.plot.vb
self.widget.curveplot.invertX = invertX
self.widget.curveplot.invertX_apply()
vb.set_mode_zooming()
vr = vb.viewRect()
tls = vr.bottomRight() if self.widget.curveplot.invertX else vr.bottomLeft()
# move down to avoid clicking on the menu button
tl = vb.mapViewToScene(tls).toPoint() + QPoint(0, 100)
br = vb.mapViewToScene(vr.center()).toPoint()
tlw = vb.mapSceneToView(tl)
brw = vb.mapSceneToView(br)
ca = self.widget.curveplot.childAt(tl)
QTest.mouseClick(ca, Qt.LeftButton, pos=tl)
QTest.qWait(1)
self.widget.curveplot.plot.scene().sigMouseMoved.emit(tl)
QTest.qWait(1)
self.widget.curveplot.plot.scene().sigMouseMoved.emit(tl + QPoint(10, 10))
QTest.qWait(1)
QTest.mouseClick(ca, Qt.LeftButton, pos=br)
vr = vb.viewRect()
self.assertAlmostEqual(vr.bottom(), tlw.y())
self.assertAlmostEqual(vr.top(), brw.y())
if self.widget.curveplot.invertX:
self.assertAlmostEqual(vr.right(), tlw.x())
self.assertAlmostEqual(vr.left(), brw.x())
else:
self.assertAlmostEqual(vr.left(), tlw.x())
self.assertAlmostEqual(vr.right(), brw.x())
示例6: test_label_overlap
def test_label_overlap(self):
self.send_signal(self.widget.Inputs.data, self.heart)
self.widget.stretched = False
self.__select_variable("chest pain")
self.__select_group("gender")
self.widget.show()
QTest.qWait(3000)
self.widget.hide()
示例7: test_escape_hides
def test_escape_hides(self):
window = QDialog()
w = WebviewWidget(window)
window.show()
w.setFocus(Qt.OtherFocusReason)
self.assertFalse(window.isHidden())
QTest.keyClick(w, Qt.Key_Escape)
self.assertTrue(window.isHidden())
示例8: test_widget_without_basic_layout
def test_widget_without_basic_layout(self):
class TestWidget2(OWWidget):
name = "Test"
want_basic_layout = False
w = TestWidget2()
w.showEvent(QShowEvent())
QTest.mousePress(w, Qt.LeftButton, Qt.NoModifier, QPoint(1, 1))
示例9: mouseMove
def mouseMove(widget, pos=QPoint(), delay=-1): # pragma: no-cover
# Like QTest.mouseMove, but functional without QCursor.setPos
if pos.isNull():
pos = widget.rect().center()
me = QMouseEvent(QMouseEvent.MouseMove, pos, widget.mapToGlobal(pos),
Qt.NoButton, Qt.MouseButtons(0), Qt.NoModifier)
if delay > 0:
QTest.qWait(delay)
QApplication.sendEvent(widget, me)
示例10: test_combobox
def test_combobox(self):
cb = self.cb
cb.grab()
cb.showPopup()
popup = cb.findChild(QListView) # type: QListView
# run through paint code for coverage
popup.grab()
cb.grab()
model = popup.model()
self.assertEqual(model.rowCount(), cb.count())
QTest.keyClick(popup, Qt.Key_E)
self.assertEqual(model.rowCount(), 2)
QTest.keyClick(popup, Qt.Key_Backspace)
self.assertEqual(model.rowCount(), cb.count())
QTest.keyClick(popup, Qt.Key_F)
self.assertEqual(model.rowCount(), 1)
popup.setCurrentIndex(model.index(0, 0))
spy = QSignalSpy(cb.activated[int])
QTest.keyClick(popup, Qt.Key_Enter)
self.assertEqual(spy[0], [4])
self.assertEqual(cb.currentIndex(), 4)
self.assertEqual(cb.currentText(), "Four")
self.assertFalse(popup.isVisible())
示例11: modifiers
def modifiers(self, modifiers):
"""
Context that simulates pressed modifiers
Since QTest.keypress requries pressing some key, we simulate
pressing "BassBoost" that looks exotic enough to not meddle with
anything.
"""
old_modifiers = QApplication.keyboardModifiers()
try:
QTest.keyPress(self.widget, Qt.Key_BassBoost, modifiers)
yield
finally:
QTest.keyRelease(self.widget, Qt.Key_BassBoost, old_modifiers)
示例12: test_combobox_navigation
def test_combobox_navigation(self):
cb = self.cb
cb.setCurrentIndex(4)
self.assertTrue(cb.currentText(), "Four")
cb.showPopup()
popup = cb.findChild(QListView) # type: QListView
self.assertEqual(popup.currentIndex().row(), 4)
QTest.keyClick(popup, Qt.Key_Up)
self.assertEqual(popup.currentIndex().row(), 2)
QTest.keyClick(popup, Qt.Key_Escape)
self.assertFalse(popup.isVisible())
self.assertEqual(cb.currentIndex(), 4)
cb.hidePopup()
示例13: test_click
def test_click(self):
interval = QApplication.doubleClickInterval()
QApplication.setDoubleClickInterval(0)
cb = self.cb
spy = QSignalSpy(cb.activated[int])
cb.showPopup()
popup = cb.findChild(QListView) # type: QListView
model = popup.model()
rect = popup.visualRect(model.index(2, 0))
QTest.mouseRelease(
popup.viewport(), Qt.LeftButton, Qt.NoModifier, rect.center()
)
QApplication.setDoubleClickInterval(interval)
self.assertEqual(len(spy), 1)
self.assertEqual(spy[0], [2])
self.assertEqual(cb.currentIndex(), 2)
示例14: _update_integration_type
def _update_integration_type(self):
self.line1.hide()
self.line2.hide()
self.line3.hide()
if self.value_type == 0:
self.box_values_spectra.setDisabled(False)
self.box_values_feature.setDisabled(True)
if self.integration_methods[self.integration_method] != Integrate.PeakAt:
self.line1.show()
self.line2.show()
else:
self.line3.show()
elif self.value_type == 1:
self.box_values_spectra.setDisabled(True)
self.box_values_feature.setDisabled(False)
QTest.qWait(1) # first update the interface
示例15: test_resort_on_data_change
def test_resort_on_data_change(self):
iris = Table("iris")
# one example is included from the other class
# to keep F1 from complaining
setosa = iris[:51]
versicolor = iris[49:100]
class SetosaLearner:
def __call__(self, data):
model = ConstantModel([1., 0, 0])
model.domain = iris.domain
return model
class VersicolorLearner:
def __call__(self, data):
model = ConstantModel([0, 1., 0])
model.domain = iris.domain
return model
# this is done manually to avoid multiple computations
self.widget.resampling = 5
self.widget.set_train_data(iris)
self.widget.set_learner(SetosaLearner(), 1)
self.widget.set_learner(VersicolorLearner(), 2)
self.send_signal(self.widget.Inputs.test_data, setosa, wait=5000)
self.widget.show()
header = self.widget.view.horizontalHeader()
QTest.mouseClick(header.viewport(), Qt.LeftButton)
# Ensure that the click on header caused an ascending sort
# Ascending sort means that wrong model should be listed first
self.assertEqual(header.sortIndicatorOrder(), Qt.AscendingOrder)
self.assertEqual(
self.widget.view.model().item(0, 0).text(),
"VersicolorLearner")
self.send_signal(self.widget.Inputs.test_data, versicolor, wait=5000)
self.assertEqual(
self.widget.view.model().item(0, 0).text(),
"SetosaLearner")
self.widget.hide()