Beispiel #1
0
    def load_widgets(self, widgets, parent=None):
        for w in widgets:
            if isinstance(w, base_widgets.BaseRigToolBoxWidget):
                w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
                w.emitInfo.connect(self._on_show_success)
                w.emitError.connect(self._on_show_error)
                dock_widget = dock.DockWidget(w.title, parent=parent or self)
                info_button = QToolButton(parent=parent or self)
                info_button.setCheckable(True)
                info_button.setChecked(True)
                info_button.setIcon(resources.icon('info', theme='color'))
                if hasattr(w, '_on_toggle_info'):
                    info_button.toggled.connect(w._on_toggle_info)
                dock_widget.add_button(info_button)
            else:
                dock_widget = dock.DockWidget(w.objectName(),
                                              parent=parent or self)

            dock_widget.setWidget(w)
            self._base_window.addDockWidget(Qt.TopDockWidgetArea, dock_widget)
Beispiel #2
0
class ExpandableLine(QWidget, object):
    def __init__(self, title='', animation_duration=300, parent=None):
        super(ExpandableLine, self).__init__(parent=parent)

        self._animation_duration = animation_duration

        base_layout = layouts.GridLayout(margins=(0, 0, 0, 0))
        base_layout.setVerticalSpacing(0)
        self.setLayout(base_layout)

        self.expand_btn = QToolButton()
        self.expand_btn.setText(str(title))
        self.expand_btn.setStyleSheet('QToolButton { border : none; }')
        self.expand_btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.expand_btn.setArrowType(Qt.ArrowType.RightArrow)
        self.expand_btn.setCheckable(True)
        self.expand_btn.setChecked(True)

        header_line = QFrame()
        header_line.setFrameShape(QFrame.HLine)
        header_line.setFrameShadow(QFrame.Sunken)
        header_line.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)

        self.content_area = QScrollArea()
        self.content_area.setStyleSheet('QScrollArea { border: none;}')
        self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.content_area.setMaximumHeight(0)
        self.content_area.setMinimumHeight(0)

        self.toggle_anim = QParallelAnimationGroup()
        self.toggle_anim.addAnimation(QPropertyAnimation(self, 'minimumHeight'))
        self.toggle_anim.addAnimation(QPropertyAnimation(self, 'maximumHeight'))
        self.toggle_anim.addAnimation(QPropertyAnimation(self.content_area, 'maximumHeight'))

        row = 0
        base_layout.addWidget(self.expand_btn, row, 0, 1, 1, Qt.AlignLeft)
        base_layout.addWidget(header_line, row, 2, 1, 1)
        row += 1
        base_layout.addWidget(self.content_area, row, 0, 1, 3)

        def expand_view(checked):
            arrow_type = Qt.DownArrow if checked else Qt.RightArrow
            direction = QAbstractAnimation.Forward if checked else QAbstractAnimation.Backward
            self.expand_btn.setArrowType(arrow_type)
            self.toggle_anim.setDirection(direction)
            self.toggle_anim.start()

        # === SIGNALS === #
        self.expand_btn.toggled.connect(expand_view)

        expand_view(True)

    def set_content_layout(self, content_layout):
        self.content_area.destroy()
        self.content_area.setLayout(content_layout)
        collapsed_height = self.sizeHint().height() - self.content_area.maximumHeight()
        content_height = content_layout.sizeHint().height() + 300
        for i in range(self.toggle_anim.animationCount() - 1):
            expand_anim = self.toggle_anim.animationAt(i)
            expand_anim.setDuration(self._animation_duration)
            expand_anim.setStartValue(collapsed_height)
            expand_anim.setEndValue(collapsed_height + content_height)
        content_anim = self.toggle_anim.animationAt(self.toggle_anim.animationCount() - 1)
        content_anim.setDuration(self._animation_duration)
        content_anim.setStartValue(0)
        content_anim.setEndValue(content_height)
Beispiel #3
0
class View(QFrame):
    graphicsView = None
    label = None
    label2 = None
    selectModeButton = None
    dragModeButton = None
    openGlButton = None
    antialiasButton = None
    resetButton = None
    zoomSlider = None
    rotateSlider = None

    def __init__(self, name, parent=None):
        super(View, self).__init__(parent)
        self.init_ui(name)

    def init_ui(self, name):
        self.setFrameStyle(QFrame.Sunken | QFrame.StyledPanel)
        self.graphicsView = GraphicsView(self)
        self.graphicsView.setRenderHint(QPainter.Antialiasing, False)
        self.graphicsView.setDragMode(QGraphicsView.RubberBandDrag)
        self.graphicsView.setOptimizationFlags(QGraphicsView.DontSavePainterState)
        self.graphicsView.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate)
        self.graphicsView.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)

        size = self.style().pixelMetric(QStyle.PM_ToolBarIconSize)
        iconSize = QSize(size, size)

        zoomInIcon = QToolButton()
        zoomInIcon.setAutoRepeat(True)
        zoomInIcon.setAutoRepeatInterval(33)
        zoomInIcon.setAutoRepeatDelay(0)
        zoomInIcon.setIcon(QIcon(":/zoomin.png"))
        zoomInIcon.setIconSize(iconSize)
        zoomOutIcon = QToolButton()
        zoomOutIcon.setAutoRepeat(True)
        zoomOutIcon.setAutoRepeatInterval(33)
        zoomOutIcon.setAutoRepeatDelay(0)
        zoomOutIcon.setIcon(QIcon(":/zoomout.png"))
        zoomOutIcon.setIconSize(iconSize)
        self.zoomSlider = QSlider()
        self.zoomSlider.setMinimum(0)
        self.zoomSlider.setMaximum(500)
        self.zoomSlider.setValue(250)
        self.zoomSlider.setTickPosition(QSlider.TicksRight)

        # Zoom slider layout
        zoomSliderLayout = QVBoxLayout()
        zoomSliderLayout.addWidget(zoomInIcon)
        zoomSliderLayout.addWidget(self.zoomSlider)
        zoomSliderLayout.addWidget(zoomOutIcon)

        rotateLeftIcon = QToolButton()
        rotateLeftIcon.setIcon(QIcon(":/rotateleft.png"))
        rotateLeftIcon.setIconSize(iconSize)
        rotateRightIcon = QToolButton()
        rotateRightIcon.setIcon(QIcon(":/rotateright.png"))
        rotateRightIcon.setIconSize(iconSize)
        self.rotateSlider = QSlider()
        self.rotateSlider.setOrientation(Qt.Horizontal)
        self.rotateSlider.setMinimum(-360)
        self.rotateSlider.setMaximum(360)
        self.rotateSlider.setValue(0)
        self.rotateSlider.setTickPosition(QSlider.TicksBelow)

        # Rotate slider layout
        rotateSliderLayout = QHBoxLayout()
        rotateSliderLayout.addWidget(rotateLeftIcon)
        rotateSliderLayout.addWidget(self.rotateSlider)
        rotateSliderLayout.addWidget(rotateRightIcon)

        self.resetButton = QToolButton()
        self.resetButton.setText("0")
        self.resetButton.setEnabled(False)

        # Label layout
        labelLayout = QHBoxLayout()
        self.label = QLabel(name)
        self.label2 = QLabel("Pointer Mode")
        self.selectModeButton = QToolButton()
        self.selectModeButton.setText("Select")
        self.selectModeButton.setCheckable(True)
        self.selectModeButton.setChecked(True)
        self.dragModeButton = QToolButton()
        self.dragModeButton.setText("Drag")
        self.dragModeButton.setCheckable(True)
        self.dragModeButton.setChecked(False)
        self.antialiasButton = QToolButton()
        self.antialiasButton.setText("Antialiasing")
        self.antialiasButton.setCheckable(True)
        self.antialiasButton.setChecked(False)
        self.openGlButton = QToolButton()
        self.openGlButton.setText("OpenGL")
        self.openGlButton.setCheckable(True)
        self.openGlButton.setEnabled(QGLFormat.hasOpenGL())

        pointerModeGroup = QButtonGroup()
        pointerModeGroup.setExclusive(True)
        pointerModeGroup.addButton(self.selectModeButton)
        pointerModeGroup.addButton(self.dragModeButton)

        labelLayout.addWidget(self.label)
        labelLayout.addStretch()
        labelLayout.addWidget(self.label2)
        labelLayout.addWidget(self.selectModeButton)
        labelLayout.addWidget(self.dragModeButton)
        labelLayout.addStretch()
        labelLayout.addWidget(self.antialiasButton)
        labelLayout.addWidget(self.openGlButton)

        topLayout = QGridLayout()
        topLayout.addLayout(labelLayout, 0, 0)
        topLayout.addWidget(self.graphicsView, 1, 0)
        topLayout.addLayout(zoomSliderLayout, 1, 1)
        topLayout.addLayout(rotateSliderLayout, 2, 0)
        topLayout.addWidget(self.resetButton, 2, 1)
        self.setLayout(topLayout)

        self.resetButton.clicked.connect(self.resetView)
        self.zoomSlider.valueChanged.connect(self.setupTransform)
        self.rotateSlider.valueChanged.connect(self.setupTransform)

        self.graphicsView.verticalScrollBar().valueChanged.connect(self.setResetButtonEnabled)
        self.graphicsView.horizontalScrollBar().valueChanged.connect(self.setResetButtonEnabled)
        self.selectModeButton.toggled.connect(self.togglePointerMode)
        self.dragModeButton.toggled.connect(self.togglePointerMode)
        self.antialiasButton.toggled.connect(self.toggleAntialiasing)
        self.openGlButton.toggled.connect(self.toggleOpenGL)
        rotateLeftIcon.clicked.connect(self.rotateLeft)
        rotateRightIcon.clicked.connect(self.rotateRight)
        zoomInIcon.clicked.connect(self.zoomIn)
        zoomOutIcon.clicked.connect(self.zoomOut)

        self.setupTransform()

    def view(self):
        return self.graphicsView

    @Slot()
    def zoomIn(self):
        self.zoomSlider.setValue(self.zoomSlider.value() + 1)

    @Slot()
    def zoomOut(self):
        self.zoomSlider.setValue(self.zoomSlider.value() - 1)

    @Slot()
    def resetView(self):
        self.zoomSlider.setValue(250)
        self.rotateSlider.setValue(0)
        self.setupTransform()
        self.graphicsView.ensureVisible(QRectF(0, 0, 0, 0))

        self.resetButton.setEnabled(False)

    @Slot()
    def setResetButtonEnabled(self):
        self.resetButton.setEnabled(True)

    @Slot()
    def setupTransform(self):
        scale = pow(2.0, (self.zoomSlider.value() - 250) / 50.0)
        trans = QTransform()
        trans.scale(scale, scale)
        trans.rotate(self.rotateSlider.value())

        self.graphicsView.setTransform(trans)
        self.setResetButtonEnabled()

    @Slot()
    def togglePointerMode(self):
        self.graphicsView.setDragMode(
            QGraphicsView.RubberBandDrag if self.selectModeButton.isChecked() else QGraphicsView.ScrollHandDrag)
        self.graphicsView.setInteractive(self.selectModeButton.isChecked())

    @Slot()
    def toggleOpenGL(self):
        self.graphicsView.setViewport(
            QGLWidget(QGLFormat(QGL.SampleBuffers)) if self.openGlButton.isChecked() else QWidget())

    @Slot()
    def toggleAntialiasing(self):
        self.graphicsView.setRenderHint(QPainter.Antialiasing, self.antialiasButton.isChecked())

    @Slot()
    def rotateLeft(self):
        self.rotateSlider.setValue(self.rotateSlider.value() - 10)

    @Slot()
    def rotateRight(self):
        self.rotateSlider.setValue(self.rotateSlider.value() + 10)