From 35ea55897e970cce193058cb7626d21cf8172279 Mon Sep 17 00:00:00 2001 From: Guillaume Poulin Date: Tue, 10 Sep 2013 20:57:56 +0800 Subject: [PATCH 1/3] python3 bugfixes (SVGexpoter) --- pyqtgraph/exporters/SVGExporter.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pyqtgraph/exporters/SVGExporter.py b/pyqtgraph/exporters/SVGExporter.py index 672897ab..7c48c8a9 100644 --- a/pyqtgraph/exporters/SVGExporter.py +++ b/pyqtgraph/exporters/SVGExporter.py @@ -1,4 +1,5 @@ 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 @@ -91,8 +92,8 @@ class SVGExporter(Exporter): md.setData('image/svg+xml', QtCore.QByteArray(xml.encode('UTF-8'))) QtGui.QApplication.clipboard().setMimeData(md) else: - with open(fileName, 'w') as fh: - fh.write(xml.encode('UTF-8')) + with open(fileName, 'wt') as fh: + fh.write(asUnicode(xml)) xmlHeader = """\ @@ -221,8 +222,8 @@ def _generateItemSvg(item, nodes=None, root=None): ## this is taken care of in generateSvg instead. #if hasattr(item, 'setExportMode'): #item.setExportMode(False) - - xmlStr = str(arr) + + xmlStr = bytes(arr).decode('utf-8') doc = xml.parseString(xmlStr) try: @@ -340,7 +341,7 @@ def correctCoordinates(node, item): if match is None: vals = [1,0,0,1,0,0] else: - vals = map(float, match.groups()[0].split(',')) + vals = [float(a) for a in match.groups()[0].split(',')] tr = np.array([[vals[0], vals[2], vals[4]], [vals[1], vals[3], vals[5]]]) removeTransform = False From 59ada9b1b4c8195e280c0bf6368be25e58b8a0e6 Mon Sep 17 00:00:00 2001 From: Guillaume Poulin Date: Tue, 10 Sep 2013 22:12:55 +0800 Subject: [PATCH 2/3] More bugfixes in SVGExporter.py --- pyqtgraph/exporters/SVGExporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/exporters/SVGExporter.py b/pyqtgraph/exporters/SVGExporter.py index 7c48c8a9..821427a4 100644 --- a/pyqtgraph/exporters/SVGExporter.py +++ b/pyqtgraph/exporters/SVGExporter.py @@ -350,9 +350,9 @@ def correctCoordinates(node, item): continue if ch.tagName == 'polyline': removeTransform = True - coords = np.array([map(float, c.split(',')) for c in ch.getAttribute('points').strip().split(' ')]) + 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) - ch.setAttribute('points', ' '.join([','.join(map(str, c)) for c in coords])) + ch.setAttribute('points', ' '.join([','.join([str(a) for a in c]) for c in coords])) elif ch.tagName == 'path': removeTransform = True newCoords = '' From b48e0e9eb50b5007a95d10eabb269c952129c729 Mon Sep 17 00:00:00 2001 From: Guillaume Poulin Date: Tue, 10 Sep 2013 22:34:20 +0800 Subject: [PATCH 3/3] Restore utf-8 compatibility for python 2 --- pyqtgraph/exporters/SVGExporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/exporters/SVGExporter.py b/pyqtgraph/exporters/SVGExporter.py index 821427a4..62b49d30 100644 --- a/pyqtgraph/exporters/SVGExporter.py +++ b/pyqtgraph/exporters/SVGExporter.py @@ -92,8 +92,8 @@ class SVGExporter(Exporter): md.setData('image/svg+xml', QtCore.QByteArray(xml.encode('UTF-8'))) QtGui.QApplication.clipboard().setMimeData(md) else: - with open(fileName, 'wt') as fh: - fh.write(asUnicode(xml)) + with open(fileName, 'wb') as fh: + fh.write(asUnicode(xml).encode('utf-8')) xmlHeader = """\