exporters, multiprocess, opengl

This commit is contained in:
Luke Campagnola 2013-12-23 09:46:54 -05:00
parent a2e8290d8e
commit 7777240d89
23 changed files with 74 additions and 118 deletions

View File

@ -1,8 +1,7 @@
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from ..Qt import QtGui, QtCore
from .Exporter import Exporter
from pyqtgraph.parametertree import Parameter
from ..parametertree import Parameter
from .. import PlotItem
__all__ = ['CSVExporter']
@ -22,7 +21,7 @@ class CSVExporter(Exporter):
def export(self, fileName=None):
if not isinstance(self.item, pg.PlotItem):
if not isinstance(self.item, PlotItem):
raise Exception("Must have a PlotItem selected for CSV export.")
if fileName is None:

View File

@ -1,7 +1,7 @@
from pyqtgraph.widgets.FileDialog import FileDialog
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore, QtSvg
from pyqtgraph.python2_3 import asUnicode
from ..widgets.FileDialog import FileDialog
from ..Qt import QtGui, QtCore, QtSvg
from ..python2_3 import asUnicode
from ..GraphicsScene import GraphicsScene
import os, re
LastExportDirectory = None
@ -77,20 +77,20 @@ class Exporter(object):
self.export(fileName=fileName, **self.fileDialog.opts)
def getScene(self):
if isinstance(self.item, pg.GraphicsScene):
if isinstance(self.item, GraphicsScene):
return self.item
else:
return self.item.scene()
def getSourceRect(self):
if isinstance(self.item, pg.GraphicsScene):
if isinstance(self.item, GraphicsScene):
w = self.item.getViewWidget()
return w.viewportTransform().inverted()[0].mapRect(w.rect())
else:
return self.item.sceneBoundingRect()
def getTargetRect(self):
if isinstance(self.item, pg.GraphicsScene):
if isinstance(self.item, GraphicsScene):
return self.item.getViewWidget().rect()
else:
return self.item.mapRectToDevice(self.item.boundingRect())

View File

@ -1,7 +1,7 @@
from .Exporter import Exporter
from pyqtgraph.parametertree import Parameter
from pyqtgraph.Qt import QtGui, QtCore, QtSvg, USE_PYSIDE
import pyqtgraph as pg
from ..parametertree import Parameter
from ..Qt import QtGui, QtCore, QtSvg, USE_PYSIDE\
from .. import functions as fn
import numpy as np
__all__ = ['ImageExporter']
@ -73,7 +73,7 @@ class ImageExporter(Exporter):
bg[:,:,1] = color.green()
bg[:,:,2] = color.red()
bg[:,:,3] = color.alpha()
self.png = pg.makeQImage(bg, alpha=True)
self.png = fn.makeQImage(bg, alpha=True)
## set resolution of image:
origTargetRect = self.getTargetRect()

View File

@ -1,7 +1,7 @@
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from ..Qt import QtGui, QtCore
from .Exporter import Exporter
from .. import PlotItem
from .. import functions as fn
__all__ = ['MatplotlibExporter']
@ -17,7 +17,7 @@ class MatplotlibExporter(Exporter):
def export(self, fileName=None):
if isinstance(self.item, pg.PlotItem):
if isinstance(self.item, PlotItem):
mpw = MatplotlibWindow()
MatplotlibExporter.windows.append(mpw)
fig = mpw.getFigure()
@ -29,23 +29,23 @@ class MatplotlibExporter(Exporter):
for item in self.item.curves:
x, y = item.getData()
opts = item.opts
pen = pg.mkPen(opts['pen'])
pen = fn.mkPen(opts['pen'])
if pen.style() == QtCore.Qt.NoPen:
linestyle = ''
else:
linestyle = '-'
color = tuple([c/255. for c in pg.colorTuple(pen.color())])
color = tuple([c/255. for c in fn.colorTuple(pen.color())])
symbol = opts['symbol']
if symbol == 't':
symbol = '^'
symbolPen = pg.mkPen(opts['symbolPen'])
symbolBrush = pg.mkBrush(opts['symbolBrush'])
markeredgecolor = tuple([c/255. for c in pg.colorTuple(symbolPen.color())])
markerfacecolor = tuple([c/255. for c in pg.colorTuple(symbolBrush.color())])
symbolPen = fn.mkPen(opts['symbolPen'])
symbolBrush = fn.mkBrush(opts['symbolBrush'])
markeredgecolor = tuple([c/255. for c in fn.colorTuple(symbolPen.color())])
markerfacecolor = tuple([c/255. for c in fn.colorTuple(symbolBrush.color())])
if opts['fillLevel'] is not None and opts['fillBrush'] is not None:
fillBrush = pg.mkBrush(opts['fillBrush'])
fillcolor = tuple([c/255. for c in pg.colorTuple(fillBrush.color())])
fillBrush = fn.mkBrush(opts['fillBrush'])
fillcolor = tuple([c/255. for c in fn.colorTuple(fillBrush.color())])
ax.fill_between(x=x, y1=y, y2=opts['fillLevel'], facecolor=fillcolor)
ax.plot(x, y, marker=symbol, color=color, linewidth=pen.width(), linestyle=linestyle, markeredgecolor=markeredgecolor, markerfacecolor=markerfacecolor)
@ -62,7 +62,7 @@ MatplotlibExporter.register()
class MatplotlibWindow(QtGui.QMainWindow):
def __init__(self):
import pyqtgraph.widgets.MatplotlibWidget
from .. import widgets.MatplotlibWidget
QtGui.QMainWindow.__init__(self)
self.mpl = pyqtgraph.widgets.MatplotlibWidget.MatplotlibWidget()
self.setCentralWidget(self.mpl)

View File

@ -1,6 +1,6 @@
from .Exporter import Exporter
from pyqtgraph.parametertree import Parameter
from pyqtgraph.Qt import QtGui, QtCore, QtSvg
from ..parametertree import Parameter
from ..Qt import QtGui, QtCore, QtSvg
import re
__all__ = ['PrintExporter']

View File

@ -1,8 +1,9 @@
from .Exporter import Exporter
from pyqtgraph.python2_3 import asUnicode
from pyqtgraph.parametertree import Parameter
from pyqtgraph.Qt import QtGui, QtCore, QtSvg
import pyqtgraph as pg
from ..python2_3 import asUnicode
from ..parametertree import Parameter
from ..Qt import QtGui, QtCore, QtSvg
from .. import debug
from .. import functions as fn
import re
import xml.dom.minidom as xml
import numpy as np
@ -156,7 +157,7 @@ def _generateItemSvg(item, nodes=None, root=None):
##
## Both 2 and 3 can be addressed by drawing all items in world coordinates.
profiler = pg.debug.Profiler()
profiler = debug.Profiler()
if nodes is None: ## nodes maps all node IDs to their XML element.
## this allows us to ensure all elements receive unique names.
@ -196,17 +197,12 @@ def _generateItemSvg(item, nodes=None, root=None):
tr2 = QtGui.QTransform()
tr2.translate(-rootPos.x(), -rootPos.y())
tr = tr * tr2
#print item, pg.SRTTransform(tr)
#tr.translate(item.pos().x(), item.pos().y())
#tr = tr * item.transform()
arr = QtCore.QByteArray()
buf = QtCore.QBuffer(arr)
svg = QtSvg.QSvgGenerator()
svg.setOutputDevice(buf)
dpi = QtGui.QDesktopWidget().physicalDpiX()
### not really sure why this works, but it seems to be important:
#self.svg.setSize(QtCore.QSize(self.params['width']*dpi/90., self.params['height']*dpi/90.))
svg.setResolution(dpi)
p = QtGui.QPainter()
@ -350,7 +346,7 @@ def correctCoordinates(node, item):
if ch.tagName == 'polyline':
removeTransform = True
coords = np.array([[float(a) for a in c.split(',')] for c in ch.getAttribute('points').strip().split(' ')])
coords = pg.transformCoordinates(tr, coords, transpose=True)
coords = fn.transformCoordinates(tr, coords, transpose=True)
ch.setAttribute('points', ' '.join([','.join([str(a) for a in c]) for c in coords]))
elif ch.tagName == 'path':
removeTransform = True
@ -365,7 +361,7 @@ def correctCoordinates(node, item):
x = x[1:]
else:
t = ''
nc = pg.transformCoordinates(tr, np.array([[float(x),float(y)]]), transpose=True)
nc = fn.transformCoordinates(tr, np.array([[float(x),float(y)]]), transpose=True)
newCoords += t+str(nc[0,0])+','+str(nc[0,1])+' '
ch.setAttribute('d', newCoords)
elif ch.tagName == 'text':
@ -375,7 +371,7 @@ def correctCoordinates(node, item):
#[float(ch.getAttribute('x')), float(ch.getAttribute('y'))],
#[float(ch.getAttribute('font-size')), 0],
#[0,0]])
#c = pg.transformCoordinates(tr, c, transpose=True)
#c = fn.transformCoordinates(tr, c, transpose=True)
#ch.setAttribute('x', str(c[0,0]))
#ch.setAttribute('y', str(c[0,1]))
#fs = c[1]-c[2]
@ -397,7 +393,7 @@ def correctCoordinates(node, item):
## correct line widths if needed
if removeTransform and ch.getAttribute('vector-effect') != 'non-scaling-stroke':
w = float(grp.getAttribute('stroke-width'))
s = pg.transformCoordinates(tr, np.array([[w,0], [0,0]]), transpose=True)
s = fn.transformCoordinates(tr, np.array([[w,0], [0,0]]), transpose=True)
w = ((s[0]-s[1])**2).sum()**0.5
ch.setAttribute('stroke-width', str(w))
@ -443,35 +439,9 @@ def itemTransform(item, root):
tr = item.sceneTransform()
else:
tr = itemTransform(nextRoot, root) * item.itemTransform(nextRoot)[0]
#pos = QtGui.QTransform()
#pos.translate(root.pos().x(), root.pos().y())
#tr = pos * root.transform() * item.itemTransform(root)[0]
return tr
#def correctStroke(node, item, root, width=1):
##print "==============", item, node
#if node.hasAttribute('stroke-width'):
#width = float(node.getAttribute('stroke-width'))
#if node.getAttribute('vector-effect') == 'non-scaling-stroke':
#node.removeAttribute('vector-effect')
#if isinstance(root, QtGui.QGraphicsScene):
#w = item.mapFromScene(pg.Point(width,0))
#o = item.mapFromScene(pg.Point(0,0))
#else:
#w = item.mapFromItem(root, pg.Point(width,0))
#o = item.mapFromItem(root, pg.Point(0,0))
#w = w-o
##print " ", w, o, w-o
#w = (w.x()**2 + w.y()**2) ** 0.5
##print " ", w
#node.setAttribute('stroke-width', str(w))
#for ch in node.childNodes:
#if isinstance(ch, xml.Element):
#correctStroke(ch, item, root, width)
def cleanXml(node):
## remove extraneous text; let the xml library do the formatting.

View File

@ -1,16 +1,3 @@
#Exporters = []
#from pyqtgraph import importModules
#import os
#d = os.path.split(__file__)[0]
#for mod in importModules('', globals(), locals(), excludes=['Exporter']).values():
#if hasattr(mod, '__all__'):
#names = mod.__all__
#else:
#names = [n for n in dir(mod) if n[0] != '_']
#for k in names:
#if hasattr(mod, k):
#Exporters.append(getattr(mod, k))
from .Exporter import Exporter
from .ImageExporter import *
from .SVGExporter import *

View File

@ -63,8 +63,8 @@ class Parallelize(object):
self.showProgress = True
if isinstance(progressDialog, basestring):
progressDialog = {'labelText': progressDialog}
import pyqtgraph as pg
self.progressDlg = pg.ProgressDialog(**progressDialog)
from ..widgets.ProgressDialog import ProgressDialog
self.progressDlg = ProgressDialog(**progressDialog)
if workers is None:
workers = self.suggestedWorkerCount()

View File

@ -1,7 +1,8 @@
from .remoteproxy import RemoteEventHandler, ClosedError, NoResultError, LocalObjectProxy, ObjectProxy
import subprocess, atexit, os, sys, time, random, socket, signal
import multiprocessing.connection
import pyqtgraph as pg
from ..Qt import USE_PYSIDE
try:
import cPickle as pickle
except ImportError:
@ -118,7 +119,7 @@ class Process(RemoteEventHandler):
ppid=pid,
targetStr=targetStr,
path=sysPath,
pyside=pg.Qt.USE_PYSIDE,
pyside=USE_PYSIDE,
debug=debug
)
pickle.dump(data, self.proc.stdin)
@ -337,7 +338,7 @@ class RemoteQtEventHandler(RemoteEventHandler):
RemoteEventHandler.__init__(self, *args, **kwds)
def startEventTimer(self):
from pyqtgraph.Qt import QtGui, QtCore
from ..Qt import QtGui, QtCore
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.processRequests)
self.timer.start(10)
@ -346,7 +347,7 @@ class RemoteQtEventHandler(RemoteEventHandler):
try:
RemoteEventHandler.processRequests(self)
except ClosedError:
from pyqtgraph.Qt import QtGui, QtCore
from ..Qt import QtGui, QtCore
QtGui.QApplication.instance().quit()
self.timer.stop()
#raise SystemExit
@ -384,7 +385,7 @@ class QtProcess(Process):
self.startEventTimer()
def startEventTimer(self):
from pyqtgraph.Qt import QtGui, QtCore ## avoid module-level import to keep bootstrap snappy.
from ..Qt import QtGui, QtCore ## avoid module-level import to keep bootstrap snappy.
self.timer = QtCore.QTimer()
if self._processRequests:
app = QtGui.QApplication.instance()
@ -415,7 +416,7 @@ def startQtEventLoop(name, port, authkey, ppid, debug=False):
conn = multiprocessing.connection.Client(('localhost', int(port)), authkey=authkey)
if debug:
print('[%d] connected; starting remote proxy.' % os.getpid())
from pyqtgraph.Qt import QtGui, QtCore
from ..Qt import QtGui, QtCore
#from PyQt4 import QtGui, QtCore
app = QtGui.QApplication.instance()
#print app

View File

@ -1,5 +1,5 @@
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph import Transform3D
from ..Qt import QtGui, QtCore
from .. import Transform3D
from OpenGL.GL import *
from OpenGL import GL

View File

@ -1,9 +1,9 @@
from pyqtgraph.Qt import QtCore, QtGui, QtOpenGL
from ..Qt import QtCore, QtGui, QtOpenGL
from OpenGL.GL import *
import OpenGL.GL.framebufferobjects as glfbo
import numpy as np
from pyqtgraph import Vector
import pyqtgraph.functions as fn
from .. import Vector
from .. import functions as fn
##Vector = QtGui.QVector3D
@ -179,7 +179,7 @@ class GLViewWidget(QtOpenGL.QGLWidget):
self._itemNames[id(i)] = i
i.paint()
except:
import pyqtgraph.debug
from .. import debug
pyqtgraph.debug.printExc()
msg = "Error while drawing item %s." % str(item)
ver = glGetString(GL_VERSION)
@ -345,7 +345,7 @@ class GLViewWidget(QtOpenGL.QGLWidget):
## Only to be called from within exception handler.
ver = glGetString(GL_VERSION).split()[0]
if int(ver.split('.')[0]) < 2:
import pyqtgraph.debug
from .. import debug
pyqtgraph.debug.printExc()
raise Exception(msg + " The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is %s. Installing updated display drivers may resolve this issue." % ver)
else:

View File

@ -1,5 +1,5 @@
from pyqtgraph.Qt import QtGui
import pyqtgraph.functions as fn
from ..Qt import QtGui
from .. import functions as fn
import numpy as np
class MeshData(object):

View File

@ -1,7 +1,7 @@
from .GLViewWidget import GLViewWidget
## dynamic imports cause too many problems.
#from pyqtgraph import importAll
#from .. import importAll
#importAll('items', globals(), locals())
from .items.GLGridItem import *

View File

@ -1,4 +1,4 @@
from pyqtgraph.Qt import QtCore, QtGui, QtOpenGL
from ..Qt import QtCore, QtGui, QtOpenGL
from OpenGL.GL import *
app = QtGui.QApplication([])

View File

@ -1,6 +1,6 @@
from OpenGL.GL import *
from .. GLGraphicsItem import GLGraphicsItem
from pyqtgraph import QtGui
from ... import QtGui
__all__ = ['GLAxisItem']

View File

@ -1,7 +1,7 @@
from OpenGL.GL import *
from .. GLGraphicsItem import GLGraphicsItem
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
from ...Qt import QtGui
from ... import functions as fn
__all__ = ['GLBoxItem']
@ -38,7 +38,7 @@ class GLBoxItem(GLGraphicsItem):
def setColor(self, *args):
"""Set the color of the box. Arguments are the same as those accepted by functions.mkColor()"""
self.__color = pg.Color(*args)
self.__color = fn.Color(*args)
def color(self):
return self.__color

View File

@ -1,6 +1,6 @@
from OpenGL.GL import *
from .. GLGraphicsItem import GLGraphicsItem
from pyqtgraph import QtGui
from ... import QtGui
__all__ = ['GLGridItem']

View File

@ -1,6 +1,6 @@
from OpenGL.GL import *
from .. GLGraphicsItem import GLGraphicsItem
from pyqtgraph.Qt import QtGui
from ...Qt import QtGui
import numpy as np
__all__ = ['GLImageItem']

View File

@ -2,7 +2,7 @@ from OpenGL.GL import *
from OpenGL.arrays import vbo
from .. GLGraphicsItem import GLGraphicsItem
from .. import shaders
from pyqtgraph import QtGui
from ... import QtGui
import numpy as np
__all__ = ['GLLinePlotItem']

View File

@ -1,9 +1,9 @@
from OpenGL.GL import *
from .. GLGraphicsItem import GLGraphicsItem
from .. MeshData import MeshData
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
from ...Qt import QtGui
from .. import shaders
from ... import functions as fn
import numpy as np
@ -177,7 +177,7 @@ class GLMeshItem(GLGraphicsItem):
if self.colors is None:
color = self.opts['color']
if isinstance(color, QtGui.QColor):
glColor4f(*pg.glColor(color))
glColor4f(*fn.glColor(color))
else:
glColor4f(*color)
else:
@ -209,7 +209,7 @@ class GLMeshItem(GLGraphicsItem):
if self.edgeColors is None:
color = self.opts['edgeColor']
if isinstance(color, QtGui.QColor):
glColor4f(*pg.glColor(color))
glColor4f(*fn.glColor(color))
else:
glColor4f(*color)
else:

View File

@ -2,7 +2,7 @@ from OpenGL.GL import *
from OpenGL.arrays import vbo
from .. GLGraphicsItem import GLGraphicsItem
from .. import shaders
from pyqtgraph import QtGui
from ... import QtGui
import numpy as np
__all__ = ['GLScatterPlotItem']

View File

@ -1,8 +1,7 @@
from OpenGL.GL import *
from .GLMeshItem import GLMeshItem
from .. MeshData import MeshData
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
from ...Qt import QtGui
import numpy as np

View File

@ -1,6 +1,6 @@
from OpenGL.GL import *
from .. GLGraphicsItem import GLGraphicsItem
from pyqtgraph.Qt import QtGui
from ...Qt import QtGui
import numpy as np
__all__ = ['GLVolumeItem']