예제 #1
0
    def listKeyPressed(self, event: QKeyEvent):
        """ Activates the panel matching a key press event if the QListWidget has focus.
        The QListWidget items can be selected using the Up and Down arrow keys or by pressing the
        first letter of the item title (e.g. "a" for the "About" item).
        These key events emit an `itemClicked` event in turn, which are being handled by the `listItemClicked` method.
        """
        key = (event.text() or '').lower() or event.key()
        list_index = self.keymap.get(key, -1)
        if list_index < 0:
            # User did not press the first letter of a panel name: check if arrow keys were pressed
            row_index = self.listWidget.currentRow()
            if key == Qt.Key_Up and row_index > 0:
                # User pressed the Up key and there is a list item above the current one
                list_index = row_index - 1
            elif key == Qt.Key_Down and row_index < len(
                    self.panel_widgets) - 1:
                # User pressed the Down key and there is a list item below the current one
                list_index = row_index + 1

        if list_index >= 0:
            # Select the list item that the user requested
            self.listSelectNoSignals(list_index)
            list_item = self.listWidget.item(list_index)
            self.listWidget.itemClicked.emit(list_item)

        # Default action
        event.accept()
예제 #2
0
    def keyPressEvent(self, event: QKeyEvent) -> None:
        """Modify key press events.

        :param event:
        """
        # gobble Enter
        if event.key() == Qt.Key_Enter:
            pass

        # close dialog on Escape
        if event.key() == Qt.Key_Escape:
            self.close()
예제 #3
0
 def doneCompletion(self):
     self.timer.stop()
     self.popup.hide()
     self.editor.setFocus()
     item = self.popup.currentItem()
     if item:
         self.editor.setText(item.text(0))
         obj = item.data(2, Qt.UserRole)  #.toPyObject()
         self.selectedObject = obj[0]
         e = QKeyEvent(QEvent.KeyPress, Qt.Key_Enter, Qt.NoModifier)
         QApplication.postEvent(self.editor, e)
         e = QKeyEvent(QEvent.KeyRelease, Qt.Key_Enter, Qt.NoModifier)
         QApplication.postEvent(self.editor, e)
예제 #4
0
    def keyReleaseEvent(self, event: QKeyEvent) -> None:
        index = self.currentIndex()
        if (index.column() == 0
                and event.key() in [Qt.Key_Enter, Qt.Key_Return]):
            node: PlanetNode = self.model().get_node(index)
            if (node.node_type() == NodeT.LOAD_MORE
                    and node.parent() == self.model().root):
                self.model().fetch_more_top_items(index)

        return QTreeView.keyReleaseEvent(self, event)
예제 #5
0
    def listKeyPressed(self, event: QKeyEvent):
        """ Activates the server widget matching a key press event if the QListWidget has focus.
        The QListWidget items can be selected using the Up and Down arrow keys only.
        These key events emit an `itemClicked` event in turn, which are being handled by the `listItemClicked` method.
        """
        list_index = -1
        row_index = self.listServers.currentRow()
        if event.key() == Qt.Key_Up and row_index > 0:
            # User pressed the Up key and there is a list item above the current one
            list_index = row_index - 1
        elif event.key(
        ) == Qt.Key_Down and row_index < self.listServers.count() - 1:
            # User pressed the Down key and there is a list item below the current one
            list_index = row_index + 1

        if list_index >= 0:
            # Select the list item that the user requested
            list_item = self.listServers.item(list_index)
            self.listSelectNoSignals(list_item)
            self.listServers.itemClicked.emit(list_item)

        # Default action
        event.accept()
예제 #6
0
    def test_tool(self):
        """
        Test some plot tool logic
        """
        canvas = QgsElevationProfileCanvas()
        canvas.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
        canvas.setFrameStyle(0)
        canvas.resize(600, 400)
        canvas.setProject(QgsProject.instance())
        canvas.show()
        self.assertEqual(canvas.width(), 600)
        self.assertEqual(canvas.height(), 400)
        ls = QgsLineString()
        ls.fromWkt('LineString(0 2, 10 2, 10 4)')
        canvas.setProfileCurve(ls)
        canvas.setVisiblePlotRange(0, ls.length(), 0, 100)

        self.assertFalse(canvas.tool())
        tool = TestTool(canvas)
        self.assertFalse(tool.isActive())
        canvas.setTool(tool)
        self.assertEqual(canvas.tool(), tool)

        key_press_event = QKeyEvent(QEvent.KeyPress, 54, Qt.ShiftModifier)
        canvas.keyPressEvent(key_press_event)
        self.assertEqual(tool.events[-1].type(), QEvent.KeyPress)

        key_release_event = QKeyEvent(QEvent.KeyRelease, 54, Qt.ShiftModifier)
        canvas.keyReleaseEvent(key_release_event)
        self.assertEqual(tool.events[-1].type(), QEvent.KeyRelease)

        mouse_dbl_click_event = QMouseEvent(QEvent.MouseButtonDblClick, QPointF(300, 200), Qt.LeftButton, Qt.MouseButtons(), Qt.ShiftModifier)
        canvas.mouseDoubleClickEvent(mouse_dbl_click_event)
        self.assertEqual(tool.events[-1].type(), QEvent.MouseButtonDblClick)
        self.assertIsInstance(tool.events[-1], QgsPlotMouseEvent)
        self.assertAlmostEqual(tool.events[-1].mapPoint().x(), 5.92, delta=0.6)
        self.assertAlmostEqual(tool.events[-1].mapPoint().y(), 2, 4)
        self.assertAlmostEqual(tool.events[-1].mapPoint().z(), 49.165, delta=5)

        mouse_move_event = QMouseEvent(QEvent.MouseMove, QPointF(300, 200), Qt.LeftButton, Qt.MouseButtons(), Qt.ShiftModifier)
        canvas.mouseMoveEvent(mouse_move_event)
        self.assertEqual(tool.events[-1].type(), QEvent.MouseMove)
        self.assertIsInstance(tool.events[-1], QgsPlotMouseEvent)
        self.assertAlmostEqual(tool.events[-1].mapPoint().x(), 5.92, delta=10)
        self.assertAlmostEqual(tool.events[-1].mapPoint().y(), 2, 4)
        self.assertAlmostEqual(tool.events[-1].mapPoint().z(), 49.165, delta=5)

        mouse_press_event = QMouseEvent(QEvent.MouseButtonPress, QPointF(300, 200), Qt.LeftButton, Qt.MouseButtons(), Qt.ShiftModifier)
        canvas.mousePressEvent(mouse_press_event)
        self.assertEqual(tool.events[-1].type(), QEvent.MouseButtonPress)
        self.assertIsInstance(tool.events[-1], QgsPlotMouseEvent)
        self.assertAlmostEqual(tool.events[-1].mapPoint().x(), 5.927, delta=1)
        self.assertAlmostEqual(tool.events[-1].mapPoint().y(), 2, 4)
        self.assertAlmostEqual(tool.events[-1].mapPoint().z(), 49.165, delta=5)

        mouse_release_event = QMouseEvent(QEvent.MouseButtonRelease, QPointF(300, 200), Qt.LeftButton, Qt.MouseButtons(), Qt.ShiftModifier)
        canvas.mouseReleaseEvent(mouse_release_event)
        self.assertEqual(tool.events[-1].type(), QEvent.MouseButtonRelease)
        self.assertIsInstance(tool.events[-1], QgsPlotMouseEvent)
        self.assertAlmostEqual(tool.events[-1].mapPoint().x(), 5.927, delta=1)
        self.assertAlmostEqual(tool.events[-1].mapPoint().y(), 2, 4)
        self.assertAlmostEqual(tool.events[-1].mapPoint().z(), 49.165, delta=5)

        wheel_event = QWheelEvent(QPointF(300, 200), QPointF(300, 200), QPoint(1, 2), QPoint(3, 4), Qt.NoButton, Qt.NoModifier, Qt.ScrollBegin, False)
        canvas.wheelEvent(wheel_event)
        self.assertEqual(tool.events[-1].type(), QEvent.Wheel)