python类Key_Return()的实例源码

test_utils.py 文件源码 项目:RRPam-WDS 作者: asselapathirana 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def set_text_spinbox(item, value=""):  # useful for qtests.

    for i in range(3):
        QTest.keyPress(item, Qt.Key_Backspace)
        QTest.keyPress(item, Qt.Key_Delete)
    QTest.keyClicks(item, str(value))
    QTest.keyPress(item, Qt.Key_Return)
test_datawindow.py 文件源码 项目:RRPam-WDS 作者: asselapathirana 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_get_information_returns_the_right_data(self):
        # create some groups
        item = self.aw.datawindow.ui.no_groups
        set_text_spinbox(item, 12)
        A1 = 1.12e-4
        N01 = 1.34e-5
        cost1 = 22.
        A2 = 1.2e-4
        N02 = 2.2e-1
        one = self.aw.datawindow.assetgrouplist[11]
        set_text_textbox(one.A, A1)
        A1 = float(one.A.text())
        set_text_textbox(one.N0, N01)
        N01 = float(one.N0.text())
        set_text_textbox(one.cost, cost1)
        cost1 = float(one.cost.text())
        box = self.aw.datawindow.assetgrouplist[2]
        set_text_textbox(box.A, A2)
        A2 = float(box.A.text())
        set_text_textbox(box.N0, N02)
        N02 = float(box.N0.text())
        set_text_spinbox(item, 4)
        QTest.keyPress(item, Qt.Key_Return)  # now we have only 4 active items
        active, values = self.aw.datawindow.get_information(all=True)
        self.assertEqual(active, 4)
        self.assertEqual(values[11][0], A1)
        self.assertEqual(values[11][1], N01)
        self.assertEqual(values[11][2], cost1)
        self.assertEqual(values[2][0], A2)
        self.assertEqual(values[2][1], N02)
test_datawindow.py 文件源码 项目:RRPam-WDS 作者: asselapathirana 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_number_of_property_groups_is_kept_equal_to_no_groups_spinbox(self):
        self.compare()
        item = self.aw.datawindow.ui.no_groups
        set_text_spinbox(item, "12")
        self.compare()
        set_text_spinbox(item, "2")
        self.compare()
        set_text_spinbox(item, "8")
        QTest.keyPress(item, Qt.Key_Return)
        self.compare()
        set_text_spinbox(item, "-5")
        self.compare()
featureCodeEditor.py 文件源码 项目:defconQt 作者: trufont 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def keyPressEvent(self, event):
        key = event.key()
        if key == Qt.Key_Return:
            cursor = self.textCursor()
            indentLvl = self.findLineIndentLevel()
            newBlock = False

            pos = cursor.position()
            cursor.movePosition(QTextCursor.PreviousCharacter,
                                QTextCursor.KeepAnchor)
            if cursor.selectedText() == self.openBlockDelimiter:
                # We don't add a closing tag if there is text right
                # below with the same indentation level because in
                # that case the user might just be looking to add a
                # new line
                ok = cursor.movePosition(QTextCursor.Down)
                if ok:
                    downIndentLvl = self.findLineIndentLevel(cursor)
                    cursor.select(QTextCursor.LineUnderCursor)
                    if (cursor.selectedText().strip(
                            ) == '' or downIndentLvl <= indentLvl):
                        newBlock = True
                    cursor.movePosition(QTextCursor.Up)
                else:
                    newBlock = True
                indentLvl += 1

            if newBlock:
                cursor.select(QTextCursor.LineUnderCursor)
                txt = cursor.selectedText().lstrip(" ").split(" ")
                if len(txt) > 1:
                    if len(txt) < 3 and txt[-1][-1] == self.openBlockDelimiter:
                        feature = txt[-1][:-1]
                    else:
                        feature = txt[1]
                else:
                    feature = None
            cursor.setPosition(pos)

            cursor.beginEditBlock()
            cursor.insertText("\n")
            newLineSpace = "".join(self._indent for _ in range(indentLvl))
            cursor.insertText(newLineSpace)
            if newBlock:
                cursor.insertText("\n")
                newLineSpace = "".join((newLineSpace[:-len(self._indent)],
                                        "} ", feature, ";"))
                cursor.insertText(newLineSpace)
                cursor.movePosition(QTextCursor.Up)
                cursor.movePosition(QTextCursor.EndOfLine)
                self.setTextCursor(cursor)
            cursor.endEditBlock()
        else:
            super(FeatureCodeEditor, self).keyPressEvent(event)


问题


面经


文章

微信
公众号

扫码关注公众号