Ejemplo n.º 1
0
 def _tool_tip(self, command):
     popup = self.popup()
     point = QtCore.QPoint(popup.pos().x() + popup.width(),
                           popup.pos().y() - 16)
     for item in self._command_hints:
         if item['Command'] == command:
             QToolTip.showText(point, item['Hint'])
             break
         else:
             QToolTip.hideText()
Ejemplo n.º 2
0
    def __init__(self, parent=None):
        super(ScribbleArea, self).__init__(parent)

        self.setAttribute(QtCore.Qt.WA_StaticContents)
        self.modified = False
        self.scribbling = False
        self.myPenWidth = 1
        self.myPenColor = QtCore.Qt.blue
        self.image = QImage()
        self.lastPoint = QtCore.QPoint()
Ejemplo n.º 3
0
    def mouseReleaseEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.pixmapOffset += event.pos() - self.lastDragPos
            self.lastDragPos = QtCore.QPoint()

            deltaX = (self.width() -
                      self.pixmap.width()) / 2 - self.pixmapOffset.x()
            deltaY = (self.height() -
                      self.pixmap.height()) / 2 - self.pixmapOffset.y()
            self.scroll(deltaX, deltaY)
Ejemplo n.º 4
0
    def paintLimits(self, limits, qp, pen, brush):
        qp.setPen(pen)
        qp.setBrush(brush)

        x0 = int(round(self.pixel_per_msec * (limits[0] - self.t0))) + self.lmx
        x1 = int(round(self.pixel_per_msec * (limits[1] - self.t0)))
        y0 = self.ytick + self.mitick
        y1 = self.h + self.lmy + self.umy

        self.logger.debug("paintLimits: %i, %i, %i, %i", x0, x1, y0, y1)

        rect = [
            QtCore.QPoint(x0, y0),
            QtCore.QPoint(x1, y0),
            QtCore.QPoint(x1, y1),
            QtCore.QPoint(x0, y1)
        ]

        qp.drawPolygon(QtGui.QPolygon(rect))
Ejemplo n.º 5
0
    def _show_context_menu(self, x, y, used_labels, unused_labels):
        menu = QtWidgets.QMenu(self._ui.sceneviewer_widget)

        self._add_labels_as_actions(menu, unused_labels)
        menu.addSeparator()
        self._add_labels_as_actions(menu, used_labels)

        menu.exec_(
            self.mapToGlobal(
                QtCore.QPoint(x, y) + self._ui.sceneviewer_widget.pos()))
Ejemplo n.º 6
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.setMouseTracking(True)

        self.drag = False
        self.offset = QtCore.QPoint(0, 0)
Ejemplo n.º 7
0
    def mouse_update(self, event):
        if self._current_tool == 'rect':
            self.color_point = event.pos()
        else:
            center = self._get_center()
            a = QtCore.QPoint(event.pos().x(), center.y())
            self._angle = get_absolute_angle_c(a=a, b=event.pos(), c=center)

        self.repaint()
        self.currentColorChanged.emit(self.current_color())
Ejemplo n.º 8
0
 def __init__(self, parent=None):
     super(ColorWheel, self).__init__(parent)
     self._is_clicked = False
     self._rect = QtCore.QRect(25, 25, 50, 50)
     self._current_color = QtGui.QColor(WHITE)
     self._color_point = QtCore.QPoint(150, 50)
     self._current_tool = None
     self._angle = 180
     self.setFixedSize(100, 100)
     self.initUI()
Ejemplo n.º 9
0
    def mouseMoveEvent(self, event):
        if self.isSelected():
            if event.buttons() & QtCore.Qt.LeftButton:
                super(boxItem, self).mouseMoveEvent(event)
            elif event.buttons() & QtCore.Qt.MiddleButton:
                self.rect = QtCore.QRectF(QtCore.QPoint(), event.pos()).normalized()
                self.prepareGeometryChange()
                self.setRect(self.rect)

            self.setGridIntersection(self.p_scene, self.a_state)
Ejemplo n.º 10
0
    def read_settings(self):
        """read settings from persistent storage
        """
        self.settings.beginGroup('MainWindow')

        self.resize(self.settings.value('size', QtCore.QSize(800, 600)))
        self.move(self.settings.value('pos', QtCore.QPoint(100, 100)))
        self.restoreState(self.settings.value('windowState'))

        self.settings.endGroup()
Ejemplo n.º 11
0
def test_laser_view(qtbot: QtBot):
    viewspace = LaserViewSpace()
    qtbot.addWidget(viewspace)
    viewspace.show()
    view = viewspace.activeView()
    laser = view.addLaser(Laser(rand_data(["A1", "B2", "C3"])))
    qtbot.waitExposed(laser)

    view.tabs.setTabText(0, "newname")
    assert view.stack.widget(0).laserName() == "newname"

    view.contextMenuEvent(
        QtGui.QContextMenuEvent(QtGui.QContextMenuEvent.Mouse,
                                QtCore.QPoint(0, 0)))

    # Drop event
    drag_mime = QtCore.QMimeData()
    path = Path(__file__).parent.joinpath("data", "io", "npz", "test.npz")
    drag_mime.setUrls([QtCore.QUrl.fromLocalFile(str(path.resolve()))])
    drag_event = QtGui.QDragEnterEvent(
        QtCore.QPoint(0, 0),
        QtCore.Qt.CopyAction,
        drag_mime,
        QtCore.Qt.LeftButton,
        QtCore.Qt.NoModifier,
    )
    view.dragEnterEvent(drag_event)
    assert drag_event.isAccepted()
    drop_event = QtGui.QDropEvent(
        QtCore.QPoint(0, 0),
        QtCore.Qt.CopyAction,
        drag_mime,
        QtCore.Qt.LeftButton,
        QtCore.Qt.NoModifier,
    )
    with qtbot.waitSignal(view.numTabsChanged):
        view.dropEvent(drop_event)
    assert drop_event.isAccepted()
    assert len(view.widgets()) == 2

    dlg = view.actionOpen()
    dlg.show()
    dlg.close()
Ejemplo n.º 12
0
 def __init__(self, parent):
     self.parent = parent
     self.origin = QtCore.QPoint()
     mouse.Listener.__init__(self,
                             on_move=self.on_mouse_move,
                             on_click=self.on_mouse_click,
                             suppress=True)
     QtWidgets.QRubberBand.__init__(self, QtWidgets.QRubberBand.Rectangle)
     self.setWindowOpacity(0.25)
     self.start()
Ejemplo n.º 13
0
 def moveWindow(event):
     """
     Metoto de evento a ação de mover o formulário
     Parâmetro:
         - event: evento do formulário
     """
     if event.buttons() == QtCore.Qt.LeftButton:
         delta = QtCore.QPoint(event.globalPos() - self.oldPos)
         self.move(self.x() + delta.x(), self.y() + delta.y())
         self.oldPos = event.globalPos()
    def paintEvent(self, event):
        if SnippingWidget.is_snipping:
            brush_color = (128, 128, 255, 100)
            lw = 3
            opacity = 0.3
        else:
            # reset points, so the rectangle won't show up again.
            self.begin = QtCore.QPoint()
            self.end = QtCore.QPoint()
            brush_color = (0, 0, 0, 0)
            lw = 0
            opacity = 0

        self.setWindowOpacity(opacity)
        qp = QtGui.QPainter(self)
        qp.setPen(QtGui.QPen(QtGui.QColor('black'), lw))
        qp.setBrush(QtGui.QColor(*brush_color))
        rect = QtCore.QRectF(self.begin, self.end)
        qp.drawRect(rect)
Ejemplo n.º 15
0
def test_scaled_image_item_smooth():
    image = QtGui.QImage(100, 100, QtGui.QImage.Format_Mono)
    image.fill(QtCore.Qt.white)

    item = ScaledImageItem(image, QtCore.QRectF(0, 100, 200, 400), smooth=True)

    assert item.width() == 100
    assert item.height() == 100
    assert item.pixelSize() == QtCore.QSizeF(2.0, 4.0)
    assert item.mapToData(QtCore.QPointF(100, 100)) == QtCore.QPoint(50, 0)
Ejemplo n.º 16
0
    def initialItemPosition(self, path):
        y = (self.height() - path.controlPointRect().height()) / 2

        if len(self.shapeItems) == 0:
            x = ((3 * self.width()) / 2 - path.controlPointRect().width()) / 2
        else:
            x = (self.width() / len(self.shapeItems) -
                 path.controlPointRect().width()) / 2

        return QtCore.QPoint(x, y)
Ejemplo n.º 17
0
        def __pointToPixel(self, p):
            p = np.array(p)
            pixel = (p - self.center) * self.ech

            # pixel = p * self.ech

            pixel[1] = -pixel[1]

            pixel += self.center
            return qtcore.QPoint(pixel[0], pixel[1])
Ejemplo n.º 18
0
    def mouseMoveEvent(self, event):
        dx = event.x() - self.lastPos.x()
        dy = event.y() - self.lastPos.y()

        if event.buttons() & QtCore.Qt.LeftButton:
            self.rotateBy(8 * dy, 8 * dx, 0)
        elif event.buttons() & QtCore.Qt.RightButton:
            self.rotateBy(8 * dy, 0, 8 * dx)

        self.lastPos = QtCore.QPoint(event.pos())
Ejemplo n.º 19
0
    def addPieces(self, pixmap):
        self.beginRemoveRows(QtCore.QModelIndex(), 0, 24)
        self.pixmaps = []
        self.locations = []
        self.endRemoveRows()

        for y in range(5):
            for x in range(5):
                pieceImage = pixmap.copy(x * 80, y * 80, 80, 80)
                self.addPiece(pieceImage, QtCore.QPoint(x, y))
Ejemplo n.º 20
0
    def mouseMoveEvent(self, event):

        self.mouse_position = (self._mouse.x(), self._mouse.y())

        ctrl = (self._key_modifiers
                & QtCore.Qt.KeyboardModifier.ControlModifier) != 0
        shift = (self._key_modifiers
                 & QtCore.Qt.KeyboardModifier.ShiftModifier) != 0
        alt = (self._key_modifiers
               & QtCore.Qt.KeyboardModifier.AltModifier) != 0

        # Screen units delta
        dx = event.x() - self._mouse.x()
        dy = event.y() - self._mouse.y()

        # Right mouse button held down with CTRL/cmd key - rotate
        # Or middle mouse button held
        if ((event.buttons() & QtCore.Qt.RightButton and ctrl)
                or ((event.buttons() & QtCore.Qt.MiddleButton) and not ctrl)):
            self._rotating = True
            self._rotate_x = self._rotate_x + dy
            self._rotate_y = self._rotate_y + dx
            self.updateGL()

        # Middle mouse button held down with CTRL - translate
        # or right mouse button with alt
        elif ((event.buttons() & QtCore.Qt.MiddleButton and ctrl)
              or (event.buttons() & QtCore.Qt.RightButton and alt)):
            self._rotating = True
            # Work out the translation in 3d space
            self._translate_x = self._translate_x + dx * self._htranslate
            self._translate_y = self._translate_y + ((-dy) * self._vtranslate)
            self.updateGL()

        else:
            # Remember the mouse deltas
            self.mouse_delta_relative = (dx, dy)
            self.mouse_delta_absolute = (event.x() - self._mouse_absolute.x(),
                                         event.y() - self._mouse_absolute.y())

            # Maybe we are dragging
            if time.time() - self._mousedown_time > 0.3 and not self._dragging:
                self._dragging = True
                # Announce the start of a drag
                x, y, z, face = self.window_to_voxel(event.x(), event.y())
                self.send_drag(self.DRAG_START, x, y, z, event.x(), event.y(),
                               face)
                self.refresh()
            elif time.time() - self._mousedown_time > 0.3 and self._dragging:
                # Already dragging - send a drag event
                x, y, z, face = self.window_to_voxel(event.x(), event.y())
                self.send_drag(self.DRAG, x, y, z, event.x(), event.y(), face)
                self.refresh()

        self._mouse = QtCore.QPoint(event.pos())
    def slideInWgt(self, newwidget):
        if self.m_active:
            return

        self.m_active = True

        _now = self.currentIndex()
        _next = self.indexOf(newwidget)

        if _now == _next:
            self.m_active = False
            return

        offsetx, offsety = self.frameRect().width(), self.frameRect().height()
        self.widget(_next).setGeometry(self.frameRect())

        if not self.m_direction == QtCore.Qt.Horizontal:
            if _now < _next:
                offsetx, offsety = 0, -offsety
            else:
                offsetx = 0
        else:
            if _now < _next:
                offsetx, offsety = -offsetx, 0
            else:
                offsety = 0

        pnext = self.widget(_next).pos()
        pnow = self.widget(_now).pos()
        self.m_pnow = pnow

        offset = QtCore.QPoint(offsetx, offsety)
        self.widget(_next).move(pnext - offset)
        self.widget(_next).show()
        self.widget(_next).raise_()

        anim_group = QtCore.QParallelAnimationGroup(
            self, finished=self.animationDoneSlot)

        for index, start, end in zip((_now, _next), (pnow, pnext - offset),
                                     (pnow + offset, pnext)):
            animation = QtCore.QPropertyAnimation(
                self.widget(index),
                b"pos",
                duration=self.m_speed,
                easingCurve=self.m_animationtype,
                startValue=start,
                endValue=end,
            )
            anim_group.addAnimation(animation)

        self.m_next = _next
        self.m_now = _now
        self.m_active = True
        anim_group.start(QtCore.QAbstractAnimation.DeleteWhenStopped)
Ejemplo n.º 22
0
    def __init__(self, scene, parent=None):
        """
        Create an instance of this class

        :param scene: GraphScene reference
        :type scene: :class:`nodegraph.nodegraphScene.GraphScene`

        :param parent: Parent widget
        :type parent: mixed

        :return: An instance of this class
        :rtype :class:`nodegraph.nodegraphView.GraphView`

        """
        QtWidgets.QGraphicsView.__init__(self, scene, parent)
        self._last_mouse_pos = QtCore.QPoint(0, 0)
        self._width = SCENE_WIDTH
        self._height = SCENE_HEIGHT
        self._scale = 1.0
        self._is_view_initialised = False
        self._is_pan = False
        self._is_zoom = False

        # Set scene
        self.setScene(scene)

        # Set scene rectangle
        self.scene().setSceneRect(
            QtCore.QRectF(-self._width / 2, -self._height / 2, self._width,
                          self._height))

        # Enable OpenGL
        # GL_format = QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)
        # viewport = QtOpenGL.QGLWidget(GL_format)
        # self.setViewport(viewport)

        # Settings
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorViewCenter)
        self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
        self.setRenderHint(QtGui.QPainter.Antialiasing)
        # self.setRenderHint(QtGui.QPainter.TextAntialiasing)
        # self.setRenderHint(QtGui.QPainter.HighQualityAntialiasing)
        self.setViewportUpdateMode(
            QtWidgets.QGraphicsView.BoundingRectViewportUpdate)
        # self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)
        self.setDragMode(QtWidgets.QGraphicsView.NoDrag)
        self.setRubberBandSelectionMode(QtCore.Qt.ContainsItemBoundingRect)
        # self.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
        #                    QtWidgets.QSizePolicy.Expanding)

        # Init scene
        self.setInteractive(True)
        self.setAcceptDrops(True)
Ejemplo n.º 23
0
    def paintEvent(self, event):
        rect = self.rect()
        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing, True)
        painter.save()

        fontColor = self._color
        fontFamily = "Work Sans SemiBold"
        gradient = QtGui.QLinearGradient(rect.topLeft(), rect.bottomRight())
        gradient.setColorAt(0, self._color)
        gradient.setColorAt(1, self._color)

        if self._style == DialogButton.DisplayStyle.kMainPriority:
            # Draw BG
            painter.restore()
            painter.setBrush(QtGui.QBrush(gradient))
            painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
            painter.drawRoundedRect(rect, self._radius, self._radius)
            fontColor = QtGui.QColor(255 - self._color.red(), 255 - self._color.green(), 255 - self._color.blue())
        elif self._style == DialogButton.DisplayStyle.kSecondaryPriority:
            # Draw Stroke
            painter.restore()
            painter.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
            pen = QtGui.QPen(QtGui.QBrush(gradient), 2)
            painter.setPen(pen)
            pntList = []
            pntList.append(QtCore.QPoint(rect.left() + 1, rect.top() + rect.height() - 1)) # Bottom left
            pntList.append(QtCore.QPoint(rect.left() + rect.width() - 1, rect.top() + rect.height() - 1)) # Bottom right
            pntList.append(QtCore.QPoint(rect.left() + rect.width() - 1, rect.top() + 2)) # Top right
            pntList.append(QtCore.QPoint(rect.left() + 1, rect.top() + 2)) # Top left
            painter.drawPath(self._getPath(pntList))
        else:
            fontFamily = "Work Sans Medium"

        # Draw Text
        painter.restore()
        font = QtGui.QFont()
        font.setPixelSize(14)
        font.setFamily(fontFamily)
        painter.setFont(font)
        painter.setPen(QtGui.QPen(fontColor))
        painter.drawText(rect, QtCore.Qt.AlignCenter, self._text)
Ejemplo n.º 24
0
    def _drawToast(self, toastInQuestion, option):

        self._animating = True
        parentRect = self.parent.rect()

        if option == ToastOption.Add:
            self._notifications.append(toastInQuestion)
        elif option == ToastOption.Remove:
            self._notifications.remove(toastInQuestion)
        else:
            raise ValueError(f"Toast option invalid: {option}")

        basePoint = parentRect.bottomRight() + QtCore.QPoint(
            -self.BOTTOM_SCREEN_MARGIN, -self.SIDE_MARGIN
        )

        for toast in reversed(self._notifications):

            # Determine and set position of this toast
            geo = toast.geometry()
            geo.moveBottomRight(basePoint + QtCore.QPoint(0, -self.BOTTOM_MARGIN))

            toast.setGeometry(geo)

            # If this is the relevant toast, determine where it
            # should be coming from or going
            otherGeo = toast.geometry()
            if toast is toastInQuestion:
                if option == ToastOption.Add:
                    otherGeo.moveBottomRight(
                        otherGeo.bottomRight() + QtCore.QPoint(0, 10)
                    )
                elif option == ToastOption.Remove:
                    otherGeo.moveBottomRight(
                        otherGeo.bottomRight() + QtCore.QPoint(0, 10)
                    )

            # toast.animateIn(geo.move)
            toast.show_()
            basePoint = geo.topRight()

        self._animating = False
Ejemplo n.º 25
0
 def getCheckBoxRect(self, option):
     opts = QtWidgets.QStyleOptionButton()
     rect = QtWidgets.QApplication.style().subElementRect(
         QtWidgets.QStyle.SE_CheckBoxIndicator, opts, None)
     x = option.rect.x()
     y = option.rect.y()
     w = option.rect.width()
     h = option.rect.height()
     checkBoxTopLeftCorner = QtCore.QPoint(x + w / 2 - rect.width() / 2,
                                           y + h / 2 - rect.height() / 2)
     return QtCore.QRect(checkBoxTopLeftCorner, rect.size())
Ejemplo n.º 26
0
    def _update_visible_indices(self):
        """
        Updates the stored first & last visible text content indices so we
        can focus operations like highlighting on text that is visible

        @postcondition: The _first_visible_index & _last_visible_index are
                        up to date (in sync with the current viewport)
        """

        viewport = self._content_box.viewport()
        try:
            top_left = QtCore.QPoint(0, 0)
            bottom_right = QtCore.QPoint(viewport.width() - 1,
                                         viewport.height() - 1)
            first = self._content_box.cursorForPosition(top_left).position()
            last = self._content_box.cursorForPosition(bottom_right).position()
            self._first_visible_index = first
            self._last_visible_index = last
        except IndexError:  # When there's nothing in the content box
            pass
Ejemplo n.º 27
0
    def _set_scrollbar_value(self, val):
        """
        Stores the passed value in self._scrollbar_value. This slot is
        connected to the valueChanged event of the main scrollbar, and is used
        for storing the scrollbar value after updating the content box.
        * It also triggers the same actions triggered by pressing the mouse
        somewhere in the content box, (updating)
        """

        self._scrollbar_value = val
        self._on_mouse_pressed(QtCore.QPoint(0, 0))
Ejemplo n.º 28
0
 def paintEvent(self, event):
     # Set up the painter
     paint = QtGui.QPainter(self)
     paint.setRenderHint(QtGui.QPainter.Antialiasing)
     paint.setBrush(QtCore.Qt.red)
     # Get the ball position
     position = QtCore.QPoint(
         int(self.ball.position[0] * self.size().width()),
         int(self.ball.position[1] * self.size().height()))
     # Draw the ball
     paint.drawEllipse(position, 60, 60)
Ejemplo n.º 29
0
 def paintEvent(self, event):
     if not self.pixmap.isNull():
         size = self.size()
         painter = QtGui.QPainter(self)
         point = QtCore.QPoint(0,0)
         scaledPix = self.pixmap.scaled(size,
                                     QtCore.Qt.KeepAspectRatio,
                                     transformMode = QtCore.Qt.SmoothTransformation)
         point.setX((size.width() - scaledPix.width()) / 2)
         point.setY((size.height() - scaledPix.height()) / 2)
         painter.drawPixmap(point, scaledPix)
Ejemplo n.º 30
0
 def initTitleFrame(self, colour="40, 40, 40, 255"):
     self.setMinimumHeight(24)
     self.setStyleSheet("QFrame {\
        background-color: rgba(" + colour + ");\
        margin: 0px, 0px, 0px, 0px;\
        padding: 0px, 0px, 0px, 0px;\
        }")
     self.arrow = CollapsibleArrow(self)
     self.titleLabel = QtWidgets.QLabel(self)
     self.titleLabel.setMinimumHeight(24)
     self.titleLabel.move(QtCore.QPoint(24, 0))