From 42d96d0c21525c35dc5181c7cf1cc9106759363f Mon Sep 17 00:00:00 2001 From: Billy Su Date: Mon, 2 Apr 2018 19:26:01 +0800 Subject: [PATCH 1/2] Remove outdated comments --- pyqtgraph/graphicsItems/PlotItem/PlotItem.py | 8 -------- pyqtgraph/graphicsItems/tests/test_GraphicsItem.py | 11 ----------- 2 files changed, 19 deletions(-) diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py index 7321702c..65e10439 100644 --- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py +++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py @@ -356,14 +356,6 @@ class PlotItem(GraphicsWidget): v = np.clip(alpha, 0, 1)*self.ctrl.gridAlphaSlider.maximum() self.ctrl.gridAlphaSlider.setValue(v) - #def paint(self, *args): - #prof = debug.Profiler() - #QtGui.QGraphicsWidget.paint(self, *args) - - ## bad idea. - #def __getattr__(self, attr): ## wrap ms - #return getattr(self.vb, attr) - def close(self): #print "delete", self ## Most of this crap is needed to avoid PySide trouble. diff --git a/pyqtgraph/graphicsItems/tests/test_GraphicsItem.py b/pyqtgraph/graphicsItems/tests/test_GraphicsItem.py index 112dd4d5..47dfd907 100644 --- a/pyqtgraph/graphicsItems/tests/test_GraphicsItem.py +++ b/pyqtgraph/graphicsItems/tests/test_GraphicsItem.py @@ -34,14 +34,3 @@ def test_getViewWidget_deleted(): assert not pg.Qt.isQObjectAlive(view) assert item.getViewWidget() is None - - -#if __name__ == '__main__': - #view = pg.PlotItem() - #vref = weakref.ref(view) - #item = pg.InfiniteLine() - #view.addItem(item) - #del view - #gc.collect() - - \ No newline at end of file From 90857e7f27fb0a0523754e41646b4b3a0a73e1e4 Mon Sep 17 00:00:00 2001 From: Billy Su Date: Thu, 5 Apr 2018 00:25:36 +0800 Subject: [PATCH 2/2] Extract _choose_filename_dialog() as helper func To reduce the redundancy, extract the same code as a helper function _choose_filename_dialog() in PlotItem class --- pyqtgraph/graphicsItems/PlotItem/PlotItem.py | 45 ++++++++------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py index 65e10439..fdf60399 100644 --- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py +++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py @@ -694,16 +694,9 @@ class PlotItem(GraphicsWidget): ## Qt's SVG-writing capabilities are pretty terrible. def writeSvgCurves(self, fileName=None): if fileName is None: - self.fileDialog = FileDialog() - if PlotItem.lastFileDir is not None: - self.fileDialog.setDirectory(PlotItem.lastFileDir) - self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile) - self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) - self.fileDialog.show() - self.fileDialog.fileSelected.connect(self.writeSvg) + self._choose_filename_dialog(handler=self.writeSvg) return - #if fileName is None: - #fileName = QtGui.QFileDialog.getSaveFileName() + if isinstance(fileName, tuple): raise Exception("Not implemented yet..") fileName = str(fileName) @@ -780,7 +773,9 @@ class PlotItem(GraphicsWidget): def writeSvg(self, fileName=None): if fileName is None: - fileName = QtGui.QFileDialog.getSaveFileName() + self._choose_filename_dialog(handler=self.writeSvg) + return + fileName = str(fileName) PlotItem.lastFileDir = os.path.dirname(fileName) @@ -790,16 +785,9 @@ class PlotItem(GraphicsWidget): def writeImage(self, fileName=None): if fileName is None: - self.fileDialog = FileDialog() - if PlotItem.lastFileDir is not None: - self.fileDialog.setDirectory(PlotItem.lastFileDir) - self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile) - self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) - self.fileDialog.show() - self.fileDialog.fileSelected.connect(self.writeImage) + self._choose_filename_dialog(handler=self.writeImage) return - #if fileName is None: - #fileName = QtGui.QFileDialog.getSaveFileName() + if isinstance(fileName, tuple): raise Exception("Not implemented yet..") fileName = str(fileName) @@ -813,16 +801,9 @@ class PlotItem(GraphicsWidget): def writeCsv(self, fileName=None): if fileName is None: - self.fileDialog = FileDialog() - if PlotItem.lastFileDir is not None: - self.fileDialog.setDirectory(PlotItem.lastFileDir) - self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile) - self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) - self.fileDialog.show() - self.fileDialog.fileSelected.connect(self.writeCsv) + self._choose_filename_dialog(handler=self.writeCsv) return - #if fileName is None: - #fileName = QtGui.QFileDialog.getSaveFileName() + fileName = str(fileName) PlotItem.lastFileDir = os.path.dirname(fileName) @@ -1227,3 +1208,11 @@ class PlotItem(GraphicsWidget): #else: #self.autoBtn.show() + def _choose_filename_dialog(self, handler): + self.fileDialog = FileDialog() + if PlotItem.lastFileDir is not None: + self.fileDialog.setDirectory(PlotItem.lastFileDir) + self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile) + self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) + self.fileDialog.show() + self.fileDialog.fileSelected.connect(handler)