5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog showing a summary of all created.migrations. |
7 Module implementing a dialog showing a summary of all created.migrations. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QEventLoop, QTimer |
10 from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QEventLoop, QTimer |
11 from PyQt5.QtGui import QGuiApplication |
11 from PyQt6.QtGui import QGuiApplication |
12 from PyQt5.QtWidgets import ( |
12 from PyQt6.QtWidgets import ( |
13 QDialog, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, |
13 QDialog, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, |
14 QAbstractItemView |
14 QAbstractItemView |
15 ) |
15 ) |
16 |
16 |
17 from E5Gui import E5MessageBox |
17 from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor |
|
18 from EricWidgets import EricMessageBox |
18 |
19 |
19 from .Ui_MigrateSummaryDialog import Ui_MigrateSummaryDialog |
20 from .Ui_MigrateSummaryDialog import Ui_MigrateSummaryDialog |
20 |
21 |
21 |
22 |
22 class MigrateSummaryDialog(QDialog, Ui_MigrateSummaryDialog): |
23 class MigrateSummaryDialog(QDialog, Ui_MigrateSummaryDialog): |
38 """ |
39 """ |
39 super().__init__(parent) |
40 super().__init__(parent) |
40 self.setupUi(self) |
41 self.setupUi(self) |
41 |
42 |
42 self.__refreshButton = self.buttonBox.addButton( |
43 self.__refreshButton = self.buttonBox.addButton( |
43 self.tr("Refresh"), QDialogButtonBox.ActionRole) |
44 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) |
44 self.__refreshButton.clicked.connect(self.showSummary) |
45 self.__refreshButton.clicked.connect(self.showSummary) |
45 |
46 |
46 self.__project = project |
47 self.__project = project |
47 self.__migrateProject = migrateProject |
48 self.__migrateProject = migrateProject |
48 self.__migrations = migrations |
49 self.__migrations = migrations |
58 workdir, env = self.__project.prepareRuntimeEnvironment() |
59 workdir, env = self.__project.prepareRuntimeEnvironment() |
59 if env is not None: |
60 if env is not None: |
60 self.show() |
61 self.show() |
61 self.raise_() |
62 self.raise_() |
62 |
63 |
63 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
64 self.buttonBox.button( |
64 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
65 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
65 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
66 self.buttonBox.button( |
66 self.buttonBox.button(QDialogButtonBox.Cancel).setFocus( |
67 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
67 Qt.OtherFocusReason) |
68 self.buttonBox.button( |
68 QGuiApplication.processEvents(QEventLoop.ExcludeUserInputEvents) |
69 QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
|
70 self.buttonBox.button( |
|
71 QDialogButtonBox.StandardButton.Cancel).setFocus( |
|
72 Qt.FocusReason.OtherFocusReason) |
|
73 QGuiApplication.processEvents( |
|
74 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents) |
69 |
75 |
70 command = self.__project.getFlaskCommand() |
76 command = self.__project.getFlaskCommand() |
71 |
77 |
72 self.__process = QProcess() |
78 self.__process = QProcess() |
73 self.__process.setProcessEnvironment(env) |
79 self.__process.setProcessEnvironment(env) |
75 |
81 |
76 args = ["db", "history", "--indicate-current"] |
82 args = ["db", "history", "--indicate-current"] |
77 if self.__migrations: |
83 if self.__migrations: |
78 args += ["--directory", self.__migrations] |
84 args += ["--directory", self.__migrations] |
79 |
85 |
80 QGuiApplication.setOverrideCursor(Qt.WaitCursor) |
86 with EricOverrideCursor(): |
81 self.__process.start(command, args) |
87 self.__process.start(command, args) |
82 ok = self.__process.waitForStarted(10000) |
88 ok = self.__process.waitForStarted(10000) |
83 if ok: |
|
84 ok = self.__process.waitForFinished(10000) |
|
85 if ok: |
89 if ok: |
86 out = str(self.__process.readAllStandardOutput(), "utf-8") |
90 ok = self.__process.waitForFinished(10000) |
87 self.__processOutput(out) |
91 if ok: |
88 self.__selectItem(self.__currentRevision) |
92 out = str(self.__process.readAllStandardOutput(), |
|
93 "utf-8") |
|
94 self.__processOutput(out) |
|
95 self.__selectItem(self.__currentRevision) |
|
96 else: |
|
97 with EricOverridenCursor(): |
|
98 EricMessageBox.critical( |
|
99 None, |
|
100 self.tr("Migrations Summary"), |
|
101 self.tr("""The Flask process did not finish""" |
|
102 """ within 10 seconds.""")) |
89 else: |
103 else: |
90 E5MessageBox.critical( |
104 with EricOverridenCursor(): |
91 None, |
105 EricMessageBox.critical( |
92 self.tr("Migrations Summary"), |
106 None, |
93 self.tr("""The Flask process did not finish within""" |
107 self.tr("Migrations Summary"), |
94 """ 10 seconds.""")) |
108 self.tr("""The Flask process could not be""" |
95 else: |
109 """ started.""")) |
96 E5MessageBox.critical( |
110 for column in range(self.summaryWidget.columnCount()): |
97 None, |
111 self.summaryWidget.resizeColumnToContents(column) |
98 self.tr("Migrations Summary"), |
112 |
99 self.tr("""The Flask process could not be started.""")) |
113 self.buttonBox.button( |
100 for column in range(self.summaryWidget.columnCount()): |
114 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
101 self.summaryWidget.resizeColumnToContents(column) |
115 self.buttonBox.button( |
102 QGuiApplication.restoreOverrideCursor() |
116 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
103 |
117 self.buttonBox.button( |
104 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
118 QDialogButtonBox.StandardButton.Close).setDefault(True) |
105 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
119 self.buttonBox.button( |
106 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
120 QDialogButtonBox.StandardButton.Close).setFocus( |
107 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
121 Qt.FocusReason.OtherFocusReason) |
108 Qt.OtherFocusReason) |
|
109 |
122 |
110 def __processOutput(self, output): |
123 def __processOutput(self, output): |
111 """ |
124 """ |
112 Private method to process the flask output and populate the summary |
125 Private method to process the flask output and populate the summary |
113 list. |
126 list. |
189 Private slot handling a button press of the button box. |
202 Private slot handling a button press of the button box. |
190 |
203 |
191 @param button reference to the pressed button |
204 @param button reference to the pressed button |
192 @type QAbstractButton |
205 @type QAbstractButton |
193 """ |
206 """ |
194 if button is self.buttonBox.button(QDialogButtonBox.Cancel): |
207 if button is self.buttonBox.button( |
|
208 QDialogButtonBox.StandardButton.Cancel |
|
209 ): |
195 self.__cancelProcess() |
210 self.__cancelProcess() |
196 |
211 |
197 @pyqtSlot() |
212 @pyqtSlot() |
198 def __cancelProcess(self): |
213 def __cancelProcess(self): |
199 """ |
214 """ |
200 Private slot to terminate the current process. |
215 Private slot to terminate the current process. |
201 """ |
216 """ |
202 if ( |
217 if ( |
203 self.__process is not None and |
218 self.__process is not None and |
204 self.__process.state() != QProcess.NotRunning |
219 self.__process.state() != QProcess.ProcessState.NotRunning |
205 ): |
220 ): |
206 self.__process.terminate() |
221 self.__process.terminate() |
207 QTimer.singleShot(2000, self.__process.kill) |
222 QTimer.singleShot(2000, self.__process.kill) |
208 self.__process.waitForFinished(3000) |
223 self.__process.waitForFinished(3000) |
209 |
224 |
216 @param revision revision of the item to select |
231 @param revision revision of the item to select |
217 @type str |
232 @type str |
218 """ |
233 """ |
219 if revision: |
234 if revision: |
220 items = self.summaryWidget.findItems( |
235 items = self.summaryWidget.findItems( |
221 revision, Qt.MatchExactly, 1) |
236 revision, Qt.MatchFlag.MatchExactly, 1) |
222 if items: |
237 if items: |
223 # select the first item |
238 # select the first item |
224 items[0].setSelected(True) |
239 items[0].setSelected(True) |
225 self.summaryWidget.scrollToItem( |
240 self.summaryWidget.scrollToItem( |
226 items[0], QAbstractItemView.PositionAtCenter) |
241 items[0], QAbstractItemView.ScrollHint.PositionAtCenter) |