From 3fd56eb195b10e209c3c00376b37408328fce58f Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Fri, 22 Jun 2018 17:26:31 -0700 Subject: [PATCH 1/2] Handle Qt4/5 API difference in filedialog --- examples/relativity/relativity.py | 16 ++++++++++------ pyqtgraph/imageview/ImageView.py | 2 ++ pyqtgraph/widgets/TableWidget.py | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/relativity/relativity.py b/examples/relativity/relativity.py index e3f2c435..726b49b4 100644 --- a/examples/relativity/relativity.py +++ b/examples/relativity/relativity.py @@ -159,17 +159,21 @@ class RelativityGUI(QtGui.QWidget): self.setAnimation(self.params['Animate']) def save(self): - fn = str(pg.QtGui.QFileDialog.getSaveFileName(self, "Save State..", "untitled.cfg", "Config Files (*.cfg)")) - if fn == '': + filename = str(pg.QtGui.QFileDialog.getSaveFileName(self, "Save State..", "untitled.cfg", "Config Files (*.cfg)")) + if isinstance(filename, tuple): + filename = filename[0] # Qt4/5 API difference + if filename == '': return state = self.params.saveState() - pg.configfile.writeConfigFile(state, fn) + pg.configfile.writeConfigFile(state, filename) def load(self): - fn = str(pg.QtGui.QFileDialog.getOpenFileName(self, "Save State..", "", "Config Files (*.cfg)")) - if fn == '': + filename = str(pg.QtGui.QFileDialog.getOpenFileName(self, "Save State..", "", "Config Files (*.cfg)")) + if isinstance(filename, tuple): + filename = filename[0] # Qt4/5 API difference + if filename == '': return - state = pg.configfile.readConfigFile(fn) + state = pg.configfile.readConfigFile(filename) self.loadState(state) def loadPreset(self, param, preset): diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 40a3987a..ca3ac416 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -790,6 +790,8 @@ class ImageView(QtGui.QWidget): def exportClicked(self): fileName = QtGui.QFileDialog.getSaveFileName() + if isinstance(fileName, tuple): + fileName = fileName[0] # Qt4/5 API difference if fileName == '': return self.export(fileName) diff --git a/pyqtgraph/widgets/TableWidget.py b/pyqtgraph/widgets/TableWidget.py index d1bec16b..66fdea8e 100644 --- a/pyqtgraph/widgets/TableWidget.py +++ b/pyqtgraph/widgets/TableWidget.py @@ -351,6 +351,8 @@ class TableWidget(QtGui.QTableWidget): def save(self, data): fileName = QtGui.QFileDialog.getSaveFileName(self, "Save As..", "", "Tab-separated values (*.tsv)") + if isinstance(fileName, tuple): + fileName = fileName[0] # Qt4/5 API difference if fileName == '': return open(fileName, 'w').write(data) From 08349351da13c7108b43ad6eddace08d3eab0269 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Fri, 22 Jun 2018 17:31:58 -0700 Subject: [PATCH 2/2] Fix QString handling --- examples/relativity/relativity.py | 8 ++++---- pyqtgraph/imageview/ImageView.py | 2 +- pyqtgraph/widgets/TableWidget.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/relativity/relativity.py b/examples/relativity/relativity.py index 726b49b4..98ef524e 100644 --- a/examples/relativity/relativity.py +++ b/examples/relativity/relativity.py @@ -159,21 +159,21 @@ class RelativityGUI(QtGui.QWidget): self.setAnimation(self.params['Animate']) def save(self): - filename = str(pg.QtGui.QFileDialog.getSaveFileName(self, "Save State..", "untitled.cfg", "Config Files (*.cfg)")) + filename = pg.QtGui.QFileDialog.getSaveFileName(self, "Save State..", "untitled.cfg", "Config Files (*.cfg)") if isinstance(filename, tuple): filename = filename[0] # Qt4/5 API difference if filename == '': return state = self.params.saveState() - pg.configfile.writeConfigFile(state, filename) + pg.configfile.writeConfigFile(state, str(filename)) def load(self): - filename = str(pg.QtGui.QFileDialog.getOpenFileName(self, "Save State..", "", "Config Files (*.cfg)")) + filename = pg.QtGui.QFileDialog.getOpenFileName(self, "Save State..", "", "Config Files (*.cfg)") if isinstance(filename, tuple): filename = filename[0] # Qt4/5 API difference if filename == '': return - state = pg.configfile.readConfigFile(filename) + state = pg.configfile.readConfigFile(str(filename)) self.loadState(state) def loadPreset(self, param, preset): diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index ca3ac416..2b43b940 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -794,7 +794,7 @@ class ImageView(QtGui.QWidget): fileName = fileName[0] # Qt4/5 API difference if fileName == '': return - self.export(fileName) + self.export(str(fileName)) def buildMenu(self): self.menu = QtGui.QMenu() diff --git a/pyqtgraph/widgets/TableWidget.py b/pyqtgraph/widgets/TableWidget.py index 66fdea8e..90b56139 100644 --- a/pyqtgraph/widgets/TableWidget.py +++ b/pyqtgraph/widgets/TableWidget.py @@ -355,7 +355,7 @@ class TableWidget(QtGui.QTableWidget): fileName = fileName[0] # Qt4/5 API difference if fileName == '': return - open(fileName, 'w').write(data) + open(str(fileName), 'w').write(data) def contextMenuEvent(self, ev): self.contextMenu.popup(ev.globalPos())