ProjectDjango/DjangoSquashMigrationSelectionDialog.py

branch
eric7
changeset 180
64339135bd61
parent 175
30cb5e553e7e
child 190
f394b11f9f31
equal deleted inserted replaced
179:8413c2429808 180:64339135bd61
12 from PyQt6.QtCore import pyqtSlot 12 from PyQt6.QtCore import pyqtSlot
13 from PyQt6.QtGui import QIcon 13 from PyQt6.QtGui import QIcon
14 from PyQt6.QtWidgets import QDialog, QDialogButtonBox 14 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
15 15
16 from .Ui_DjangoSquashMigrationSelectionDialog import ( 16 from .Ui_DjangoSquashMigrationSelectionDialog import (
17 Ui_DjangoSquashMigrationSelectionDialog 17 Ui_DjangoSquashMigrationSelectionDialog,
18 ) 18 )
19 19
20 20
21 class DjangoSquashMigrationSelectionDialog( 21 class DjangoSquashMigrationSelectionDialog(
22 QDialog, Ui_DjangoSquashMigrationSelectionDialog): 22 QDialog, Ui_DjangoSquashMigrationSelectionDialog
23 ):
23 """ 24 """
24 Class implementing a dialog to enter data needed to squash migrations. 25 Class implementing a dialog to enter data needed to squash migrations.
25 """ 26 """
27
26 def __init__(self, migrations, django, suffix, parent=None): 28 def __init__(self, migrations, django, suffix, parent=None):
27 """ 29 """
28 Constructor 30 Constructor
29 31
30 @param migrations dictionary containing the available migrations 32 @param migrations dictionary containing the available migrations
31 @type dict 33 @type dict
32 @param django reference to the Django project object 34 @param django reference to the Django project object
33 @type Project 35 @type Project
34 @param suffix icon suffix 36 @param suffix icon suffix
36 @param parent reference to the parent widget 38 @param parent reference to the parent widget
37 @type QWidget 39 @type QWidget
38 """ 40 """
39 super().__init__(parent) 41 super().__init__(parent)
40 self.setupUi(self) 42 self.setupUi(self)
41 43
42 self.__appliedIcon = QIcon(os.path.join( 44 self.__appliedIcon = QIcon(
43 os.path.dirname(__file__), "icons", "applied-{0}".format(suffix) 45 os.path.join(
44 )) 46 os.path.dirname(__file__), "icons", "applied-{0}".format(suffix)
45 47 )
48 )
49
46 self.__migrations = migrations 50 self.__migrations = migrations
47 self.applicationComboBox.addItems( 51 self.applicationComboBox.addItems([""] + sorted(self.__migrations.keys()))
48 [""] + sorted(self.__migrations.keys()))
49 self.on_applicationComboBox_activated("") 52 self.on_applicationComboBox_activated("")
50 53
51 msh = self.minimumSizeHint() 54 msh = self.minimumSizeHint()
52 self.resize(max(self.width(), msh.width()), msh.height()) 55 self.resize(max(self.width(), msh.width()), msh.height())
53 56
54 def __updateOkButton(self): 57 def __updateOkButton(self):
55 """ 58 """
56 Private slot to set the enabled state of the OK button. 59 Private slot to set the enabled state of the OK button.
57 """ 60 """
58 enabled = ( 61 enabled = bool(self.applicationComboBox.currentText()) and bool(
59 bool(self.applicationComboBox.currentText()) and 62 self.endMigrationComboBox.currentText()
60 bool(self.endMigrationComboBox.currentText())) 63 )
61 self.buttonBox.button( 64 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enabled)
62 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) 65
63
64 @pyqtSlot(str) 66 @pyqtSlot(str)
65 def on_applicationComboBox_activated(self, app): 67 def on_applicationComboBox_activated(self, app):
66 """ 68 """
67 Private slot to update the migrations combo boxes. 69 Private slot to update the migrations combo boxes.
68 70
69 @param app name of the selected application 71 @param app name of the selected application
70 @type str 72 @type str
71 """ 73 """
72 self.startMigrationComboBox.clear() 74 self.startMigrationComboBox.clear()
73 self.endMigrationComboBox.clear() 75 self.endMigrationComboBox.clear()
74 if app: 76 if app:
75 for combo in [self.startMigrationComboBox, 77 for combo in [self.startMigrationComboBox, self.endMigrationComboBox]:
76 self.endMigrationComboBox]:
77 combo.addItem("") 78 combo.addItem("")
78 for applied, migration in self.__migrations[app]: 79 for applied, migration in self.__migrations[app]:
79 if applied: 80 if applied:
80 combo.addItem(self.__appliedIcon, migration) 81 combo.addItem(self.__appliedIcon, migration)
81 else: 82 else:
82 combo.addItem(migration) 83 combo.addItem(migration)
83 self.__updateOkButton() 84 self.__updateOkButton()
84 85
85 @pyqtSlot(str) 86 @pyqtSlot(str)
86 def on_endMigrationComboBox_activated(self, migration): 87 def on_endMigrationComboBox_activated(self, migration):
87 """ 88 """
88 Private slot handling the selection of a migration. 89 Private slot handling the selection of a migration.
89 90
90 @param migration name of the selected migration 91 @param migration name of the selected migration
91 @type str 92 @type str
92 """ 93 """
93 self.__updateOkButton() 94 self.__updateOkButton()
94 95
95 def getData(self): 96 def getData(self):
96 """ 97 """
97 Public method to retrieve the data entered by the user. 98 Public method to retrieve the data entered by the user.
98 99
99 @return tuple containing the selected app, the start migration, 100 @return tuple containing the selected app, the start migration,
100 the end migration and a flag indicating no optimization is wanted 101 the end migration and a flag indicating no optimization is wanted
101 @rtype tuple of three str and a bool 102 @rtype tuple of three str and a bool
102 """ 103 """
103 startMigration = ( 104 startMigration = (
104 self.startMigrationComboBox.currentText() 105 self.startMigrationComboBox.currentText()
105 if self.startMigrationComboBox.isEnabled() else 106 if self.startMigrationComboBox.isEnabled()
106 "" 107 else ""
107 ) 108 )
108 name = self.nameEdit.text() if self.nameEdit.isEnabled() else "" 109 name = self.nameEdit.text() if self.nameEdit.isEnabled() else ""
109 110
110 return ( 111 return (
111 self.applicationComboBox.currentText(), 112 self.applicationComboBox.currentText(),
112 startMigration, 113 startMigration,
113 self.endMigrationComboBox.currentText(), 114 self.endMigrationComboBox.currentText(),
114 self.noOptimizeCheckBox.isChecked(), 115 self.noOptimizeCheckBox.isChecked(),
115 name 116 name,
116 ) 117 )

eric ide

mercurial