Beispiel #1
0
    def __init__(self, document: Optional[vp.Document] = None, parent=None):
        """Constructor.
        Args:
            document: the document to display
            parent: QWidget parent
        """
        fmt = QGLFormat()
        fmt.setVersion(3, 3)
        fmt.setProfile(QGLFormat.CoreProfile)
        fmt.setSampleBuffers(True)
        super().__init__(fmt, parent=parent)

        self.setMouseTracking(True)

        self._document = document

        self._last_mouse_x = 0.0
        self._last_mouse_y = 0.0
        self._mouse_drag = False

        # deferred initialization in initializeGL()
        self._ctx: Optional[mgl.Context] = None
        self._screen = None
        self.engine = Engine(view_mode=ViewMode.OUTLINE,
                             show_pen_up=False,
                             render_cb=self.update)

        # adjust default scale based on hidpi
        self.engine.scale = self.window().devicePixelRatio()
Beispiel #2
0
 def __init__(self, renderer, title):
     QApplication.__init__(self, sys.argv)
     self.window = QMainWindow()
     self.window.setWindowTitle(title)
     self.window.resize(800,600)
     # Get OpenGL 4.1 context
     glformat = QGLFormat()
     glformat.setVersion(4, 1)
     glformat.setProfile(QGLFormat.CoreProfile)
     glformat.setDoubleBuffer(False)
     self.glwidget = MyGlWidget(renderer, glformat, self)
     self.window.setCentralWidget(self.glwidget)
     self.window.show()
Beispiel #3
0
    def __init__(self, document: Optional[vp.Document] = None, parent=None):
        """Constructor.
        Args:
            document: the document to display
            parent: QWidget parent
        """
        fmt = QGLFormat()
        fmt.setVersion(3, 3)
        fmt.setProfile(QGLFormat.CoreProfile)
        fmt.setSampleBuffers(True)
        super().__init__(fmt, parent=parent)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.setMouseTracking(True)

        self._document = document

        self._last_mouse_x = 0.0
        self._last_mouse_y = 0.0
        self._mouse_drag = False
        self._factor = 1.0

        # deferred initialization in initializeGL()
        self._ctx: Optional[mgl.Context] = None
        self._screen = None
        self.engine = Engine(view_mode=ViewMode.OUTLINE,
                             show_pen_up=False,
                             render_cb=self.update)

        self.windowHandle().screenChanged.connect(self.on_screen_changed)

        # print diagnostic information
        screen = self.screen()
        logging.info(f"QScreen info: pixelRatio={screen.devicePixelRatio()}, "
                     f"physicalSize={screen.physicalSize().toTuple()}, "
                     f"physicalDotsPerInch={screen.physicalDotsPerInch()}, "
                     f"virtualSize={screen.virtualSize().toTuple()}, "
                     f"size={screen.size().toTuple()}, "
                     f"logicalDotsPerInch={screen.logicalDotsPerInch()}, ")
Beispiel #4
0
# -*- coding: utf-8 -*-
"""
Created on Mon Jun  3 15:20:33 2019

@author: aluo
"""
import mainGUI
from PySide2.QtWidgets import QApplication
from PySide2.QtOpenGL import QGLFormat
import sys

if __name__ == "__main__":
    app = QApplication(sys.argv)
    gl_format = QGLFormat()
    gl_format.setVersion(3, 3)
    gl_format.setProfile(QGLFormat.CoreProfile)
    gl_format.setSampleBuffers(True)
    main_gui = mainGUI.MainGui()
    main_gui.show()
    sys.exit(app.exec_())
Beispiel #5
0
    def __init__(self, name: str, parent: QWidget = None):
        QFrame.__init__(self, parent)

        self.setFrameShape(QFrame.Shape(QFrame.Sunken | QFrame.StyledPanel))
        self.graphicsView = GraphicsView(self)
        self.graphicsView.setRenderHint(QPainter.Antialiasing, False)
        self.graphicsView.setDragMode(QGraphicsView.RubberBandDrag)
        self.graphicsView.setOptimizationFlag(
            QGraphicsView.DontSavePainterState)
        self.graphicsView.setViewportUpdateMode(
            QGraphicsView.SmartViewportUpdate)
        self.graphicsView.setTransformationAnchor(
            QGraphicsView.AnchorUnderMouse)

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

        self.zoomInIcon = QToolButton()
        self.zoomInIcon.setAutoRepeat(True)
        self.zoomInIcon.setAutoRepeatInterval(33)
        self.zoomInIcon.setAutoRepeatDelay(0)
        self.zoomInIcon.setIcon(QIcon(":/zoomin.png"))
        self.zoomInIcon.setIconSize(iconSize)
        self.zoomOutIcon = QToolButton()
        self.zoomOutIcon.setAutoRepeat(True)
        self.zoomOutIcon.setAutoRepeatInterval(33)
        self.zoomOutIcon.setAutoRepeatDelay(0)
        self.zoomOutIcon.setIcon(QIcon(":/zoomout.png"))
        self.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(self.zoomInIcon)
        zoomSliderLayout.addWidget(self.zoomSlider)
        zoomSliderLayout.addWidget(self.zoomOutIcon)

        self.rotateLeftIcon = QToolButton()
        self.rotateLeftIcon.setIcon(QIcon(":/rotateleft.png"))
        self.rotateLeftIcon.setIconSize(iconSize)
        self.rotateRightIcon = QToolButton()
        self.rotateRightIcon.setIcon(QIcon(":/rotateright.png"))
        self.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(self.rotateLeftIcon)
        rotateSliderLayout.addWidget(self.rotateSlider)
        rotateSliderLayout.addWidget(self.rotateRightIcon)

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

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

        pointerModeGroup = QButtonGroup(self)
        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)
        labelLayout.addWidget(self.printButton)

        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.setupMatrix)
        self.rotateSlider.valueChanged.connect(self.setupMatrix)
        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)
        self.rotateLeftIcon.clicked.connect(self.rotateLeft)
        self.rotateRightIcon.clicked.connect(self.rotateRight)
        self.zoomInIcon.clicked.connect(self.zoomIn)
        self.zoomOutIcon.clicked.connect(self.zoomOut)
        self.printButton.clicked.connect(self.print)

        self.setupMatrix()
Beispiel #6
0
 def toggleOpenGL(self):
     self.graphicsView.setViewport(
         QGLWidget(QGLFormat(QGL.SampleBuffers)) if self.openGlButton.
         isChecked() else QWidget())