minor code cleanups
pyside-specific bugfixes (there is still one pyside bug for which I have no workaround: https://bugreports.qt-project.org/browse/PYSIDE-86)
This commit is contained in:
commit
3fc741abdc
@ -13,10 +13,13 @@ from .mouseEvents import *
|
||||
import pyqtgraph.debug as debug
|
||||
from . import exportDialog
|
||||
|
||||
try:
|
||||
if hasattr(QtCore, 'PYQT_VERSION'):
|
||||
try:
|
||||
import sip
|
||||
HAVE_SIP = True
|
||||
except:
|
||||
except ImportError:
|
||||
HAVE_SIP = False
|
||||
else:
|
||||
HAVE_SIP = False
|
||||
|
||||
|
||||
|
@ -193,7 +193,10 @@ show = image ## for backward compatibility
|
||||
|
||||
def mkQApp():
|
||||
global QAPP
|
||||
if QtGui.QApplication.instance() is None:
|
||||
inst = QtGui.QApplication.instance()
|
||||
if inst is None:
|
||||
QAPP = QtGui.QApplication([])
|
||||
else:
|
||||
QAPP = inst
|
||||
return QAPP
|
||||
|
||||
|
@ -8,11 +8,7 @@ from . import functions
|
||||
from .common import *
|
||||
import numpy as np
|
||||
|
||||
try:
|
||||
import metaarray
|
||||
HAVE_METAARRAY = True
|
||||
except:
|
||||
HAVE_METAARRAY = False
|
||||
import pyqtgraph.metaarray as metaarray
|
||||
|
||||
|
||||
class Downsample(CtrlNode):
|
||||
@ -145,11 +141,11 @@ class Derivative(CtrlNode):
|
||||
nodeName = 'DerivativeFilter'
|
||||
|
||||
def processData(self, data):
|
||||
if HAVE_METAARRAY and (hasattr(data, 'implements') and data.implements('MetaArray')):
|
||||
if hasattr(data, 'implements') and data.implements('MetaArray'):
|
||||
info = data.infoCopy()
|
||||
if 'values' in info[0]:
|
||||
info[0]['values'] = info[0]['values'][:-1]
|
||||
return MetaArray(data[1:] - data[:-1], info=info)
|
||||
return metaarray.MetaArray(data[1:] - data[:-1], info=info)
|
||||
else:
|
||||
return data[1:] - data[:-1]
|
||||
|
||||
|
@ -15,12 +15,21 @@ class GraphicsItem(object):
|
||||
The GraphicsView system places a lot of emphasis on the notion that the graphics within the scene should be device independent--you should be able to take the same graphics and display them on screens of different resolutions, printers, export to SVG, etc. This is nice in principle, but causes me a lot of headache in practice. It means that I have to circumvent all the device-independent expectations any time I want to operate in pixel coordinates rather than arbitrary scene coordinates. A lot of the code in GraphicsItem is devoted to this task--keeping track of view widgets and device transforms, computing the size and shape of a pixel in local item coordinates, etc. Note that in item coordinates, a pixel does not have to be square or even rectangular, so just asking how to increase a bounding rect by 2px can be a rather complex task.
|
||||
"""
|
||||
def __init__(self, register=True):
|
||||
if not hasattr(self, '_qtBaseClass'):
|
||||
for b in self.__class__.__bases__:
|
||||
if issubclass(b, QtGui.QGraphicsItem):
|
||||
self.__class__._qtBaseClass = b
|
||||
break
|
||||
if not hasattr(self, '_qtBaseClass'):
|
||||
raise Exception('Could not determine Qt base class for GraphicsItem: %s' % str(self))
|
||||
|
||||
self._viewWidget = None
|
||||
self._viewBox = None
|
||||
self._connectedView = None
|
||||
if register:
|
||||
GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items()
|
||||
|
||||
|
||||
def getViewWidget(self):
|
||||
"""
|
||||
Return the view widget for this item. If the scene has multiple views, only the first view is returned.
|
||||
@ -76,7 +85,7 @@ class GraphicsItem(object):
|
||||
if view is None:
|
||||
return None
|
||||
viewportTransform = view.viewportTransform()
|
||||
dt = QtGui.QGraphicsObject.deviceTransform(self, viewportTransform)
|
||||
dt = self._qtBaseClass.deviceTransform(self, viewportTransform)
|
||||
|
||||
#xmag = abs(dt.m11())+abs(dt.m12())
|
||||
#ymag = abs(dt.m21())+abs(dt.m22())
|
||||
@ -274,19 +283,26 @@ class GraphicsItem(object):
|
||||
return vt.mapRect(obj)
|
||||
|
||||
def pos(self):
|
||||
return Point(QtGui.QGraphicsObject.pos(self))
|
||||
return Point(self._qtBaseClass.pos(self))
|
||||
|
||||
def viewPos(self):
|
||||
return self.mapToView(self.mapFromParent(self.pos()))
|
||||
|
||||
def parentItem(self):
|
||||
## PyQt bug -- some items are returned incorrectly.
|
||||
return GraphicsScene.translateGraphicsItem(QtGui.QGraphicsObject.parentItem(self))
|
||||
return GraphicsScene.translateGraphicsItem(self._qtBaseClass.parentItem(self))
|
||||
|
||||
def setParentItem(self, parent):
|
||||
## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616
|
||||
if parent is not None:
|
||||
pscene = parent.scene()
|
||||
if pscene is not None and self.scene() is not pscene:
|
||||
pscene.addItem(self)
|
||||
return self._qtBaseClass.setParentItem(self, parent)
|
||||
|
||||
def childItems(self):
|
||||
## PyQt bug -- some child items are returned incorrectly.
|
||||
return list(map(GraphicsScene.translateGraphicsItem, QtGui.QGraphicsObject.childItems(self)))
|
||||
return list(map(GraphicsScene.translateGraphicsItem, self._qtBaseClass.childItems(self)))
|
||||
|
||||
|
||||
def sceneTransform(self):
|
||||
@ -296,7 +312,7 @@ class GraphicsItem(object):
|
||||
if self.scene() is None:
|
||||
return self.transform()
|
||||
else:
|
||||
return QtGui.QGraphicsObject.sceneTransform(self)
|
||||
return self._qtBaseClass.sceneTransform(self)
|
||||
|
||||
|
||||
def transformAngle(self, relativeItem=None):
|
||||
@ -315,7 +331,7 @@ class GraphicsItem(object):
|
||||
|
||||
|
||||
#def itemChange(self, change, value):
|
||||
#ret = QtGui.QGraphicsObject.itemChange(self, change, value)
|
||||
#ret = self._qtBaseClass.itemChange(self, change, value)
|
||||
#if change == self.ItemParentHasChanged or change == self.ItemSceneHasChanged:
|
||||
#print "Item scene changed:", self
|
||||
#self.setChildScene(self) ## This is bizarre.
|
||||
|
@ -8,6 +8,7 @@ class GraphicsObject(GraphicsItem, QtGui.QGraphicsObject):
|
||||
|
||||
Extension of QGraphicsObject with some useful methods (provided by :class:`GraphicsItem <pyqtgraph.graphicsItems.GraphicsItem>`)
|
||||
"""
|
||||
_qtBaseClass = QtGui.QGraphicsObject
|
||||
def __init__(self, *args):
|
||||
QtGui.QGraphicsObject.__init__(self, *args)
|
||||
GraphicsItem.__init__(self)
|
||||
@ -17,13 +18,3 @@ class GraphicsObject(GraphicsItem, QtGui.QGraphicsObject):
|
||||
if change in [self.ItemParentHasChanged, self.ItemSceneHasChanged]:
|
||||
self._updateView()
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
def setParentItem(self, parent):
|
||||
## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616
|
||||
if parent is not None:
|
||||
pscene = parent.scene()
|
||||
if pscene is not None and self.scene() is not pscene:
|
||||
pscene.addItem(self)
|
||||
return QtGui.QGraphicsObject.setParentItem(self, parent)
|
||||
|
@ -5,6 +5,8 @@ from .GraphicsItem import GraphicsItem
|
||||
__all__ = ['GraphicsWidget']
|
||||
|
||||
class GraphicsWidget(GraphicsItem, QtGui.QGraphicsWidget):
|
||||
|
||||
_qtBaseClass = QtGui.QGraphicsWidget
|
||||
def __init__(self, *args, **kargs):
|
||||
"""
|
||||
**Bases:** :class:`GraphicsItem <pyqtgraph.GraphicsItem>`, :class:`QtGui.QGraphicsWidget`
|
||||
@ -14,7 +16,9 @@ class GraphicsWidget(GraphicsItem, QtGui.QGraphicsWidget):
|
||||
"""
|
||||
QtGui.QGraphicsWidget.__init__(self, *args, **kargs)
|
||||
GraphicsItem.__init__(self)
|
||||
GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items()
|
||||
|
||||
## done by GraphicsItem init
|
||||
#GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items()
|
||||
|
||||
## Removed because this causes segmentation faults. Don't know why.
|
||||
# def itemChange(self, change, value):
|
||||
@ -52,11 +56,3 @@ class GraphicsWidget(GraphicsItem, QtGui.QGraphicsWidget):
|
||||
return p
|
||||
|
||||
|
||||
|
||||
def setParentItem(self, parent):
|
||||
## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616
|
||||
if parent is not None:
|
||||
pscene = parent.scene()
|
||||
if pscene is not None and self.scene() is not pscene:
|
||||
pscene.addItem(self)
|
||||
return QtGui.QGraphicsObject.setParentItem(self, parent)
|
||||
|
@ -36,7 +36,7 @@ for k, c in coords.items():
|
||||
def makeSymbolPixmap(size, pen, brush, symbol):
|
||||
## Render a spot with the given parameters to a pixmap
|
||||
penPxWidth = max(np.ceil(pen.width()), 1)
|
||||
image = QtGui.QImage(size+penPxWidth, size+penPxWidth, QtGui.QImage.Format_ARGB32_Premultiplied)
|
||||
image = QtGui.QImage(int(size+penPxWidth), int(size+penPxWidth), QtGui.QImage.Format_ARGB32_Premultiplied)
|
||||
image.fill(0)
|
||||
p = QtGui.QPainter(image)
|
||||
p.setRenderHint(p.Antialiasing)
|
||||
|
Loading…
Reference in New Issue
Block a user