ProjectFlask/FlaskMigrateExtension/MigrateSummaryDialog.py

branch
eric7
changeset 64
0ee58185b8df
parent 61
fe1e8783a95f
child 66
0d3168d0e310
--- a/ProjectFlask/FlaskMigrateExtension/MigrateSummaryDialog.py	Sat May 29 15:04:41 2021 +0200
+++ b/ProjectFlask/FlaskMigrateExtension/MigrateSummaryDialog.py	Sun May 30 17:33:37 2021 +0200
@@ -7,14 +7,15 @@
 Module implementing a dialog showing a summary of all created.migrations.
 """
 
-from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QEventLoop, QTimer
-from PyQt5.QtGui import QGuiApplication
-from PyQt5.QtWidgets import (
+from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QEventLoop, QTimer
+from PyQt6.QtGui import QGuiApplication
+from PyQt6.QtWidgets import (
     QDialog, QDialogButtonBox, QAbstractButton, QTreeWidgetItem,
     QAbstractItemView
 )
 
-from E5Gui import E5MessageBox
+from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor
+from EricWidgets import EricMessageBox
 
 from .Ui_MigrateSummaryDialog import Ui_MigrateSummaryDialog
 
@@ -40,7 +41,7 @@
         self.setupUi(self)
         
         self.__refreshButton = self.buttonBox.addButton(
-            self.tr("Refresh"), QDialogButtonBox.ActionRole)
+            self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole)
         self.__refreshButton.clicked.connect(self.showSummary)
         
         self.__project = project
@@ -60,12 +61,17 @@
             self.show()
             self.raise_()
             
-            self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
-            self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
-            self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
-            self.buttonBox.button(QDialogButtonBox.Cancel).setFocus(
-                Qt.OtherFocusReason)
-            QGuiApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Close).setEnabled(False)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Cancel).setDefault(True)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Cancel).setFocus(
+                    Qt.FocusReason.OtherFocusReason)
+            QGuiApplication.processEvents(
+                QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents)
             
             command = self.__project.getFlaskCommand()
             
@@ -77,35 +83,42 @@
             if self.__migrations:
                 args += ["--directory", self.__migrations]
             
-            QGuiApplication.setOverrideCursor(Qt.WaitCursor)
-            self.__process.start(command, args)
-            ok = self.__process.waitForStarted(10000)
-            if ok:
-                ok = self.__process.waitForFinished(10000)
+            with EricOverrideCursor():
+                self.__process.start(command, args)
+                ok = self.__process.waitForStarted(10000)
                 if ok:
-                    out = str(self.__process.readAllStandardOutput(), "utf-8")
-                    self.__processOutput(out)
-                    self.__selectItem(self.__currentRevision)
+                    ok = self.__process.waitForFinished(10000)
+                    if ok:
+                        out = str(self.__process.readAllStandardOutput(),
+                                  "utf-8")
+                        self.__processOutput(out)
+                        self.__selectItem(self.__currentRevision)
+                    else:
+                        with EricOverridenCursor():
+                            EricMessageBox.critical(
+                                None,
+                                self.tr("Migrations Summary"),
+                                self.tr("""The Flask process did not finish"""
+                                        """ within 10 seconds."""))
                 else:
-                    E5MessageBox.critical(
-                        None,
-                        self.tr("Migrations Summary"),
-                        self.tr("""The Flask process did not finish within"""
-                                """ 10 seconds."""))
-            else:
-                E5MessageBox.critical(
-                    None,
-                    self.tr("Migrations Summary"),
-                    self.tr("""The Flask process could not be started."""))
-            for column in range(self.summaryWidget.columnCount()):
-                self.summaryWidget.resizeColumnToContents(column)
-            QGuiApplication.restoreOverrideCursor()
+                    with EricOverridenCursor():
+                        EricMessageBox.critical(
+                            None,
+                            self.tr("Migrations Summary"),
+                            self.tr("""The Flask process could not be"""
+                                    """ started."""))
+                for column in range(self.summaryWidget.columnCount()):
+                    self.summaryWidget.resizeColumnToContents(column)
             
-            self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
-            self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
-            self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
-            self.buttonBox.button(QDialogButtonBox.Close).setFocus(
-                Qt.OtherFocusReason)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Close).setEnabled(True)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Close).setDefault(True)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Close).setFocus(
+                    Qt.FocusReason.OtherFocusReason)
     
     def __processOutput(self, output):
         """
@@ -191,7 +204,9 @@
         @param button reference to the pressed button
         @type QAbstractButton
         """
-        if button is self.buttonBox.button(QDialogButtonBox.Cancel):
+        if button is self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Cancel
+        ):
             self.__cancelProcess()
     
     @pyqtSlot()
@@ -201,7 +216,7 @@
         """
         if (
             self.__process is not None and
-            self.__process.state() != QProcess.NotRunning
+            self.__process.state() != QProcess.ProcessState.NotRunning
         ):
             self.__process.terminate()
             QTimer.singleShot(2000, self.__process.kill)
@@ -218,9 +233,9 @@
         """
         if revision:
             items = self.summaryWidget.findItems(
-                revision, Qt.MatchExactly, 1)
+                revision, Qt.MatchFlag.MatchExactly, 1)
             if items:
                 # select the first item
                 items[0].setSelected(True)
                 self.summaryWidget.scrollToItem(
-                    items[0], QAbstractItemView.PositionAtCenter)
+                    items[0], QAbstractItemView.ScrollHint.PositionAtCenter)

eric ide

mercurial