Esempio n. 1
0
 def keyPressEvent(self, keyEvent):
     key = keyEvent.key()
     if key == Qt.Key_Escape:
         self.showNormal()
     elif key == Qt.Key_F11:
         self.showFullScreen()
     elif key == Qt.Key_A:
         self.zoom(FACTEUR_ZOOM_FIN)
     elif key == Qt.Key_Q:
         self.zoom(-FACTEUR_ZOOM_FIN)
     elif key == Qt.Key_F1:
         self.panneauInfo.setVisible(not self.panneauInfo.isVisible())
         if self.panneauInfo.isVisible():
             self.scene().changed.connect(self.panneauInfo.sceneChanged)
         else:
             self.scene().changed.disconnect(self.panneauInfo.sceneChanged)
     elif keyEvent.modifiers() == Qt.ControlModifier \
          and key == Qt.Key_P:
         (nomFichier, filtre) = QFileDialog.getSaveFileName(
             self,
             "Sauvegarder image",
             filter="PNG (*.png);;JPEG (*.jpg);;BMP (*.bmp)")
         if nomFichier:
             pixmap = self.grab()
             pixmap.save(nomFichier)
     else:
         QGraphicsView.keyPressEvent(self, keyEvent)
 def keyPressEvent(self, event):
     """
     Handle key presses for mouse-drag transforms and arrow-key panning.
     """
     if not self._has_focus:  # we don't have focus -> ignore keypress
         return
     if event.key() == self._key_mod:
         self._transform_enable = True
         QGraphicsView.keyPressEvent(self, event)
     elif event.key() == Qt.Key_Left:
         transform = self.scene_root_item.transform()
         transform.translate(self.keyPanDeltaX(), 0)
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Up:
         transform = self.scene_root_item.transform()
         transform.translate(0, self.keyPanDeltaY())
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Right:
         transform = self.scene_root_item.transform()
         transform.translate(-self.keyPanDeltaX(), 0)
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Down:
         transform = self.scene_root_item.transform()
         transform.translate(0, -self.keyPanDeltaY())
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Plus:
         self.zoomIn(0.3)
     elif event.key() == Qt.Key_Minus:
         self.zoomIn(0.03)
     else:
         return QGraphicsView.keyPressEvent(self, event)
Esempio n. 3
0
 def keyPressEvent(self, event):
     """
     Handle key presses for mouse-drag transforms and arrow-key panning.
     """
     if not self._has_focus:  # we don't have focus -> ignore keypress
         return
     if event.key() == self._key_mod:
         self._transform_enable = True
         QGraphicsView.keyPressEvent(self, event)
     elif event.key() == Qt.Key_Left:
         transform = self.scene_root_item.transform()
         transform.translate(self.keyPanDeltaX(), 0)
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Up:
         transform = self.scene_root_item.transform()
         transform.translate(0, self.keyPanDeltaY())
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Right:
         transform = self.scene_root_item.transform()
         transform.translate(-self.keyPanDeltaX(), 0)
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Down:
         transform = self.scene_root_item.transform()
         transform.translate(0, -self.keyPanDeltaY())
         self.scene_root_item.setTransform(transform)
     elif event.key() == Qt.Key_Plus:
         self.zoomIn(0.3)
     elif event.key() == Qt.Key_Minus:
         self.zoomIn(0.03)
     else:
         if hasattr(self.scene_root_item, KEY_PRESS_EVENT):
             getattr(self.scene_root_item, KEY_PRESS_EVENT)(event)
Esempio n. 4
0
 def inputGraphicsViewKeyPressEvent(self,event):
     mousePosition = QCursor().pos()
     mousePosition = self.inputGraphicsView.mapFromGlobal(mousePosition)
     if event.type() == QtCore.QEvent.KeyPress:
         key = event.key()
         if key == QtCore.Qt.Key_Space:
             self.videoPlaybackWidget.playButtonClicked()
         elif key == QtCore.Qt.Key_A:
             self.videoPlaybackWidget.movePrevButtonClicked()
         elif key == QtCore.Qt.Key_D:
             self.videoPlaybackWidget.moveNextButtonClicked()
         elif key == QtCore.Qt.Key_Down:
             self.inputGraphicsViewScaleDown()
         elif key == QtCore.Qt.Key_Up:
             self.inputGraphicsViewScaleUp()
             pass
         elif key == QtCore.Qt.Key_R:
             self.graphicsViewResized()
         elif key == QtCore.Qt.Key_P:
             pass
             #self.handInputSystem.nextDataFrame()
         elif key == QtCore.Qt.Key_O:
             pass
             #self.handInputSystem.previousDataFrame()
         elif key == QtCore.Qt.Key_J:
             frameNo = self.handInputSystem.getLastInputedFrameIndex()
             self.videoPlaybackWidget.moveToFrame(frameNo)
         elif key == QtCore.Qt.Key_S:
             self.handInputSystem.saveCSV("./a.csv")
     QGraphicsView.keyPressEvent(self.inputGraphicsView, event)
Esempio n. 5
0
 def inputGraphicsViewKeyPressEvent(self, event):
     mousePosition = QCursor().pos()
     mousePosition = self.inputGraphicsView.mapFromGlobal(mousePosition)
     if event.type() == QtCore.QEvent.KeyPress:
         key = event.key()
         if key == QtCore.Qt.Key_Space:
             self.videoPlaybackWidget.playButtonClicked()
         elif key == QtCore.Qt.Key_A:
             self.videoPlaybackWidget.movePrevButtonClicked()
         elif key == QtCore.Qt.Key_D:
             self.videoPlaybackWidget.moveNextButtonClicked()
         elif key == QtCore.Qt.Key_Down:
             self.inputGraphicsViewScaleDown()
         elif key == QtCore.Qt.Key_Up:
             self.inputGraphicsViewScaleUp()
             pass
         elif key == QtCore.Qt.Key_R:
             self.graphicsViewResized()
         elif key == QtCore.Qt.Key_P:
             pass
             #self.handInputSystem.nextDataFrame()
         elif key == QtCore.Qt.Key_O:
             pass
             #self.handInputSystem.previousDataFrame()
         elif key == QtCore.Qt.Key_J:
             frameNo = self.handInputSystem.getLastInputedFrameIndex()
             self.videoPlaybackWidget.moveToFrame(frameNo)
         elif key == QtCore.Qt.Key_S:
             self.handInputSystem.saveCSV("./a.csv")
     QGraphicsView.keyPressEvent(self.inputGraphicsView, event)
 def graphics_view_on_key_press(self, event):
     key = event.key()
     if key in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down,
                Qt.Key_PageUp, Qt.Key_PageDown):
         # This causes the graphics view to ignore these keys so they can be caught by the bag_widget keyPressEvent
         event.ignore()
     else:
         # Maintains functionality for all other keys QGraphicsView implements
         QGraphicsView.keyPressEvent(self.graphics_view, event)
    def keyReleaseEvent(self, event):

        if self.hasImage():

            if event.key(
            ) == Qt.Key_Control and not self.global_erase_override:
                self._deleteCrossHandles[0].hide()
                self._deleteCrossHandles[1].hide()

            # Show the overlay again
            if event.key() == Qt.Key_H:
                self._overlayHandle.show()

        QGraphicsView.keyPressEvent(self, event)
Esempio n. 8
0
class MyMainWindow(QMainWindow):
    # call constructor of MyMainWindow
    def __init__(self, parent=None):
        # call constructor of QMainWindow
        super(MyMainWindow, self).__init__(parent)

        w = 1000
        h = 800
        self.scene = QGraphicsScene(-w/2, -h/2, w, h)

        self.view = QGraphicsView()
        # set QGraphicsView attributes
        # self.view.setViewport(QOpenGLWidget())
        self.view.setRenderHints(QtGui.QPainter.Antialiasing |
            QPainter.HighQualityAntialiasing)
        self.view.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
        self.view.setScene(self.scene)

        # set central widget for the application
        self.setCentralWidget(self.view)

        # add items to the scene
        self.addGraphicsItem((0, 0, 250, 250), 8.0, (255, 0, 0), (0, 0, 255), 'My first item')
        self.addGraphicsItem((-250, -250, 300, 200), 4.0, (0, 0, 0), (255, 0, 100), 'My 2nd item')
        self.addGraphicsItem((200, -200, 200, 200), 10.0, (0, 0, 255), (0, 255, 100), 'My 3rd item')

    def addGraphicsItem(self, rect, pw, pc, bc, tooltip):
        pen = QtGui.QPen(QtCore.Qt.SolidLine)
        pen.setColor(QtGui.QColor(pc[0], pc[1], pc[2], 255))
        pen.setWidth(pw)
        brush = QtGui.QBrush(QtGui.QColor(bc[0], bc[1], bc[2], 255))
        item = GraphicsItem(rect, pen, brush, tooltip)
        self.scene.addItem(item)

    def mousePressEvent(self, event):
        #print 'from MainWindow'
        pass

    def keyPressEvent(self, event: QtGui.QKeyEvent):
        key = event.key()

        if key == QtCore.Qt.Key_Escape:
            sys.exit(QApplication.quit())
        else:
            self.view.keyPressEvent(event)
Esempio n. 9
0
 def keyPressEvent(self, event):
     QGraphicsView.keyPressEvent(self, event)
     if event.key() == Qt.Key_Home or\
        event.key() == Qt.Key_H:
         self.fitWindow()
     elif event.key() == Qt.Key_W or\
          event.key() == Qt.Key_Space:
         if self.wabbox is None:
             self.fitWindow()
         else:
             b = self.wabbox
             self.fitWindow(QRectF(b.x0, b.y0, b.dx, b.dy))
     elif event.key() == Qt.Key_Plus:
         self.scaleCheck(1.25)
     elif event.key() == Qt.Key_Minus:
         self.scaleCheck(0.8)
     elif event.key() == Qt.Key_Slash:
         self.rotate(22.5)
         self.fixWindow()
     elif event.key() == Qt.Key_Backslash:
         self.rotate(-22.5)
         self.fixWindow()
Esempio n. 10
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Control:
         self.fCtrlDown = True
     QGraphicsView.keyPressEvent(self, event)
Esempio n. 11
0
 def keyReleaseEvent(self, event):
     # Disable drag mode when control button released
     if event.key() == Qt.Key_Control:
         self.setDragMode(self.NoDrag)
     return QGraphicsView.keyPressEvent(self, event)
Esempio n. 12
0
 def keyPressEvent(self, event):
     # Enable drag mode while control button is being held down
     if event.modifiers() == Qt.ControlModifier:
         self.setDragMode(self.ScrollHandDrag)
     return QGraphicsView.keyPressEvent(self, event)
Esempio n. 13
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_F:
         self.fitSelected()
     #elif event.key() == Qt.Key_Delete:
     #    self.deleteSelected()
     return QGraphicsView.keyPressEvent(self, event)
Esempio n. 14
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Control:
         self.fCtrlDown = True
     QGraphicsView.keyPressEvent(self, event)
Esempio n. 15
0
 def keyPressEvent(self, event):
     # Enable drag mode while control button is being held down
     if event.modifiers() == Qt.ControlModifier:
         self.setDragMode(self.ScrollHandDrag)
     QGraphicsView.keyPressEvent(self, event)
Esempio n. 16
0
 def keyReleaseEvent(self, event):
     # Disable drag mode when control button released
     if event.key() == Qt.Key_Control:
         self.setDragMode(self.NoDrag)
     QGraphicsView.keyPressEvent(self, event)
    def keyPressEvent(self, event):

        if self.hasImage():

            # Zoom in
            if event.key() == Qt.Key_Plus:

                viewBBox = self.zoomStack[-1] if len(
                    self.zoomStack) else self.sceneRect()

                wh12 = int(
                    max(viewBBox.width(), viewBBox.height()) /
                    self.zoom_in_modifier)
                x, y = self._lastCursorCoords

                selectionBBox = QRectF(x - wh12, y - wh12, 2 * wh12,
                                       2 * wh12).intersected(viewBBox)

                if selectionBBox.isValid() and (selectionBBox != viewBBox):
                    self.zoomStack.append(selectionBBox)
                    self.updateViewer()

            # Zoom out
            if event.key() == Qt.Key_Minus:
                if self.canZoom:
                    viewBBox = self.zoomStack[-1] if len(
                        self.zoomStack) else False
                    if viewBBox:
                        self.zoomStack = self.zoomStack[:-1]
                        self.updateViewer()

            # Fill mask region
            if event.key() == Qt.Key_F:
                try:
                    self.viewport().setCursor(Qt.BusyCursor)
                    self.fillArea()
                except Exception as e:
                    print("Cannot fill region. Additional information:")
                    print(e)
                self.viewport().setCursor(Qt.ArrowCursor)

            # Erase closed contour under cursor with current paint color
            if event.key() == Qt.Key_X:
                if QApplication.keyboardModifiers() & Qt.ControlModifier:
                    try:
                        self.viewport().setCursor(Qt.BusyCursor)
                        self.fillArea(remove_closed_contour=True)
                    except Exception as e:
                        print(
                            "Cannot remove the contour. Additional information:"
                        )
                        print(e)
                    self.viewport().setCursor(Qt.ArrowCursor)

            # Erase closed contour under cursor and any connected contour regardless of color
            if event.key() == Qt.Key_Q:
                if QApplication.keyboardModifiers() & Qt.ControlModifier:
                    try:
                        self.viewport().setCursor(Qt.BusyCursor)
                        self.fillArea(remove_closed_contour=True,
                                      remove_only_current_color=False)
                    except Exception as e:
                        print(
                            "Cannot remove the contour. Additional information:"
                        )
                        print(e)
                    self.viewport().setCursor(Qt.ArrowCursor)

            # Erase mode enable/disable
            if event.key() == Qt.Key_D:
                self.global_erase_override = not self.global_erase_override
                if self.global_erase_override:
                    self.current_painting_mode = self.MODE_ERASE
                    self._deleteCrossHandles[0].show()
                    self._deleteCrossHandles[1].show()
                else:
                    self.current_painting_mode = self.MODE_PAINT
                    self._deleteCrossHandles[0].hide()
                    self._deleteCrossHandles[1].hide()

            # Temporarily hide the overlay
            if event.key() == Qt.Key_H:
                self._overlayHandle.hide()

            # Toggle helper on and off
            if event.key() == Qt.Key_T:
                if self._auxHelper is not None:
                    if self.showHelper:
                        self._auxHelper.hide()
                        self.showHelper = False
                    else:
                        self._auxHelper.show()
                        self.showHelper = True

            # Undo operations
            if event.key() == Qt.Key_Z:
                if QApplication.keyboardModifiers() & Qt.ControlModifier:
                    if (len(self._overlay_stack) > 0):
                        self.mask_pixmap = self._overlay_stack.pop()
                        self._overlayHandle.setPixmap(self.mask_pixmap)

                    if self.direct_mask_paint:
                        if len(self._offscreen_mask_stack) > 0:
                            self._offscreen_mask = self._offscreen_mask_stack.pop(
                            )

            # When CONTROL is pressed, show the delete cross
            if event.key(
            ) == Qt.Key_Control and not self.global_erase_override:
                self._deleteCrossHandles[0].show()
                self._deleteCrossHandles[1].show()

        QGraphicsView.keyPressEvent(self, event)