Commit f6307344 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Switching to relative imports to allow pyqtgraph to be imported under other names.

finished top-level files and graphicsItems
parent 34889108
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
from .Qt import QtCore, QtGui from .Qt import QtCore, QtGui
from .Point import Point from .Point import Point
import numpy as np import numpy as np
import pyqtgraph as pg
class SRTTransform(QtGui.QTransform): class SRTTransform(QtGui.QTransform):
"""Transform that can always be represented as a combination of 3 matrices: scale * rotate * translate """Transform that can always be represented as a combination of 3 matrices: scale * rotate * translate
...@@ -77,7 +76,7 @@ class SRTTransform(QtGui.QTransform): ...@@ -77,7 +76,7 @@ class SRTTransform(QtGui.QTransform):
self.update() self.update()
def setFromMatrix4x4(self, m): def setFromMatrix4x4(self, m):
m = pg.SRTTransform3D(m) m = SRTTransform3D(m)
angle, axis = m.getRotation() angle, axis = m.getRotation()
if angle != 0 and (axis[0] != 0 or axis[1] != 0 or axis[2] != 1): if angle != 0 and (axis[0] != 0 or axis[1] != 0 or axis[2] != 1):
print("angle: %s axis: %s" % (str(angle), str(axis))) print("angle: %s axis: %s" % (str(angle), str(axis)))
...@@ -256,4 +255,4 @@ if __name__ == '__main__': ...@@ -256,4 +255,4 @@ if __name__ == '__main__':
w1.sigRegionChanged.connect(update) w1.sigRegionChanged.connect(update)
#w2.sigRegionChanged.connect(update2) #w2.sigRegionChanged.connect(update2)
from .SRTTransform3D import SRTTransform3D
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from .Qt import QtCore, QtGui from .Qt import QtCore, QtGui
from .Vector import Vector from .Vector import Vector
from .SRTTransform import SRTTransform from .Transform3D import Transform3D
import pyqtgraph as pg from .Vector import Vector
import numpy as np import numpy as np
import scipy.linalg import scipy.linalg
class SRTTransform3D(pg.Transform3D): class SRTTransform3D(Transform3D):
"""4x4 Transform matrix that can always be represented as a combination of 3 matrices: scale * rotate * translate """4x4 Transform matrix that can always be represented as a combination of 3 matrices: scale * rotate * translate
This transform has no shear; angles are always preserved. This transform has no shear; angles are always preserved.
""" """
def __init__(self, init=None): def __init__(self, init=None):
pg.Transform3D.__init__(self) Transform3D.__init__(self)
self.reset() self.reset()
if init is None: if init is None:
return return
...@@ -44,14 +44,14 @@ class SRTTransform3D(pg.Transform3D): ...@@ -44,14 +44,14 @@ class SRTTransform3D(pg.Transform3D):
def getScale(self): def getScale(self):
return pg.Vector(self._state['scale']) return Vector(self._state['scale'])
def getRotation(self): def getRotation(self):
"""Return (angle, axis) of rotation""" """Return (angle, axis) of rotation"""
return self._state['angle'], pg.Vector(self._state['axis']) return self._state['angle'], Vector(self._state['axis'])
def getTranslation(self): def getTranslation(self):
return pg.Vector(self._state['pos']) return Vector(self._state['pos'])
def reset(self): def reset(self):
self._state = { self._state = {
...@@ -169,7 +169,7 @@ class SRTTransform3D(pg.Transform3D): ...@@ -169,7 +169,7 @@ class SRTTransform3D(pg.Transform3D):
def as2D(self): def as2D(self):
"""Return a QTransform representing the x,y portion of this transform (if possible)""" """Return a QTransform representing the x,y portion of this transform (if possible)"""
return pg.SRTTransform(self) return SRTTransform(self)
#def __div__(self, t): #def __div__(self, t):
#"""A / B == B^-1 * A""" #"""A / B == B^-1 * A"""
...@@ -202,11 +202,11 @@ class SRTTransform3D(pg.Transform3D): ...@@ -202,11 +202,11 @@ class SRTTransform3D(pg.Transform3D):
self.update() self.update()
def update(self): def update(self):
pg.Transform3D.setToIdentity(self) Transform3D.setToIdentity(self)
## modifications to the transform are multiplied on the right, so we need to reverse order here. ## modifications to the transform are multiplied on the right, so we need to reverse order here.
pg.Transform3D.translate(self, *self._state['pos']) Transform3D.translate(self, *self._state['pos'])
pg.Transform3D.rotate(self, self._state['angle'], *self._state['axis']) Transform3D.rotate(self, self._state['angle'], *self._state['axis'])
pg.Transform3D.scale(self, *self._state['scale']) Transform3D.scale(self, *self._state['scale'])
def __repr__(self): def __repr__(self):
return str(self.saveState()) return str(self.saveState())
...@@ -311,4 +311,4 @@ if __name__ == '__main__': ...@@ -311,4 +311,4 @@ if __name__ == '__main__':
w1.sigRegionChanged.connect(update) w1.sigRegionChanged.connect(update)
#w2.sigRegionChanged.connect(update2) #w2.sigRegionChanged.connect(update2)
from .SRTTransform import SRTTransform
\ No newline at end of file
from pyqtgraph.Qt import QtCore, QtGui from .Qt import QtCore, QtGui
class ThreadsafeTimer(QtCore.QObject): class ThreadsafeTimer(QtCore.QObject):
""" """
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from .Qt import QtCore, QtGui from .Qt import QtCore, QtGui
import pyqtgraph as pg from . import functions as fn
import numpy as np import numpy as np
class Transform3D(QtGui.QMatrix4x4): class Transform3D(QtGui.QMatrix4x4):
...@@ -26,7 +26,7 @@ class Transform3D(QtGui.QMatrix4x4): ...@@ -26,7 +26,7 @@ class Transform3D(QtGui.QMatrix4x4):
Extends QMatrix4x4.map() to allow mapping (3, ...) arrays of coordinates Extends QMatrix4x4.map() to allow mapping (3, ...) arrays of coordinates
""" """
if isinstance(obj, np.ndarray) and obj.ndim >= 2 and obj.shape[0] in (2,3): if isinstance(obj, np.ndarray) and obj.ndim >= 2 and obj.shape[0] in (2,3):
return pg.transformCoordinates(self, obj) return fn.transformCoordinates(self, obj)
else: else:
return QtGui.QMatrix4x4.map(self, obj) return QtGui.QMatrix4x4.map(self, obj)
......
import numpy as np import numpy as np
import scipy.interpolate import scipy.interpolate
from pyqtgraph.Qt import QtGui, QtCore from .Qt import QtGui, QtCore
class ColorMap(object): class ColorMap(object):
""" """
......
...@@ -24,7 +24,7 @@ SI_PREFIXES_ASCII = 'yzafpnum kMGTPEZY' ...@@ -24,7 +24,7 @@ SI_PREFIXES_ASCII = 'yzafpnum kMGTPEZY'
from .Qt import QtGui, QtCore, USE_PYSIDE from .Qt import QtGui, QtCore, USE_PYSIDE
import pyqtgraph as pg from . import getConfigOption, setConfigOptions
import numpy as np import numpy as np
import decimal, re import decimal, re
import ctypes import ctypes
...@@ -33,11 +33,11 @@ import sys, struct ...@@ -33,11 +33,11 @@ import sys, struct
try: try:
import scipy.ndimage import scipy.ndimage
HAVE_SCIPY = True HAVE_SCIPY = True
if pg.getConfigOption('useWeave'): if getConfigOption('useWeave'):
try: try:
import scipy.weave import scipy.weave
except ImportError: except ImportError:
pg.setConfigOptions(useWeave=False) setConfigOptions(useWeave=False)
except ImportError: except ImportError:
HAVE_SCIPY = False HAVE_SCIPY = False
...@@ -620,7 +620,7 @@ def rescaleData(data, scale, offset, dtype=None): ...@@ -620,7 +620,7 @@ def rescaleData(data, scale, offset, dtype=None):
dtype = np.dtype(dtype) dtype = np.dtype(dtype)
try: try:
if not pg.getConfigOption('useWeave'): if not getConfigOption('useWeave'):
raise Exception('Weave is disabled; falling back to slower version.') raise Exception('Weave is disabled; falling back to slower version.')
## require native dtype when using weave ## require native dtype when using weave
...@@ -647,10 +647,10 @@ def rescaleData(data, scale, offset, dtype=None): ...@@ -647,10 +647,10 @@ def rescaleData(data, scale, offset, dtype=None):
newData = newData.astype(dtype) newData = newData.astype(dtype)
data = newData.reshape(data.shape) data = newData.reshape(data.shape)
except: except:
if pg.getConfigOption('useWeave'): if getConfigOption('useWeave'):
if pg.getConfigOption('weaveDebug'): if getConfigOption('weaveDebug'):
debug.printExc("Error; disabling weave.") debug.printExc("Error; disabling weave.")
pg.setConfigOption('useWeave', False) setConfigOptions(useWeave=False)
#p = np.poly1d([scale, -offset*scale]) #p = np.poly1d([scale, -offset*scale])
#data = p(data).astype(dtype) #data = p(data).astype(dtype)
......
from pyqtgraph.Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
import pyqtgraph.functions as fn from .. import functions as fn
import numpy as np import numpy as np
__all__ = ['ArrowItem'] __all__ = ['ArrowItem']
......
from pyqtgraph.Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from pyqtgraph.python2_3 import asUnicode from ..python2_3 import asUnicode
import numpy as np import numpy as np
from pyqtgraph.Point import Point from ..Point import Point
import pyqtgraph.debug as debug from .. import debug as debug
import weakref import weakref
import pyqtgraph.functions as fn from .. import functions as fn
import pyqtgraph as pg from .. import getConfigOption
from .GraphicsWidget import GraphicsWidget from .GraphicsWidget import GraphicsWidget
__all__ = ['AxisItem'] __all__ = ['AxisItem']
...@@ -268,8 +268,8 @@ class AxisItem(GraphicsWidget): ...@@ -268,8 +268,8 @@ class AxisItem(GraphicsWidget):
def pen(self): def pen(self):
if self._pen is None: if self._pen is None:
return fn.mkPen(pg.getConfigOption('foreground')) return fn.mkPen(getConfigOption('foreground'))
return pg.mkPen(self._pen) return fn.mkPen(self._pen)
def setPen(self, pen): def setPen(self, pen):
""" """
...@@ -280,8 +280,8 @@ class AxisItem(GraphicsWidget): ...@@ -280,8 +280,8 @@ class AxisItem(GraphicsWidget):
self._pen = pen self._pen = pen
self.picture = None self.picture = None
if pen is None: if pen is None:
pen = pg.getConfigOption('foreground') pen = getConfigOption('foreground')
self.labelStyle['color'] = '#' + pg.colorStr(pg.mkPen(pen).color())[:6] self.labelStyle['color'] = '#' + fn.colorStr(fn.mkPen(pen).color())[:6]
self.setLabel() self.setLabel()
self.update() self.update()
......
import pyqtgraph as pg from ..Qt import QtGui, QtCore
from pyqtgraph.Qt import QtGui, QtCore
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
from .. import getConfigOption
from .. import functions as fn
import numpy as np import numpy as np
__all__ = ['BarGraphItem'] __all__ = ['BarGraphItem']
class BarGraphItem(GraphicsObject): class BarGraphItem(GraphicsObject):
...@@ -61,7 +63,7 @@ class BarGraphItem(GraphicsObject): ...@@ -61,7 +63,7 @@ class BarGraphItem(GraphicsObject):
pens = self.opts['pens'] pens = self.opts['pens']
if pen is None and pens is None: if pen is None and pens is None:
pen = pg.getConfigOption('foreground') pen = getConfigOption('foreground')
brush = self.opts['brush'] brush = self.opts['brush']
brushes = self.opts['brushes'] brushes = self.opts['brushes']
...@@ -112,13 +114,13 @@ class BarGraphItem(GraphicsObject): ...@@ -112,13 +114,13 @@ class BarGraphItem(GraphicsObject):
raise Exception('must specify either y1 or height') raise Exception('must specify either y1 or height')
height = y1 - y0 height = y1 - y0
p.setPen(pg.mkPen(pen)) p.setPen(fn.mkPen(pen))
p.setBrush(pg.mkBrush(brush)) p.setBrush(fn.mkBrush(brush))
for i in range(len(x0)): for i in range(len(x0)):
if pens is not None: if pens is not None:
p.setPen(pg.mkPen(pens[i])) p.setPen(fn.mkPen(pens[i]))
if brushes is not None: if brushes is not None:
p.setBrush(pg.mkBrush(brushes[i])) p.setBrush(fn.mkBrush(brushes[i]))
if np.isscalar(y0): if np.isscalar(y0):
y = y0 y = y0
......
from pyqtgraph.Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
__all__ = ['ButtonItem'] __all__ = ['ButtonItem']
......
from pyqtgraph.Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from . import ArrowItem from . import ArrowItem
import numpy as np import numpy as np
from pyqtgraph.Point import Point from ..Point import Point
import weakref import weakref
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
......
import pyqtgraph as pg from ..Qt import QtGui, QtCore
from pyqtgraph.Qt import QtGui, QtCore
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
from .. import getConfigOption
from .. import functions as fn
__all__ = ['ErrorBarItem'] __all__ = ['ErrorBarItem']
...@@ -121,8 +122,8 @@ class ErrorBarItem(GraphicsObject): ...@@ -121,8 +122,8 @@ class ErrorBarItem(GraphicsObject):
self.drawPath() self.drawPath()
pen = self.opts['pen'] pen = self.opts['pen']
if pen is None: if pen is None:
pen = pg.getConfigOption('foreground') pen = getConfigOption('foreground')
p.setPen(pg.mkPen(pen)) p.setPen(fn.mkPen(pen))
p.drawPath(self.path) p.drawPath(self.path)
def boundingRect(self): def boundingRect(self):
......
import pyqtgraph as pg from ..Qt import QtGui
from .. import functions as fn
class FillBetweenItem(pg.QtGui.QGraphicsPathItem): class FillBetweenItem(QtGui.QGraphicsPathItem):
""" """
GraphicsItem filling the space between two PlotDataItems. GraphicsItem filling the space between two PlotDataItems.
""" """
def __init__(self, p1, p2, brush=None): def __init__(self, p1, p2, brush=None):
pg.QtGui.QGraphicsPathItem.__init__(self) QtGui.QGraphicsPathItem.__init__(self)
self.p1 = p1 self.p1 = p1
self.p2 = p2 self.p2 = p2
p1.sigPlotChanged.connect(self.updatePath) p1.sigPlotChanged.connect(self.updatePath)
p2.sigPlotChanged.connect(self.updatePath) p2.sigPlotChanged.connect(self.updatePath)
if brush is not None: if brush is not None:
self.setBrush(pg.mkBrush(brush)) self.setBrush(fn.mkBrush(brush))
self.setZValue(min(p1.zValue(), p2.zValue())-1) self.setZValue(min(p1.zValue(), p2.zValue())-1)
self.updatePath() self.updatePath()
def updatePath(self): def updatePath(self):
p1 = self.p1.curve.path p1 = self.p1.curve.path
p2 = self.p2.curve.path p2 = self.p2.curve.path
path = pg.QtGui.QPainterPath() path = QtGui.QPainterPath()
path.addPolygon(p1.toSubpathPolygons()[0] + p2.toReversed().toSubpathPolygons()[0]) path.addPolygon(p1.toSubpathPolygons()[0] + p2.toReversed().toSubpathPolygons()[0])
self.setPath(path) self.setPath(path)
from pyqtgraph.Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from pyqtgraph.python2_3 import sortList from ..python2_3 import sortList
import pyqtgraph.functions as fn from .. import functions as fn
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
from .GraphicsWidget import GraphicsWidget from .GraphicsWidget import GraphicsWidget
import weakref import weakref
from pyqtgraph.pgcollections import OrderedDict from ..pgcollections import OrderedDict
from pyqtgraph.colormap import ColorMap from ..colormap import ColorMap
import numpy as np import numpy as np
......
from pyqtgraph.Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from .UIGraphicsItem import * from .UIGraphicsItem import *
import pyqtgraph.functions as fn from .. import functions as fn
__all__ = ['GradientLegend'] __all__ = ['GradientLegend']
......
from .. import functions as fn from .. import functions as fn
from .GraphicsObject import GraphicsObject from .GraphicsObject import GraphicsObject
from .ScatterPlotItem import ScatterPlotItem from .ScatterPlotItem import ScatterPlotItem
import pyqtgraph as pg from ..Qt import QtGui, QtCore
import numpy as np import numpy as np
__all__ = ['GraphItem'] __all__ = ['GraphItem']
...@@ -71,11 +71,11 @@ class GraphItem(GraphicsObject): ...@@ -71,11 +71,11 @@ class GraphItem(GraphicsObject):
self.picture = None self.picture = None
def generatePicture(self): def generatePicture(self):
self.picture = pg.QtGui.QPicture() self.picture = QtGui.QPicture()
if self.pen is None or self.pos is None or self.adjacency is None: if self.pen is None or self.pos is None or self.adjacency is None:
return return
p = pg.QtGui.QPainter(self.picture) p = QtGui.QPainter(self.picture)
try: try:
pts = self.pos[self.adjacency] pts = self.pos[self.adjacency]
pen = self.pen pen = self.pen
...@@ -86,14 +86,14 @@ class GraphItem(GraphicsObject): ...@@ -86,14 +86,14 @@ class GraphItem(GraphicsObject):
if np.any(pen != lastPen): if np.any(pen != lastPen):
lastPen = pen lastPen = pen
if pen.dtype.fields is None: if pen.dtype.fields is None:
p.setPen(pg.mkPen(color=(pen[0], pen[1], pen[2], pen[3]), width=1)) p.setPen(fn.mkPen(color=(pen[0], pen[1], pen[2], pen[3]), width=1))
else: else:
p.setPen(pg.mkPen(color=(pen['red'], pen['green'], pen['blue'], pen['alpha']), width=pen['width'])) p.setPen(fn.mkPen(color=(pen['red'], pen['green'], pen['blue'], pen['alpha']), width=pen['width']))
p.drawLine(pg.QtCore.QPointF(*pts[i][0]), pg.QtCore.QPointF(*pts[i][1])) p.drawLine(QtCore.QPointF(*pts[i][0]), QtCore.QPointF(*pts[i][1]))
else: else:
if pen == 'default': if pen == 'default':
pen = pg.getConfigOption('foreground') pen = getConfigOption('foreground')
p.setPen(pg.mkPen(pen)) p.setPen(fn.mkPen(pen))
pts = pts.reshape((pts.shape[0]*pts.shape[1], pts.shape[2])) pts = pts.reshape((pts.shape[0]*pts.shape[1], pts.shape[2]))
path = fn.arrayToQPath(x=pts[:,0], y=pts[:,1], connect='pairs') path = fn.arrayToQPath(x=pts[:,0], y=pts[:,1], connect='pairs')
p.drawPath(path) p.drawPath(path)
...@@ -103,7 +103,7 @@ class GraphItem(GraphicsObject): ...@@ -103,7 +103,7 @@ class GraphItem(GraphicsObject):
def paint(self, p, *args): def paint(self, p, *args):
if self.picture == None: if self.picture == None:
self.generatePicture() self.generatePicture()
if pg.getConfigOption('antialias') is True: if getConfigOption('antialias') is True:
p.setRenderHint(p.Antialiasing) p.setRenderHint(p.Antialiasing)
self.picture.play(p) self.picture.play(p)
......
from pyqtgraph.Qt import QtGui, QtCore from ..Qt import QtGui, QtCore
from pyqtgraph.GraphicsScene import GraphicsScene from ..GraphicsScene import GraphicsScene
from pyqtgraph.Point import Point from ..Point import Point
import pyqtgraph.functions as fn from .. import functions as fn
import weakref import weakref
from pyqtgraph.pgcollections import OrderedDict from ..pgcollections import OrderedDict
import operator, sys import operator, sys
class FiniteCache(OrderedDict): class FiniteCache(OrderedDict):
......