ProjectDjango/DjangoMigrationsListDialog.py

branch
eric7
changeset 172
ea7980ded4f3
parent 169
b8f263e05c39
child 175
30cb5e553e7e
equal deleted inserted replaced
171:af99f0984f20 172:ea7980ded4f3
5 5
6 """ 6 """
7 Module implementing a dialog show a list of all available migrations. 7 Module implementing a dialog show a list of all available migrations.
8 """ 8 """
9 9
10 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QTimer, QPoint 10 from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QTimer, QPoint
11 from PyQt5.QtWidgets import ( 11 from PyQt6.QtWidgets import (
12 QDialog, QDialogButtonBox, QAbstractButton, 12 QDialog, QDialogButtonBox, QAbstractButton,
13 QHeaderView, QTreeWidgetItem, QMenu, QAbstractItemView, QInputDialog, 13 QHeaderView, QTreeWidgetItem, QMenu, QAbstractItemView, QInputDialog,
14 QLineEdit 14 QLineEdit
15 ) 15 )
16 16
17 from E5Gui import E5MessageBox 17 from EricWidgets import EricMessageBox
18 18
19 from .Ui_DjangoMigrationsListDialog import Ui_DjangoMigrationsListDialog 19 from .Ui_DjangoMigrationsListDialog import Ui_DjangoMigrationsListDialog
20 20
21 import Preferences 21 import Preferences
22 22
40 @type QWidget 40 @type QWidget
41 """ 41 """
42 super().__init__(parent) 42 super().__init__(parent)
43 self.setupUi(self) 43 self.setupUi(self)
44 44
45 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 45 self.buttonBox.button(
46 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 46 QDialogButtonBox.StandardButton.Close).setEnabled(False)
47 self.buttonBox.button(
48 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
47 49
48 self.ioEncoding = Preferences.getSystem("IOEncoding") 50 self.ioEncoding = Preferences.getSystem("IOEncoding")
49 51
50 self.proc = QProcess() 52 self.proc = QProcess()
51 self.proc.finished.connect(self.__procFinished) 53 self.proc.finished.connect(self.__procFinished)
62 self.setWindowTitle(self.tr("Available Migrations")) 64 self.setWindowTitle(self.tr("Available Migrations"))
63 self.migrationsList.setHeaderLabels([ 65 self.migrationsList.setHeaderLabels([
64 self.tr("Name"), 66 self.tr("Name"),
65 ]) 67 ])
66 self.migrationsList.setSelectionMode( 68 self.migrationsList.setSelectionMode(
67 QAbstractItemView.ExtendedSelection) 69 QAbstractItemView.SelectionMode.ExtendedSelection)
68 else: 70 else:
69 self.setWindowTitle(self.tr("Migrations Plan")) 71 self.setWindowTitle(self.tr("Migrations Plan"))
70 self.migrationsList.setHeaderLabels([ 72 self.migrationsList.setHeaderLabels([
71 self.tr("Migration"), 73 self.tr("Migration"),
72 self.tr("Dependencies"), 74 self.tr("Dependencies"),
73 ]) 75 ])
74 self.migrationsList.setSelectionMode( 76 self.migrationsList.setSelectionMode(
75 QAbstractItemView.SingleSelection) 77 QAbstractItemView.SelectionMode.SingleSelection)
76 78
77 self.refreshButton = self.buttonBox.addButton( 79 self.refreshButton = self.buttonBox.addButton(
78 self.tr("&Refresh"), QDialogButtonBox.ActionRole) 80 self.tr("&Refresh"), QDialogButtonBox.ButtonRole.ActionRole)
79 self.refreshButton.setToolTip( 81 self.refreshButton.setToolTip(
80 self.tr("Press to refresh the list")) 82 self.tr("Press to refresh the list"))
81 self.refreshButton.setEnabled(False) 83 self.refreshButton.setEnabled(False)
82 84
83 @pyqtSlot(QAbstractButton) 85 @pyqtSlot(QAbstractButton)
86 Private slot called by a button of the button box clicked. 88 Private slot called by a button of the button box clicked.
87 89
88 @param button button that was clicked 90 @param button button that was clicked
89 @type QAbstractButton 91 @type QAbstractButton
90 """ 92 """
91 if button == self.buttonBox.button(QDialogButtonBox.Close): 93 if button == self.buttonBox.button(
94 QDialogButtonBox.StandardButton.Close
95 ):
92 self.close() 96 self.close()
93 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 97 elif button == self.buttonBox.button(
98 QDialogButtonBox.StandardButton.Cancel
99 ):
94 self.__finish() 100 self.__finish()
95 elif button == self.refreshButton: 101 elif button == self.refreshButton:
96 self.on_refreshButton_clicked() 102 self.on_refreshButton_clicked()
97 103
98 def __finish(self): 104 def __finish(self):
100 Private slot called when the process finished or the user pressed the 106 Private slot called when the process finished or the user pressed the
101 button. 107 button.
102 """ 108 """
103 if ( 109 if (
104 self.proc is not None and 110 self.proc is not None and
105 self.proc.state() != QProcess.NotRunning 111 self.proc.state() != QProcess.ProcessState.NotRunning
106 ): 112 ):
107 self.proc.terminate() 113 self.proc.terminate()
108 QTimer.singleShot(2000, self.proc.kill) 114 QTimer.singleShot(2000, self.proc.kill)
109 self.proc.waitForFinished(3000) 115 self.proc.waitForFinished(3000)
110 116
111 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 117 self.buttonBox.button(
112 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 118 QDialogButtonBox.StandardButton.Close).setEnabled(True)
113 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 119 self.buttonBox.button(
120 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
121 self.buttonBox.button(
122 QDialogButtonBox.StandardButton.Close).setDefault(True)
114 123
115 self.refreshButton.setEnabled(True) 124 self.refreshButton.setEnabled(True)
116 125
117 self.__resizeColumns() 126 self.__resizeColumns()
118 127
119 def __procFinished(self, exitCode, exitStatus): 128 def __procFinished(self, exitCode, exitStatus):
120 """ 129 """
121 Private slot connected to the finished signal. 130 Private slot connected to the finished signal.
122 131
123 @param exitCode exit code of the process (integer) 132 @param exitCode exit code of the process
124 @param exitStatus exit status of the process (QProcess.ExitStatus) 133 @type int
134 @param exitStatus exit status of the process
135 @type QProcess.ExitStatus
125 """ 136 """
126 self.__finish() 137 self.__finish()
127 138
128 def __resizeColumns(self): 139 def __resizeColumns(self):
129 """ 140 """
130 Private method to resize the list columns. 141 Private method to resize the list columns.
131 """ 142 """
132 self.migrationsList.header().resizeSections( 143 self.migrationsList.header().resizeSections(
133 QHeaderView.ResizeToContents) 144 QHeaderView.ResizeMode.ResizeToContents)
134 if self.__mode == DjangoMigrationsListDialog.MigrationsListMode: 145 if self.__mode == DjangoMigrationsListDialog.MigrationsListMode:
135 self.migrationsList.header().setStretchLastSection(True) 146 self.migrationsList.header().setStretchLastSection(True)
136 147
137 def start(self, pythonExecutable, sitePath, databaseName): 148 def start(self, pythonExecutable, sitePath, databaseName):
138 """ 149 """
172 183
173 self.proc.start(pythonExecutable, args) 184 self.proc.start(pythonExecutable, args)
174 procStarted = self.proc.waitForStarted() 185 procStarted = self.proc.waitForStarted()
175 if not procStarted: 186 if not procStarted:
176 self.buttonBox.setFocus() 187 self.buttonBox.setFocus()
177 E5MessageBox.critical( 188 EricMessageBox.critical(
178 self, 189 self,
179 self.tr('Process Generation Error'), 190 self.tr('Process Generation Error'),
180 self.tr( 191 self.tr(
181 'The process {0} could not be started. ' 192 'The process {0} could not be started. '
182 'Ensure, that it is in the search path.' 193 'Ensure, that it is in the search path.'
218 if self.__lastTopItem: 229 if self.__lastTopItem:
219 itm = QTreeWidgetItem(self.__lastTopItem, [name]) 230 itm = QTreeWidgetItem(self.__lastTopItem, [name])
220 else: 231 else:
221 itm = QTreeWidgetItem(self.migrationsList, [name]) 232 itm = QTreeWidgetItem(self.migrationsList, [name])
222 if applied[1] == " ": 233 if applied[1] == " ":
223 itm.setCheckState(0, Qt.Unchecked) 234 itm.setCheckState(0, Qt.CheckState.Unchecked)
224 else: 235 else:
225 itm.setCheckState(0, Qt.Checked) 236 itm.setCheckState(0, Qt.CheckState.Checked)
226 237
227 def __createPlanItem(self, line): 238 def __createPlanItem(self, line):
228 """ 239 """
229 Private method to create an item for plan mode. 240 Private method to create an item for plan mode.
230 241
246 itm = QTreeWidgetItem(self.migrationsList, [ 257 itm = QTreeWidgetItem(self.migrationsList, [
247 parts[0].strip(), 258 parts[0].strip(),
248 "", 259 "",
249 ]) 260 ])
250 if applied[1] != " ": 261 if applied[1] != " ":
251 itm.setCheckState(0, Qt.Checked) 262 itm.setCheckState(0, Qt.CheckState.Checked)
252 263
253 def __readStderr(self): 264 def __readStderr(self):
254 """ 265 """
255 Private slot to handle the readyReadStderr signal. 266 Private slot to handle the readyReadStderr signal.
256 267
267 @pyqtSlot() 278 @pyqtSlot()
268 def on_refreshButton_clicked(self): 279 def on_refreshButton_clicked(self):
269 """ 280 """
270 Private slot to refresh the log. 281 Private slot to refresh the log.
271 """ 282 """
272 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 283 self.buttonBox.button(
273 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) 284 QDialogButtonBox.StandardButton.Close).setEnabled(False)
274 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 285 self.buttonBox.button(
286 QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
287 self.buttonBox.button(
288 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
275 289
276 self.refreshButton.setEnabled(False) 290 self.refreshButton.setEnabled(False)
277 291
278 self.start(self.__pyExe, self.__sitePath) 292 self.start(self.__pyExe, self.__sitePath)
279 293
379 migration, ok = QInputDialog.getText( 393 migration, ok = QInputDialog.getText(
380 self, 394 self,
381 self.tr("Make Migrations"), 395 self.tr("Make Migrations"),
382 self.tr("Enter a name for the migrations (leave empty to" 396 self.tr("Enter a name for the migrations (leave empty to"
383 " use system supplied name):"), 397 " use system supplied name):"),
384 QLineEdit.Normal) 398 QLineEdit.EchoMode.Normal)
385 399
386 if ok: 400 if ok:
387 self.__django.makeMigrations(apps, migration, dryRun, empty, 401 self.__django.makeMigrations(apps, migration, dryRun, empty,
388 True) 402 True)
389 403

eric ide

mercurial