当前位置: 首页>>代码示例>>Python>>正文


Python QTest.keyClick方法代码示例

本文整理汇总了Python中AnyQt.QtTest.QTest.keyClick方法的典型用法代码示例。如果您正苦于以下问题:Python QTest.keyClick方法的具体用法?Python QTest.keyClick怎么用?Python QTest.keyClick使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AnyQt.QtTest.QTest的用法示例。


在下文中一共展示了QTest.keyClick方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_combo

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
 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)
开发者ID:cheral,项目名称:orange3,代码行数:9,代码来源:test_owmds.py

示例2: combobox_run_through_all

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
    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]
开发者ID:PrimozGodec,项目名称:orange3,代码行数:35,代码来源:utils.py

示例3: test_escape_hides

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
 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())
开发者ID:cheral,项目名称:orange3,代码行数:10,代码来源:test_webview.py

示例4: __set_value

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
 def __set_value(widget, value):
     if isinstance(widget, QLineEdit):
         QTest.mouseClick(widget, Qt.LeftButton)
         QTest.keyClicks(widget, value, delay=0)
         QTest.keyClick(widget, Qt.Key_Enter)
     elif isinstance(widget, QComboBox):
         simulate.combobox_activate_item(widget, value)
     else:
         raise ValueError("Unsupported widget {}".format(widget))
开发者ID:PrimozGodec,项目名称:orange3,代码行数:11,代码来源:test_owselectrows.py

示例5: test_combobox_navigation

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
    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()
开发者ID:PrimozGodec,项目名称:orange3,代码行数:16,代码来源:test_combobox.py

示例6: test_combobox

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
    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())
开发者ID:PrimozGodec,项目名称:orange3,代码行数:27,代码来源:test_combobox.py

示例7: enterFilter

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
    def enterFilter(self, variable, filter, value=None, value2=None):
        row = self.widget.cond_list.model().rowCount()
        self.widget.add_button.click()

        var_combo = self.widget.cond_list.cellWidget(row, 0)
        simulate.combobox_activate_item(var_combo, variable.name, delay=0)

        oper_combo = self.widget.cond_list.cellWidget(row, 1)
        simulate.combobox_activate_item(oper_combo, filter, delay=0)

        value_inputs = self._get_value_line_edits(row)
        for i, value in enumerate([value, value2]):
            if value is None:
                continue
            QTest.mouseClick(value_inputs[i], Qt.LeftButton)
            QTest.keyClicks(value_inputs[i], value, delay=0)
            QTest.keyClick(value_inputs[i], Qt.Key_Enter)
开发者ID:kernc,项目名称:orange3,代码行数:19,代码来源:test_owselectrows.py

示例8: test_discrete_editor_add_remove_action

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
    def test_discrete_editor_add_remove_action(self):
        w = DiscreteVariableEditor()
        v = Categorical("C", ("a", "b", "c"),
                        (("A", "1"), ("B", "b")))
        w.set_data(v)
        action_add = w.add_new_item
        action_remove = w.remove_item
        view = w.values_edit
        model, selection = view.model(), view.selectionModel()
        selection.clear()

        action_add.trigger()
        self.assertTrue(view.state() == view.EditingState)
        editor = view.focusWidget()
        assert isinstance(editor, QLineEdit)
        spy = QSignalSpy(model.dataChanged)
        QTest.keyClick(editor, Qt.Key_D)
        QTest.keyClick(editor, Qt.Key_Return)
        self.assertTrue(model.rowCount() == 4)
        # The commit to model is executed via a queued invoke
        self.assertTrue(bool(spy) or spy.wait())
        self.assertEqual(model.index(3, 0).data(Qt.EditRole), "d")
        # remove it
        spy = QSignalSpy(model.rowsRemoved)
        action_remove.trigger()
        self.assertEqual(model.rowCount(), 3)
        self.assertEqual(len(spy), 1)
        _, first, last = spy[0]
        self.assertEqual((first, last), (3, 3))
        # remove/drop and existing value
        selection.select(model.index(1, 0), QItemSelectionModel.ClearAndSelect)
        removespy = QSignalSpy(model.rowsRemoved)
        changedspy = QSignalSpy(model.dataChanged)
        action_remove.trigger()
        self.assertEqual(len(removespy), 0, "Should only mark item as removed")
        self.assertGreaterEqual(len(changedspy), 1, "Did not change data")
        w.grab()
开发者ID:PrimozGodec,项目名称:orange3,代码行数:39,代码来源:test_oweditdomain.py

示例9: enter_text

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
 def enter_text(widget, text):
     # type: (QLineEdit, str) -> None
     widget.selectAll()
     QTest.keyClick(widget, Qt.Key_Delete)
     QTest.keyClicks(widget, text)
     QTest.keyClick(widget, Qt.Key_Return)
开发者ID:PrimozGodec,项目名称:orange3,代码行数:8,代码来源:test_oweditdomain.py

示例10: test_value_edit

# 需要导入模块: from AnyQt.QtTest import QTest [as 别名]
# 或者: from AnyQt.QtTest.QTest import keyClick [as 别名]
    def test_value_edit(self):
        data = Table("heart_disease")[::10]
        self.send_signal(self.widget.Inputs.data, data)
        widget = self.widget
        model = widget.varmodel
        view = widget.varview
        selmodel = view.selectionModel()
        varbg = widget.variable_button_group

        def selectvars(varlist, command=selmodel.ClearAndSelect):
            indices = [data.domain.index(var) for var in varlist]
            itemsel = QItemSelection()
            for ind in indices:
                midx = model.index(ind)
                itemsel.select(midx, midx)
            selmodel.select(itemsel, command)

        def effective_method(var):
            return widget.get_method_for_column(data.domain.index(var))

        # select 'chest pain'
        selectvars(['chest pain'])
        self.assertTrue(widget.value_combo.isVisibleTo(widget) and
                        widget.value_combo.isEnabledTo(widget))
        self.assertEqual(varbg.checkedId(), Method.AsAboveSoBelow)

        simulate.combobox_activate_item(
            widget.value_combo, data.domain["chest pain"].values[1])
        # The 'Value' (impute.Default) should have been selected automatically
        self.assertEqual(varbg.checkedId(), Method.Default)
        imputer = effective_method('chest pain')
        self.assertIsInstance(imputer, impute.Default)
        self.assertEqual(imputer.default, 1)

        # select continuous 'rest SBP' and 'cholesterol' variables
        selectvars(["rest SBP", "cholesterol"])
        self.assertTrue(widget.value_double.isVisibleTo(widget) and
                        widget.value_double.isEnabledTo(widget))
        self.assertEqual(varbg.checkedId(), Method.AsAboveSoBelow)
        widget.value_double.setValue(-1.0)
        QTest.keyClick(self.widget.value_double, Qt.Key_Enter)
        # The 'Value' (impute.Default) should have been selected automatically
        self.assertEqual(varbg.checkedId(), Method.Default)
        imputer = effective_method("rest SBP")
        self.assertIsInstance(imputer, impute.Default)
        self.assertEqual(imputer.default, -1.0)
        imputer = effective_method("cholesterol")
        self.assertIsInstance(imputer, impute.Default)
        self.assertEqual(imputer.default, -1.0)

        # Add 'chest pain' to the selection and ensure the value stack is
        # disabled
        selectvars(["chest pain"], selmodel.Select)
        self.assertEqual(varbg.checkedId(), -1)
        self.assertFalse(widget.value_combo.isEnabledTo(widget) and
                         widget.value_double.isEnabledTo(widget))

        # select 'chest pain' only and check that the selected value is
        # restored in the value combo
        selectvars(["chest pain"])
        self.assertTrue(widget.value_combo.isVisibleTo(widget) and
                        widget.value_combo.isEnabledTo(widget))
        self.assertEqual(varbg.checkedId(), Method.Default)
        self.assertEqual(widget.value_combo.currentIndex(), 1)
开发者ID:acopar,项目名称:orange3,代码行数:66,代码来源:test_owimpute.py


注:本文中的AnyQt.QtTest.QTest.keyClick方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。