Sun, 30 May 2021 17:33:37 +0200
Ported the plug-in to PyQt6 for eric7.
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
60
02243723ac17
Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
39
diff
changeset
|
3 | # Copyright (c) 2020 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a dialog showing a summary of all created.migrations. |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
10 | from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QEventLoop, QTimer |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
11 | from PyQt6.QtGui import QGuiApplication |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
12 | from PyQt6.QtWidgets import ( |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
13 | QDialog, QDialogButtonBox, QAbstractButton, QTreeWidgetItem, |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
14 | QAbstractItemView |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | ) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
17 | from EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
18 | from EricWidgets import EricMessageBox |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | from .Ui_MigrateSummaryDialog import Ui_MigrateSummaryDialog |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | class MigrateSummaryDialog(QDialog, Ui_MigrateSummaryDialog): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | Class implementing a dialog showing a summary of all created.migrations. |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | def __init__(self, project, migrateProject, migrations="", parent=None): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | Constructor |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | |
36
548dea93941c
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
31 | @param project reference to the project object |
548dea93941c
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
32 | @type Project |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | @param migrateProject reference to the migrate project extension |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | @type MigrateProject |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | @param migrations directory path containing the migrations |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | @type str |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | @param parent reference to the parent widget |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | @type QWidget |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | """ |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
40 | super().__init__(parent) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | self.setupUi(self) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | self.__refreshButton = self.buttonBox.addButton( |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
44 | self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | self.__refreshButton.clicked.connect(self.showSummary) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | self.__project = project |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | self.__migrateProject = migrateProject |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | self.__migrations = migrations |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
50 | |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | self.__process = None |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
52 | self.__currentItemIndex = 1000000 |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
53 | self.__currentRevision = "" |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | def showSummary(self): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | Public method to show the migrations summary. |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | workdir, env = self.__project.prepareRuntimeEnvironment() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | if env is not None: |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | self.show() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | self.raise_() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
64 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
65 | QDialogButtonBox.StandardButton.Close).setEnabled(False) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
66 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
67 | QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
68 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
69 | QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
70 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
71 | QDialogButtonBox.StandardButton.Cancel).setFocus( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
72 | Qt.FocusReason.OtherFocusReason) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
73 | QGuiApplication.processEvents( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
74 | QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | command = self.__project.getFlaskCommand() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | self.__process = QProcess() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | self.__process.setProcessEnvironment(env) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | self.__process.setWorkingDirectory(workdir) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | args = ["db", "history", "--indicate-current"] |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | if self.__migrations: |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | args += ["--directory", self.__migrations] |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
86 | with EricOverrideCursor(): |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
87 | self.__process.start(command, args) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
88 | ok = self.__process.waitForStarted(10000) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | if ok: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
90 | ok = self.__process.waitForFinished(10000) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
91 | if ok: |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
92 | out = str(self.__process.readAllStandardOutput(), |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
93 | "utf-8") |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
94 | self.__processOutput(out) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
95 | self.__selectItem(self.__currentRevision) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
96 | else: |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
97 | with EricOverridenCursor(): |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
98 | EricMessageBox.critical( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
99 | None, |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
100 | self.tr("Migrations Summary"), |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
101 | self.tr("""The Flask process did not finish""" |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
102 | """ within 10 seconds.""")) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | else: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
104 | with EricOverridenCursor(): |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
105 | EricMessageBox.critical( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
106 | None, |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
107 | self.tr("Migrations Summary"), |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
108 | self.tr("""The Flask process could not be""" |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
109 | """ started.""")) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
110 | for column in range(self.summaryWidget.columnCount()): |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
111 | self.summaryWidget.resizeColumnToContents(column) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
113 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
114 | QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
115 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
116 | QDialogButtonBox.StandardButton.Close).setEnabled(True) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
117 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
118 | QDialogButtonBox.StandardButton.Close).setDefault(True) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
119 | self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
120 | QDialogButtonBox.StandardButton.Close).setFocus( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
121 | Qt.FocusReason.OtherFocusReason) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | def __processOutput(self, output): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | Private method to process the flask output and populate the summary |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | list. |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | @param output output of the flask process |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | @type str |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | self.summaryWidget.clear() |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
132 | self.upDownButton.setEnabled(False) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
133 | self.__currentItemIndex = 1000000 |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
134 | self.__currentRevision = "" |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | lines = output.splitlines() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | for line in lines: |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | isCurrent = False |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | oldRev, rest = line.split("->") |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | rest, message = rest.split(",", 1) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | newRev, *labels = rest.split() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | if labels: |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | labelList = [ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | label.replace("(", "").replace(")", "") |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | for label in labels |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | ] |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | labelsStr = ", ".join(labelList) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | if "current" in labelList: |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | isCurrent = True |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | else: |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | labelsStr = "" |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | itm = QTreeWidgetItem(self.summaryWidget, [ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | oldRev.strip(), |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | newRev.strip(), |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | message.strip(), |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | labelsStr, |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | ]) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | if isCurrent: |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | font = itm.font(0) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | font.setBold(True) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | for column in range(self.summaryWidget.columnCount()): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | itm.setFont(column, font) |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
164 | |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
165 | self.__currentItemIndex = ( |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
166 | self.summaryWidget.indexOfTopLevelItem(itm) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
167 | ) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
168 | self.__currentRevision = newRev.strip() |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | @pyqtSlot() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | def on_summaryWidget_itemSelectionChanged(self): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | Private slot to handle the selection of an entry. |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | """ |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
175 | items = self.summaryWidget.selectedItems() |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
176 | if items: |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
177 | index = self.summaryWidget.indexOfTopLevelItem(items[0]) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
178 | if index < self.__currentItemIndex: |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
179 | self.upDownButton.setText(self.tr("Upgrade")) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
180 | elif index > self.__currentItemIndex: |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
181 | self.upDownButton.setText(self.tr("Downgrade")) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
182 | self.upDownButton.setEnabled(index != self.__currentItemIndex) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
183 | else: |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
184 | self.upDownButton.setEnabled(False) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | @pyqtSlot() |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
187 | def on_upDownButton_clicked(self): |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | """ |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
189 | Private slot to upgrade/downgrade to the selected revision. |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | itm = self.summaryWidget.selectedItems()[0] |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | rev = itm.text(1) |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
193 | if self.upDownButton.text() == self.tr("Upgrade"): |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
194 | self.__migrateProject.upgradeDatabase(revision=rev) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
195 | else: |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
196 | self.__migrateProject.downgradeDatabase(revision=rev) |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | self.showSummary() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | @pyqtSlot(QAbstractButton) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | def on_buttonBox_clicked(self, button): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | """ |
36
548dea93941c
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
202 | Private slot handling a button press of the button box. |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | @param button reference to the pressed button |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | @type QAbstractButton |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | """ |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
207 | if button is self.buttonBox.button( |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
208 | QDialogButtonBox.StandardButton.Cancel |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
209 | ): |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | self.__cancelProcess() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | @pyqtSlot() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | def __cancelProcess(self): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | Private slot to terminate the current process. |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | """ |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | if ( |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | self.__process is not None and |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
219 | self.__process.state() != QProcess.ProcessState.NotRunning |
35
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | ): |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | self.__process.terminate() |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | QTimer.singleShot(2000, self.__process.kill) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | self.__process.waitForFinished(3000) |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | |
65a377b7a52c
Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | self.__process = None |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
226 | |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
227 | def __selectItem(self, revision): |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
228 | """ |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
229 | Private method to select an item given its revision. |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
230 | |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
231 | @param revision revision of the item to select |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
232 | @type str |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
233 | """ |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
234 | if revision: |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
235 | items = self.summaryWidget.findItems( |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
236 | revision, Qt.MatchFlag.MatchExactly, 1) |
39
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
237 | if items: |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
238 | # select the first item |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
239 | items[0].setSelected(True) |
120f30d7b949
MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
36
diff
changeset
|
240 | self.summaryWidget.scrollToItem( |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
241 | items[0], QAbstractItemView.ScrollHint.PositionAtCenter) |