- Bugfixes:

Fixed exporters to automatically add filename extension.
    Fixed ViewBox 'auto pan' option.
- Other minor edits.
This commit is contained in:
Luke Campagnola 2012-10-18 22:51:46 -04:00
parent c4019b900d
commit 1c8579d4b4
5 changed files with 14 additions and 5 deletions

View File

@ -22,7 +22,7 @@ class CSVExporter(Exporter):
def export(self, fileName=None): def export(self, fileName=None):
if not isinstance(self.item, pg.PlotItem): 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: if fileName is None:
self.fileSaveDialog(filter=["*.csv", "*.tsv"]) self.fileSaveDialog(filter=["*.csv", "*.tsv"])

View File

@ -54,8 +54,13 @@ class Exporter(object):
fileName = str(fileName) fileName = str(fileName)
global LastExportDirectory global LastExportDirectory
LastExportDirectory = os.path.split(fileName)[0] 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): def getScene(self):
if isinstance(self.item, pg.GraphicsScene): if isinstance(self.item, pg.GraphicsScene):

View File

@ -63,7 +63,7 @@ class ImageExporter(Exporter):
self.getScene().render(painter, QtCore.QRectF(targetRect), sourceRect) self.getScene().render(painter, QtCore.QRectF(targetRect), sourceRect)
finally: finally:
self.setExportMode(False) self.setExportMode(False)
self.png.save(fileName)
painter.end() painter.end()
self.png.save(fileName)

View File

@ -172,6 +172,8 @@ class AxisItem(GraphicsWidget):
return asUnicode("<span style='%s'>%s</span>") % (style, s) return asUnicode("<span style='%s'>%s</span>") % (style, s)
def setHeight(self, h=None): 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: if h is None:
h = self.textHeight + max(0, self.tickLength) h = self.textHeight + max(0, self.tickLength)
if self.label.isVisible(): if self.label.isVisible():
@ -182,6 +184,8 @@ class AxisItem(GraphicsWidget):
def setWidth(self, w=None): 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: if w is None:
w = max(0, self.tickLength) + 40 w = max(0, self.tickLength) + 40
if self.label.isVisible(): if self.label.isVisible():

View File

@ -554,10 +554,10 @@ class ViewBox(GraphicsWidget):
## Make corrections to range ## Make corrections to range
xr = childRange[ax] xr = childRange[ax]
if xr is not None: if xr is not None:
if self.state['autoPan'][0]: if self.state['autoPan'][ax]:
x = sum(xr) * 0.5 x = sum(xr) * 0.5
#x = childRect.center().x() #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.setLeft(x-w2)
#childRect.setRight(x+w2) #childRect.setRight(x+w2)
childRange[ax] = [x-w2, x+w2] childRange[ax] = [x-w2, x+w2]