remotegraphicsview fix for PyQt 4.10

This commit is contained in:
Luke Campagnola 2013-04-07 16:18:58 -04:00
parent daaf481830
commit 1a0b5921df
2 changed files with 14 additions and 6 deletions

View File

@ -1,20 +1,26 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Very simple example demonstrating RemoteGraphicsView Very simple example demonstrating RemoteGraphicsView.
This allows graphics to be rendered in a child process and displayed in the
parent, which can improve CPU usage on multi-core processors.
""" """
import initExample ## Add path to library (just for examples; you do not need this) import initExample ## Add path to library (just for examples; you do not need this)
from pyqtgraph.Qt import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph.widgets.RemoteGraphicsView import RemoteGraphicsView from pyqtgraph.widgets.RemoteGraphicsView import RemoteGraphicsView
app = pg.mkQApp() app = pg.mkQApp()
v = RemoteGraphicsView() ## Create the widget
v = RemoteGraphicsView(debug=False)
v.show() v.show()
v.setWindowTitle('pyqtgraph example: RemoteGraphicsView') v.setWindowTitle('pyqtgraph example: RemoteGraphicsView')
## v.pg is a proxy to the remote process' pyqtgraph module. All attribute ## v.pg is a proxy to the remote process' pyqtgraph module. All attribute
## requests and function calls made with this object are forwarded to the ## requests and function calls made with this object are forwarded to the
## remote process and executed there. ## remote process and executed there. See pyqtgraph.multiprocess.remoteproxy
## for more inormation.
plt = v.pg.PlotItem() plt = v.pg.PlotItem()
v.setCentralItem(plt) v.setCentralItem(plt)
plt.plot([1,4,2,3,6,2,3,4,2,3], pen='g') plt.plot([1,4,2,3,6,2,3,4,2,3], pen='g')

View File

@ -1,4 +1,6 @@
from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE
if not USE_PYSIDE:
import sip
import pyqtgraph.multiprocess as mp import pyqtgraph.multiprocess as mp
import pyqtgraph as pg import pyqtgraph as pg
from .GraphicsView import GraphicsView from .GraphicsView import GraphicsView
@ -21,7 +23,7 @@ class RemoteGraphicsView(QtGui.QWidget):
self._sizeHint = (640,480) ## no clue why this is needed, but it seems to be the default sizeHint for GraphicsView. self._sizeHint = (640,480) ## no clue why this is needed, but it seems to be the default sizeHint for GraphicsView.
## without it, the widget will not compete for space against another GraphicsView. ## without it, the widget will not compete for space against another GraphicsView.
QtGui.QWidget.__init__(self) QtGui.QWidget.__init__(self)
self._proc = mp.QtProcess(debug=False) self._proc = mp.QtProcess(debug=kwds.pop('debug', False))
self.pg = self._proc._import('pyqtgraph') self.pg = self._proc._import('pyqtgraph')
self.pg.setConfigOptions(**self.pg.CONFIG_OPTIONS) self.pg.setConfigOptions(**self.pg.CONFIG_OPTIONS)
rpgRemote = self._proc._import('pyqtgraph.widgets.RemoteGraphicsView') rpgRemote = self._proc._import('pyqtgraph.widgets.RemoteGraphicsView')
@ -174,7 +176,6 @@ class Renderer(GraphicsView):
self.shm = mmap.mmap(-1, size, self.shmtag) self.shm = mmap.mmap(-1, size, self.shmtag)
else: else:
self.shm.resize(size) self.shm.resize(size)
address = ctypes.addressof(ctypes.c_char.from_buffer(self.shm, 0))
## render the scene directly to shared memory ## render the scene directly to shared memory
if USE_PYSIDE: if USE_PYSIDE:
@ -182,7 +183,8 @@ class Renderer(GraphicsView):
#ch = ctypes.c_char_p(address) #ch = ctypes.c_char_p(address)
self.img = QtGui.QImage(ch, self.width(), self.height(), QtGui.QImage.Format_ARGB32) self.img = QtGui.QImage(ch, self.width(), self.height(), QtGui.QImage.Format_ARGB32)
else: else:
self.img = QtGui.QImage(address, self.width(), self.height(), QtGui.QImage.Format_ARGB32) address = ctypes.addressof(ctypes.c_char.from_buffer(self.shm, 0))
self.img = QtGui.QImage(sip.voidptr(address), self.width(), self.height(), QtGui.QImage.Format_ARGB32)
self.img.fill(0xffffffff) self.img.fill(0xffffffff)
p = QtGui.QPainter(self.img) p = QtGui.QPainter(self.img)
self.render(p, self.viewRect(), self.rect()) self.render(p, self.viewRect(), self.rect())