From 1c8579d4b45e1e25a45f6eaa343eeec6e8eb1846 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Thu, 18 Oct 2012 22:51:46 -0400 Subject: [PATCH] - Bugfixes: Fixed exporters to automatically add filename extension. Fixed ViewBox 'auto pan' option. - Other minor edits. --- exporters/CSVExporter.py | 2 +- exporters/Exporter.py | 7 ++++++- exporters/ImageExporter.py | 2 +- graphicsItems/AxisItem.py | 4 ++++ graphicsItems/ViewBox/ViewBox.py | 4 ++-- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/exporters/CSVExporter.py b/exporters/CSVExporter.py index 5e949be6..629b2789 100644 --- a/exporters/CSVExporter.py +++ b/exporters/CSVExporter.py @@ -22,7 +22,7 @@ class CSVExporter(Exporter): def export(self, fileName=None): if not isinstance(self.item, pg.PlotItem): - raise Exception("Matplotlib export currently only works with plot items") + raise Exception("Must have a PlotItem selected for CSV export.") if fileName is None: self.fileSaveDialog(filter=["*.csv", "*.tsv"]) diff --git a/exporters/Exporter.py b/exporters/Exporter.py index 709926d4..0ade8467 100644 --- a/exporters/Exporter.py +++ b/exporters/Exporter.py @@ -54,8 +54,13 @@ class Exporter(object): fileName = str(fileName) global LastExportDirectory LastExportDirectory = os.path.split(fileName)[0] - self.export(fileName=fileName, **self.fileDialog.opts) + ext = os.path.splitext(fileName)[1].lower() + selectedExt = str(self.fileDialog.selectedNameFilter()).lstrip('*').lower() + if ext != selectedExt: + fileName = fileName + selectedExt + + self.export(fileName=fileName, **self.fileDialog.opts) def getScene(self): if isinstance(self.item, pg.GraphicsScene): diff --git a/exporters/ImageExporter.py b/exporters/ImageExporter.py index e27d48ff..bf2a66f8 100644 --- a/exporters/ImageExporter.py +++ b/exporters/ImageExporter.py @@ -63,7 +63,7 @@ class ImageExporter(Exporter): self.getScene().render(painter, QtCore.QRectF(targetRect), sourceRect) finally: self.setExportMode(False) - self.png.save(fileName) painter.end() + self.png.save(fileName) \ No newline at end of file diff --git a/graphicsItems/AxisItem.py b/graphicsItems/AxisItem.py index 416d0b5a..82cbcfae 100644 --- a/graphicsItems/AxisItem.py +++ b/graphicsItems/AxisItem.py @@ -172,6 +172,8 @@ class AxisItem(GraphicsWidget): return asUnicode("%s") % (style, s) def setHeight(self, h=None): + """Set the height of this axis reserved for ticks and tick labels. + The height of the axis label is automatically added.""" if h is None: h = self.textHeight + max(0, self.tickLength) if self.label.isVisible(): @@ -182,6 +184,8 @@ class AxisItem(GraphicsWidget): def setWidth(self, w=None): + """Set the width of this axis reserved for ticks and tick labels. + The width of the axis label is automatically added.""" if w is None: w = max(0, self.tickLength) + 40 if self.label.isVisible(): diff --git a/graphicsItems/ViewBox/ViewBox.py b/graphicsItems/ViewBox/ViewBox.py index 5eca742c..83719a48 100644 --- a/graphicsItems/ViewBox/ViewBox.py +++ b/graphicsItems/ViewBox/ViewBox.py @@ -554,10 +554,10 @@ class ViewBox(GraphicsWidget): ## Make corrections to range xr = childRange[ax] if xr is not None: - if self.state['autoPan'][0]: + if self.state['autoPan'][ax]: x = sum(xr) * 0.5 #x = childRect.center().x() - w2 = (targetRect[0][1]-targetRect[0][0]) / 2. + w2 = (targetRect[ax][1]-targetRect[ax][0]) / 2. #childRect.setLeft(x-w2) #childRect.setRight(x+w2) childRange[ax] = [x-w2, x+w2]