Skip to content

Commit

Permalink
Dropped support for Qt < 5 (remaining things)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Oct 30, 2023
1 parent dc7b0e4 commit 2009a6b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 60 deletions.
32 changes: 12 additions & 20 deletions qwt/painter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
from qwt.color_map import QwtColorMap
from qwt.scale_map import QwtScaleMap

QT_MAJOR_VERSION = int(QC.__version__.split(".")[0])

QWIDGETSIZE_MAX = (1 << 24) - 1


Expand Down Expand Up @@ -443,25 +441,19 @@ def backingStore(self, widget, size):
:param QSize size: Size of the pixmap
:return: A pixmap that can be used as backing store
"""
if QT_MAJOR_VERSION >= 5:
pixelRatio = 1.0
if widget and widget.windowHandle():
pixelRatio = widget.windowHandle().devicePixelRatio()
else:
from qtpy.QtGui import qApp

if qApp is not None:
try:
pixelRatio = qApp.devicePixelRatio()
except RuntimeError:
pass
pm = QPixmap(size * pixelRatio)
pm.setDevicePixelRatio(pixelRatio)
pixelRatio = 1.0
if widget and widget.windowHandle():
pixelRatio = widget.windowHandle().devicePixelRatio()
else:
pm = QPixmap(size)
if QT_MAJOR_VERSION < 5 and widget and isX11GraphicsSystem():
if pm.x11Info().screen() != widget.x11Info().screen():
pm.x11SetScreen(widget.x11Info().screen())
from qtpy.QtGui import qApp

if qApp is not None:
try:
pixelRatio = qApp.devicePixelRatio()
except RuntimeError:
pass
pm = QPixmap(size * pixelRatio)
pm.setDevicePixelRatio(pixelRatio)
return pm


Expand Down
12 changes: 2 additions & 10 deletions qwt/plot_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import os

from qtpy import QtCore as QC
from qtpy.QtCore import QEvent, QPointF, QRect, QRectF, QSizeF, Qt
from qtpy.QtGui import (
QBrush,
Expand All @@ -35,7 +34,6 @@
from qwt.null_paintdevice import QwtNullPaintDevice
from qwt.painter import QwtPainter

QT_MAJOR_VERSION = int(QC.__version__.split(".")[0])
QT_API = os.environ["QT_API"]


Expand Down Expand Up @@ -491,10 +489,7 @@ def setPaintAttribute(self, attribute, on=True):
if self.__data.backingStore is None:
self.__data.backingStore = QPixmap()
if self.isVisible():
if QT_MAJOR_VERSION >= 5:
self.__data.backingStore = self.grab(self.rect())
else:
self.__data.backingStore = QPixmap.grabWidget(self, self.rect())
self.__data.backingStore = self.grab(self.rect())
else:
self.__data.backingStore = None
elif attribute == self.Opaque:
Expand Down Expand Up @@ -593,10 +588,7 @@ def paintEvent(self, event):
and self.__data.backingStore is not None
):
bs = self.__data.backingStore
if QT_MAJOR_VERSION >= 5:
pixelRatio = bs.devicePixelRatio()
else:
pixelRatio = 1.0
pixelRatio = bs.devicePixelRatio()
if bs.size() != self.size() * pixelRatio:
bs = QwtPainter.backingStore(self, self.size())
if self.testAttribute(Qt.WA_StyledBackground):
Expand Down
13 changes: 2 additions & 11 deletions qwt/plot_directpainter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
:members:
"""

from qtpy.QtCore import QEvent, QObject, Qt
from qtpy.QtGui import QPainter, QRegion
from qtpy.QtCore import QObject, Qt, QEvent
from qtpy import QtCore as QC

QT_MAJOR_VERSION = int(QC.__version__.split(".")[0])

from qwt.plot import QwtPlotItem
from qwt.plot_canvas import QwtPlotCanvas
Expand Down Expand Up @@ -222,13 +219,7 @@ def drawSeries(self, seriesItem, from_, to):
if self.testAttribute(self.FullRepaint):
plotCanvas.repaint()
return
immediatePaint = True
if not canvas.testAttribute(Qt.WA_WState_InPaintEvent):
if QT_MAJOR_VERSION >= 5 or not canvas.testAttribute(
Qt.WA_PaintOutsidePaintEvent
):
immediatePaint = False
if immediatePaint:
if canvas.testAttribute(Qt.WA_WState_InPaintEvent):
if not self.__data.painter.isActive():
self.reset()
self.__data.painter.begin(canvas)
Expand Down
10 changes: 3 additions & 7 deletions qwt/qthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

"""Qt helpers"""

import os.path as osp
import os
import os.path as osp

from qtpy import QtCore as QC
from qtpy import QtGui as QG
from qtpy import QtWidgets as QW
from qtpy import QtCore as QC


QT_API = os.environ["QT_API"]

Expand Down Expand Up @@ -48,10 +47,7 @@ def take_screenshot(widget, path, size=None, quit=True):
widget.resize(*size)
widget.show()
QW.QApplication.processEvents()
if QT_API in ("pyqt4", "pyside2"):
pixmap = QG.QPixmap.grabWidget(widget)
else:
pixmap = widget.grab()
pixmap = widget.grab()
pixmap.save(path)
if quit:
QC.QTimer.singleShot(0, QW.QApplication.instance().quit)
21 changes: 9 additions & 12 deletions qwt/tests/test_eventfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
SHOW = True # Show test in GUI-based test launcher

import os
import numpy as np

from qtpy.QtWidgets import QApplication, QWidget, QMainWindow, QToolBar, QWhatsThis
from qtpy.QtGui import QPen, QBrush, QColor, QPainter, QPixmap
from qtpy.QtCore import QSize, QEvent, Signal, QRect, QObject, Qt, QPoint
import numpy as np
from qtpy.QtCore import QEvent, QObject, QPoint, QRect, QSize, Qt, Signal
from qtpy.QtGui import QBrush, QColor, QPainter, QPen, QPixmap
from qtpy.QtWidgets import QApplication, QMainWindow, QToolBar, QWhatsThis, QWidget

from qwt import (
QwtPlot,
QwtScaleDraw,
QwtSymbol,
QwtPlotGrid,
QwtPlotCurve,
QwtPlotCanvas,
QwtPlotCurve,
QwtPlotGrid,
QwtScaleDiv,
QwtScaleDraw,
QwtSymbol,
)
from qwt.tests import utils

Expand Down Expand Up @@ -67,10 +67,7 @@ def dark(self):

def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
if QT_API in ("pyqt4", "pyside2"):
pm = QPixmap.grabWidget(self)
else:
pm = self.grab()
pm = self.grab()
color = QColor()
color.setRgb(pm.toImage().pixel(event.x(), event.y()))
self.colorSelected.emit(color)
Expand Down

0 comments on commit 2009a6b

Please sign in to comment.