From 1d2d7be733f435f60e650ac2a2d15d9eca446c4d Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sun, 24 Feb 2013 14:31:11 -0500 Subject: [PATCH] When exporting, prefer to select PlotItem rather than ViewBox if possible CSV exporter gets 'precision' option --- pyqtgraph/GraphicsScene/exportDialog.py | 4 ++++ pyqtgraph/exporters/CSVExporter.py | 12 +++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pyqtgraph/GraphicsScene/exportDialog.py b/pyqtgraph/GraphicsScene/exportDialog.py index 73a8c83f..436d5e42 100644 --- a/pyqtgraph/GraphicsScene/exportDialog.py +++ b/pyqtgraph/GraphicsScene/exportDialog.py @@ -34,8 +34,12 @@ class ExportDialog(QtGui.QWidget): def show(self, item=None): if item is not None: + ## Select next exportable parent of the item originally clicked on while not isinstance(item, pg.ViewBox) and not isinstance(item, pg.PlotItem) and item is not None: item = item.parentItem() + ## if this is a ViewBox inside a PlotItem, select the parent instead. + if isinstance(item, pg.ViewBox) and isinstance(item.parentItem(), pg.PlotItem): + item = item.parentItem() self.updateItemList(select=item) self.setVisible(True) self.activateWindow() diff --git a/pyqtgraph/exporters/CSVExporter.py b/pyqtgraph/exporters/CSVExporter.py index 629b2789..0439fc35 100644 --- a/pyqtgraph/exporters/CSVExporter.py +++ b/pyqtgraph/exporters/CSVExporter.py @@ -14,6 +14,7 @@ class CSVExporter(Exporter): Exporter.__init__(self, item) self.params = Parameter(name='params', type='group', children=[ {'name': 'separator', 'type': 'list', 'value': 'comma', 'values': ['comma', 'tab']}, + {'name': 'precision', 'type': 'int', 'value': 10, 'limits': [0, None]}, ]) def parameters(self): @@ -42,18 +43,15 @@ class CSVExporter(Exporter): fd.write(sep.join(header) + '\n') i = 0 - while True: - done = True + numFormat = '%%0.%dg' % self.params['precision'] + numRows = reduce(max, [len(d[0]) for d in data]) + for i in range(numRows): for d in data: if i < len(d[0]): - fd.write('%g%s%g%s'%(d[0][i], sep, d[1][i], sep)) - done = False + fd.write(numFormat % d[0][i] + sep + numFormat % d[1][i] + sep) else: fd.write(' %s %s' % (sep, sep)) fd.write('\n') - if done: - break - i += 1 fd.close()