Ejemplo n.º 1
0
 def paintEvent(self, event):
     if hasattr(self, "_update_dpi") and self._update_dpi():
         return  # matplotlib#19123 (<3.4).
     # We always repaint the full canvas (doing otherwise would require an
     # additional copy of the buffer into a contiguous block, so it's not
     # clear it would be faster).
     buf = _util.cairo_to_premultiplied_argb32(
         self.get_renderer()._get_buffer())
     height, width, _ = buf.shape
     # The image buffer is not necessarily contiguous, but the padding
     # in the ARGB32 case (each scanline is 32-bit aligned) happens to
     # match what QImage requires; in the RGBA128F case the documented Qt
     # requirement does not seem necessary?
     if QtGui.__name__.startswith("PyQt6"):
         from PyQt6 import sip
         ptr = sip.voidptr(buf)
     else:
         ptr = buf
     qimage = QtGui.QImage(ptr, width, height,
                           QtGui.QImage.Format(6))  # ARGB32_Premultiplied
     getattr(qimage, "setDevicePixelRatio",
             lambda _: None)(self.device_pixel_ratio)
     # https://bugreports.qt.io/browse/PYSIDE-140
     if (QtCore.__name__.startswith("PySide") and QtCore.__version_info__ <
         (5, 12)):
         ctypes.c_long.from_address(id(buf)).value -= 1
     painter = QtGui.QPainter(self)
     painter.eraseRect(self.rect())
     painter.drawImage(0, 0, qimage)
     self._draw_rect_callback(painter)
     painter.end()
Ejemplo n.º 2
0
    def __init__(self, parent: Optional[Any] = None) -> None:
        """ TODO: Write documentation.
        """
        # Initialize Qt widget
        super(QtWidgets.QWidget, self).__init__(parent=parent)

        # Initialize Panda3D app
        super(Panda3dViewer, self).__init__(window_type='offscreen')

        # Only accept focus by clicking on widget
        self.setFocusPolicy(Qt.ClickFocus)

        # Enable mouse control
        self.setMouseTracking(True)
        self._app.getMousePos = self.getMousePos
        self._app.taskMgr.add(self._app.move_orbital_camera_task,
                              "move_camera_task",
                              sort=2)

        # Create painter to render "screenshot" from panda3d
        self.paint_surface = QtGui.QPainter()

        # Start event loop
        self.clock = QtCore.QTimer()
        self.clock.setInterval(1000.0 / FRAMERATE)
        self.clock.timeout.connect(self.update)
        self.clock.start()