|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter data needed to squash migrations. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtCore import pyqtSlot |
|
15 from PyQt5.QtGui import QIcon |
|
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
17 |
|
18 from .Ui_DjangoSquashMigrationSelectionDialog import \ |
|
19 Ui_DjangoSquashMigrationSelectionDialog |
|
20 |
|
21 |
|
22 class DjangoSquashMigrationSelectionDialog( |
|
23 QDialog, Ui_DjangoSquashMigrationSelectionDialog): |
|
24 """ |
|
25 Class implementing a dialog to enter data needed to squash migrations. |
|
26 """ |
|
27 def __init__(self, migrations, showStart, parent=None): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param migrations dictionary containing the available migrations |
|
32 @type dict |
|
33 @param showStart flag indicating to show the start migrations |
|
34 @type bool |
|
35 @param parent reference to the parent widget |
|
36 @type QWidget |
|
37 """ |
|
38 super(DjangoSquashMigrationSelectionDialog, self).__init__(parent) |
|
39 self.setupUi(self) |
|
40 |
|
41 self.__appliedIcon = QIcon(os.path.join( |
|
42 os.path.dirname(__file__), "icons", "applied.png")) |
|
43 |
|
44 self.startLabel.setEnabled(showStart) |
|
45 self.startMigrationComboBox.setEnabled(showStart) |
|
46 |
|
47 self.__migrations = migrations |
|
48 self.applicationComboBox.addItems( |
|
49 [""] + sorted(self.__migrations.keys())) |
|
50 self.on_applicationComboBox_activated("") |
|
51 |
|
52 msh = self.minimumSizeHint() |
|
53 self.resize(max(self.width(), msh.width()), msh.height()) |
|
54 |
|
55 def __updateOkButton(self): |
|
56 """ |
|
57 Private slot to set the enabled state of the OK button. |
|
58 """ |
|
59 enabled = ( |
|
60 bool(self.applicationComboBox.currentText()) and |
|
61 bool(self.endMigrationComboBox.currentText())) |
|
62 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled) |
|
63 |
|
64 @pyqtSlot(str) |
|
65 def on_applicationComboBox_activated(self, app): |
|
66 """ |
|
67 Private slot to update the migrations combo boxes. |
|
68 |
|
69 @param app name of the selected application |
|
70 @type str |
|
71 """ |
|
72 self.startMigrationComboBox.clear() |
|
73 self.endMigrationComboBox.clear() |
|
74 if app: |
|
75 for combo in [self.startMigrationComboBox, |
|
76 self.endMigrationComboBox]: |
|
77 combo.addItem("") |
|
78 for applied, migration in self.__migrations[app]: |
|
79 if applied: |
|
80 combo.addItem(self.__appliedIcon, migration) |
|
81 else: |
|
82 combo.addItem(migration) |
|
83 self.__updateOkButton() |
|
84 |
|
85 @pyqtSlot(str) |
|
86 def on_endMigrationComboBox_activated(self, migration): |
|
87 """ |
|
88 Private slot handling the selection of a migration. |
|
89 |
|
90 @param migration name of the selected migration |
|
91 @type str |
|
92 """ |
|
93 self.__updateOkButton() |
|
94 |
|
95 def getData(self): |
|
96 """ |
|
97 Public method to retrieve the data entered by the user. |
|
98 |
|
99 @return tuple containing the selected app, the start migration, |
|
100 the end migration and a flag indicating no optimization is wanted |
|
101 @rtype tuple of three str and a bool |
|
102 """ |
|
103 if self.startMigrationComboBox.isEnabled(): |
|
104 startMigration = self.startMigrationComboBox.currentText() |
|
105 else: |
|
106 startMigration = "" |
|
107 |
|
108 return ( |
|
109 self.applicationComboBox.currentText(), |
|
110 startMigration, |
|
111 self.endMigrationComboBox.currentText(), |
|
112 self.noOptimizeCheckBox.isChecked(), |
|
113 ) |