aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-06-19 08:12:33 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-06-19 08:12:33 +0200
commitd8bd1449361835a3fe67f8ad33e82cec78940f1c (patch)
tree279e019b83fb2aa9e0673d00b5df4c432315ea51 /examples
parentb4098737b13c91ca85b69362426f0f30768c49b1 (diff)
parent7dba09d7c4007e96fb0a39bf6f6e740cd207324a (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Diffstat (limited to 'examples')
-rw-r--r--examples/webenginewidgets/tabbedbrowser/webengineview.py2
-rw-r--r--examples/widgets/mainwindows/application/application.py23
-rw-r--r--examples/widgets/mainwindows/mdi/mdi.py24
3 files changed, 28 insertions, 21 deletions
diff --git a/examples/webenginewidgets/tabbedbrowser/webengineview.py b/examples/webenginewidgets/tabbedbrowser/webengineview.py
index 7b5775bc..4fdbf180 100644
--- a/examples/webenginewidgets/tabbedbrowser/webengineview.py
+++ b/examples/webenginewidgets/tabbedbrowser/webengineview.py
@@ -79,7 +79,7 @@ class WebEngineView(QWebEngineView):
def is_web_action_enabled(self, web_action):
return self.page().action(web_action).isEnabled()
- def create_window(self, window_type):
+ def createWindow(self, window_type):
if window_type == QWebEnginePage.WebBrowserTab or window_type == QWebEnginePage.WebBrowserBackgroundTab:
return self._tab_factory_func()
return self._window_factory_func()
diff --git a/examples/widgets/mainwindows/application/application.py b/examples/widgets/mainwindows/application/application.py
index e0a46bda..624fb47d 100644
--- a/examples/widgets/mainwindows/application/application.py
+++ b/examples/widgets/mainwindows/application/application.py
@@ -229,19 +229,22 @@ class MainWindow(QtWidgets.QMainWindow):
self.statusBar().showMessage("File loaded", 2000)
def saveFile(self, fileName):
- file = QtCore.QFile(fileName)
- if not file.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text):
- QtWidgets.QMessageBox.warning(self, "Application",
- "Cannot write file %s:\n%s." % (fileName, file.errorString()))
- return False
-
- outf = QtCore.QTextStream(file)
+ error = None
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
-
- # FIXME: Once file is out of scope, the file is empty, instead of having text.
- outf << self.textEdit.toPlainText()
+ file = QtCore.QSaveFile(fileName)
+ if file.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text):
+ outf = QtCore.QTextStream(file)
+ outf << self.textEdit.toPlainText()
+ if not file.commit():
+ error = "Cannot write file %s:\n%s." % (fileName, file.errorString())
+ else:
+ error = "Cannot open file %s:\n%s." % (fileName, file.errorString())
QtWidgets.QApplication.restoreOverrideCursor()
+ if error:
+ QtWidgets.QMessageBox.warning(self, "Application", error)
+ return False
+
self.setCurrentFile(fileName)
self.statusBar().showMessage("File saved", 2000)
return True
diff --git a/examples/widgets/mainwindows/mdi/mdi.py b/examples/widgets/mainwindows/mdi/mdi.py
index b3c1c1eb..9daca826 100644
--- a/examples/widgets/mainwindows/mdi/mdi.py
+++ b/examples/widgets/mainwindows/mdi/mdi.py
@@ -43,7 +43,7 @@
"""PySide2 port of the widgets/draganddrop/draggabletext example from Qt v5.x, originating from PyQt"""
from PySide2.QtCore import (QFile, QFileInfo, QPoint, QSettings, QSignalMapper,
- QSize, QTextStream, Qt)
+ QSaveFile, QSize, QTextStream, Qt)
from PySide2.QtGui import QIcon, QKeySequence
from PySide2.QtWidgets import (QAction, QApplication, QFileDialog, QMainWindow,
QMdiArea, QMessageBox, QTextEdit, QWidget)
@@ -100,18 +100,22 @@ class MdiChild(QTextEdit):
return self.saveFile(fileName)
def saveFile(self, fileName):
- file = QFile(fileName)
-
- if not file.open(QFile.WriteOnly | QFile.Text):
- QMessageBox.warning(self, "MDI",
- "Cannot write file %s:\n%s." % (fileName, file.errorString()))
- return False
-
- outstr = QTextStream(file)
+ error = None
QApplication.setOverrideCursor(Qt.WaitCursor)
- outstr << self.toPlainText()
+ file = QSaveFile(fileName)
+ if file.open(QFile.WriteOnly | QFile.Text):
+ outstr = QTextStream(file)
+ outstr << self.toPlainText()
+ if not file.commit():
+ error = "Cannot write file %s:\n%s." % (fileName, file.errorString())
+ else:
+ error = "Cannot open file %s:\n%s." % (fileName, file.errorString())
QApplication.restoreOverrideCursor()
+ if error:
+ QMessageBox.warning(self, "MDI", error)
+ return False
+
self.setCurrentFile(fileName)
return True