From b0030e1a49ca06509960d40f0bb2b8a7a50cabca Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Sat, 29 Dec 2012 02:35:45 -0500 Subject: [PATCH] Bugfixes: - Fixed RuntimeError when clearing items from ViewBox - SVG exporter adds generic font-family names to text items --- pyqtgraph/exporters/SVGExporter.py | 15 +++++++++++++++ pyqtgraph/graphicsItems/GraphicsItem.py | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/exporters/SVGExporter.py b/pyqtgraph/exporters/SVGExporter.py index 321c311f..70f1f632 100644 --- a/pyqtgraph/exporters/SVGExporter.py +++ b/pyqtgraph/exporters/SVGExporter.py @@ -17,6 +17,9 @@ class SVGExporter(Exporter): self.params = Parameter(name='params', type='group', children=[ #{'name': 'width', 'type': 'float', 'value': tr.width(), 'limits': (0, None)}, #{'name': 'height', 'type': 'float', 'value': tr.height(), 'limits': (0, None)}, + #{'name': 'viewbox clipping', 'type': 'bool', 'value': True}, + #{'name': 'normalize coordinates', 'type': 'bool', 'value': True}, + #{'name': 'normalize line width', 'type': 'bool', 'value': True}, ]) #self.params.param('width').sigValueChanged.connect(self.widthChanged) #self.params.param('height').sigValueChanged.connect(self.heightChanged) @@ -335,6 +338,18 @@ def correctCoordinates(node, item): #fs = (fs**2).sum()**0.5 #ch.setAttribute('font-size', str(fs)) + ## Correct some font information + families = ch.getAttribute('font-family').split(',') + if len(families) == 1: + font = QtGui.QFont(families[0].strip('" ')) + if font.style() == font.SansSerif: + families.append('sans-serif') + elif font.style() == font.Serif: + families.append('serif') + elif font.style() == font.Courier: + families.append('monospace') + ch.setAttribute('font-family', ', '.join([f if ' ' not in f else '"%s"'%f for f in families])) + ## correct line widths if needed if removeTransform and ch.getAttribute('vector-effect') != 'non-scaling-stroke': w = float(grp.getAttribute('stroke-width')) diff --git a/pyqtgraph/graphicsItems/GraphicsItem.py b/pyqtgraph/graphicsItems/GraphicsItem.py index 34fd4bd7..2018fb4c 100644 --- a/pyqtgraph/graphicsItems/GraphicsItem.py +++ b/pyqtgraph/graphicsItems/GraphicsItem.py @@ -63,7 +63,10 @@ class GraphicsItem(object): if self._viewBox is None: p = self while True: - p = p.parentItem() + try: + p = p.parentItem() + except RuntimeError: ## sometimes happens as items are being removed from a scene and collected. + return None if p is None: vb = self.getViewWidget() if vb is None: