Fixes for Python3, PySide

This commit is contained in:
Luke Campagnola 2013-01-12 18:07:35 -05:00
parent 051a91c688
commit 362a0dcd04
10 changed files with 36 additions and 18 deletions

View File

@ -1260,7 +1260,7 @@ def isocurve(data, level, connected=False, extendToEdge=False, path=False):
points[b[1]].append([b,a]) points[b[1]].append([b,a])
## rearrange into chains ## rearrange into chains
for k in points.keys(): for k in list(points.keys()):
try: try:
chains = points[k] chains = points[k]
except KeyError: ## already used this point elsewhere except KeyError: ## already used this point elsewhere

View File

@ -4,7 +4,7 @@ from pyqtgraph.Point import Point
import pyqtgraph.functions as fn import pyqtgraph.functions as fn
import weakref import weakref
from pyqtgraph.pgcollections import OrderedDict from pyqtgraph.pgcollections import OrderedDict
import operator import operator, sys
class FiniteCache(OrderedDict): class FiniteCache(OrderedDict):
"""Caches a finite number of objects, removing """Caches a finite number of objects, removing
@ -17,7 +17,7 @@ class FiniteCache(OrderedDict):
self.pop(item, None) # make sure item is added to end self.pop(item, None) # make sure item is added to end
OrderedDict.__setitem__(self, item, val) OrderedDict.__setitem__(self, item, val)
while len(self) > self._length: while len(self) > self._length:
del self[self.keys()[0]] del self[list(self.keys())[0]]
def __getitem__(self, item): def __getitem__(self, item):
val = dict.__getitem__(self, item) val = dict.__getitem__(self, item)
@ -197,14 +197,14 @@ class GraphicsItem(object):
## check local cache ## check local cache
if direction is None and dt == self._pixelVectorCache[0]: if direction is None and dt == self._pixelVectorCache[0]:
return map(Point, self._pixelVectorCache[1]) ## return a *copy* return tuple(map(Point, self._pixelVectorCache[1])) ## return a *copy*
## check global cache ## check global cache
key = (dt.m11(), dt.m21(), dt.m31(), dt.m12(), dt.m22(), dt.m32(), dt.m31(), dt.m32()) key = (dt.m11(), dt.m21(), dt.m31(), dt.m12(), dt.m22(), dt.m32(), dt.m31(), dt.m32())
pv = self._pixelVectorGlobalCache.get(key, None) pv = self._pixelVectorGlobalCache.get(key, None)
if pv is not None: if pv is not None:
self._pixelVectorCache = [dt, pv] self._pixelVectorCache = [dt, pv]
return map(Point,pv) ## return a *copy* return tuple(map(Point,pv)) ## return a *copy*
if direction is None: if direction is None:

View File

@ -1808,7 +1808,7 @@ class LineSegmentROI(ROI):
for i in range(len(imgPts)-1): for i in range(len(imgPts)-1):
d = Point(imgPts[i+1] - imgPts[i]) d = Point(imgPts[i+1] - imgPts[i])
o = Point(imgPts[i]) o = Point(imgPts[i])
r = fn.affineSlice(data, shape=(int(d.length()),), vectors=[d.norm()], origin=o, axes=axes, order=1) r = fn.affineSlice(data, shape=(int(d.length()),), vectors=[Point(d.norm())], origin=o, axes=axes, order=1)
rgns.append(r) rgns.append(r)
return np.concatenate(rgns, axis=axes[0]) return np.concatenate(rgns, axis=axes[0])

View File

@ -41,7 +41,7 @@ def drawSymbol(painter, symbol, size, pen, brush):
if isinstance(symbol, basestring): if isinstance(symbol, basestring):
symbol = Symbols[symbol] symbol = Symbols[symbol]
if np.isscalar(symbol): if np.isscalar(symbol):
symbol = Symbols.values()[symbol % len(Symbols)] symbol = list(Symbols.values())[symbol % len(Symbols)]
painter.drawPath(symbol) painter.drawPath(symbol)

View File

@ -1198,7 +1198,7 @@ class ViewBox(GraphicsWidget):
if ViewBox is None: ## can happen as python is shutting down if ViewBox is None: ## can happen as python is shutting down
return return
## Called with ID and name of view (the view itself is no longer available) ## Called with ID and name of view (the view itself is no longer available)
for v in ViewBox.AllViews.keys(): for v in list(ViewBox.AllViews.keys()):
if id(v) == vid: if id(v) == vid:
ViewBox.AllViews.pop(v) ViewBox.AllViews.pop(v)
break break

View File

@ -4,13 +4,19 @@ import sys, pickle, os
if __name__ == '__main__': if __name__ == '__main__':
if hasattr(os, 'setpgrp'): if hasattr(os, 'setpgrp'):
os.setpgrp() ## prevents signals (notably keyboard interrupt) being forwarded from parent to this process os.setpgrp() ## prevents signals (notably keyboard interrupt) being forwarded from parent to this process
name, port, authkey, ppid, targetStr, path = pickle.load(sys.stdin) if sys.version[0] == '3':
name, port, authkey, ppid, targetStr, path, pyside = pickle.load(sys.stdin.buffer)
else:
name, port, authkey, ppid, targetStr, path, pyside = pickle.load(sys.stdin)
#print "key:", ' '.join([str(ord(x)) for x in authkey]) #print "key:", ' '.join([str(ord(x)) for x in authkey])
if path is not None: if path is not None:
## rewrite sys.path without assigning a new object--no idea who already has a reference to the existing list. ## rewrite sys.path without assigning a new object--no idea who already has a reference to the existing list.
while len(sys.path) > 0: while len(sys.path) > 0:
sys.path.pop() sys.path.pop()
sys.path.extend(path) sys.path.extend(path)
if pyside:
import PySide
#import pyqtgraph #import pyqtgraph
#import pyqtgraph.multiprocess.processes #import pyqtgraph.multiprocess.processes
target = pickle.loads(targetStr) ## unpickling the target should import everything we need target = pickle.loads(targetStr) ## unpickling the target should import everything we need

View File

@ -1,6 +1,6 @@
import os, sys, time, multiprocessing, re import os, sys, time, multiprocessing, re
from processes import ForkedProcess from .processes import ForkedProcess
from remoteproxy import ClosedError from .remoteproxy import ClosedError
class CanceledError(Exception): class CanceledError(Exception):
"""Raised when the progress dialog is canceled during a processing operation.""" """Raised when the progress dialog is canceled during a processing operation."""

View File

@ -1,7 +1,11 @@
from remoteproxy import RemoteEventHandler, ClosedError, NoResultError, LocalObjectProxy, ObjectProxy from .remoteproxy import RemoteEventHandler, ClosedError, NoResultError, LocalObjectProxy, ObjectProxy
import subprocess, atexit, os, sys, time, random, socket, signal import subprocess, atexit, os, sys, time, random, socket, signal
import cPickle as pickle
import multiprocessing.connection import multiprocessing.connection
from pyqtgraph.Qt import USE_PYSIDE
try:
import cPickle as pickle
except ImportError:
import pickle
__all__ = ['Process', 'QtProcess', 'ForkedProcess', 'ClosedError', 'NoResultError'] __all__ = ['Process', 'QtProcess', 'ForkedProcess', 'ClosedError', 'NoResultError']
@ -75,7 +79,10 @@ class Process(RemoteEventHandler):
targetStr = pickle.dumps(target) ## double-pickle target so that child has a chance to targetStr = pickle.dumps(target) ## double-pickle target so that child has a chance to
## set its sys.path properly before unpickling the target ## set its sys.path properly before unpickling the target
pid = os.getpid() # we must sent pid to child because windows does not have getppid pid = os.getpid() # we must sent pid to child because windows does not have getppid
pickle.dump((name+'_child', port, authkey, pid, targetStr, sysPath), self.proc.stdin) pyside = USE_PYSIDE
## Send everything the remote process needs to start correctly
pickle.dump((name+'_child', port, authkey, pid, targetStr, sysPath, pyside), self.proc.stdin)
self.proc.stdin.close() self.proc.stdin.close()
## open connection for remote process ## open connection for remote process

View File

@ -1,6 +1,11 @@
import os, __builtin__, time, sys, traceback, weakref import os, time, sys, traceback, weakref
import cPickle as pickle
import numpy as np import numpy as np
try:
import __builtin__ as builtins
import cPickle as pickle
except ImportError:
import builtins
import pickle
class ClosedError(Exception): class ClosedError(Exception):
"""Raised when an event handler receives a request to close the connection """Raised when an event handler receives a request to close the connection
@ -181,7 +186,7 @@ class RemoteEventHandler(object):
elif cmd == 'import': elif cmd == 'import':
name = opts['module'] name = opts['module']
fromlist = opts.get('fromlist', []) fromlist = opts.get('fromlist', [])
mod = __builtin__.__import__(name, fromlist=fromlist) mod = builtins.__import__(name, fromlist=fromlist)
if len(fromlist) == 0: if len(fromlist) == 0:
parts = name.lstrip('.').split('.') parts = name.lstrip('.').split('.')

View File

@ -27,7 +27,7 @@ class RemoteGraphicsView(QtGui.QWidget):
rpgRemote = self._proc._import('pyqtgraph.widgets.RemoteGraphicsView') rpgRemote = self._proc._import('pyqtgraph.widgets.RemoteGraphicsView')
self._view = rpgRemote.Renderer(*args, **kwds) self._view = rpgRemote.Renderer(*args, **kwds)
self._view._setProxyOptions(deferGetattr=True) self._view._setProxyOptions(deferGetattr=True)
self.setFocusPolicy(self._view.focusPolicy()) self.setFocusPolicy(QtCore.Qt.FocusPolicy(self._view.focusPolicy()))
self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.setMouseTracking(True) self.setMouseTracking(True)
self.shm = None self.shm = None