|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to select an application and migration. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 try: |
|
12 str = unicode # __IGNORE_WARNING__ |
|
13 except NameError: |
|
14 pass |
|
15 |
|
16 import os |
|
17 |
|
18 from PyQt5.QtCore import pyqtSlot |
|
19 from PyQt5.QtGui import QIcon |
|
20 from PyQt5.QtWidgets import QDialog |
|
21 |
|
22 from .Ui_DjangoMigrationSelectionDialog import \ |
|
23 Ui_DjangoMigrationSelectionDialog |
|
24 |
|
25 |
|
26 class DjangoMigrationSelectionDialog(QDialog, |
|
27 Ui_DjangoMigrationSelectionDialog): |
|
28 """ |
|
29 Class implementing a dialog to select an application and migration. |
|
30 """ |
|
31 def __init__(self, migrations, parent=None): |
|
32 """ |
|
33 Constructor |
|
34 |
|
35 @param pythonExecutable Python executable to be used |
|
36 @type str |
|
37 @param sitePath path of the site |
|
38 @type str |
|
39 @param parent reference to the parent widget |
|
40 @type QWidget |
|
41 """ |
|
42 super(DjangoMigrationSelectionDialog, self).__init__(parent) |
|
43 self.setupUi(self) |
|
44 |
|
45 self.__appliedIcon = QIcon(os.path.join( |
|
46 os.path.dirname(__file__), "icons", "applied.png")) |
|
47 |
|
48 self.__migrations = migrations |
|
49 self.applicationComboBox.addItems(sorted(self.__migrations.keys())) |
|
50 self.on_applicationComboBox_activated( |
|
51 self.applicationComboBox.currentText()) |
|
52 |
|
53 msh = self.minimumSizeHint() |
|
54 self.resize(max(self.width(), msh.width()), msh.height()) |
|
55 |
|
56 @pyqtSlot(str) |
|
57 def on_applicationComboBox_activated(self, app): |
|
58 """ |
|
59 Private slot to update the migrations combo box. |
|
60 |
|
61 @param app name of the selected application |
|
62 @type str |
|
63 """ |
|
64 self.migrationsComboBox.clear() |
|
65 self.migrationsComboBox.addItem("") |
|
66 for applied, migration in self.__migrations[app]: |
|
67 if applied: |
|
68 self.migrationsComboBox.addItem(self.__appliedIcon, migration) |
|
69 else: |
|
70 self.migrationsComboBox.addItem(migration) |
|
71 |
|
72 def getData(self): |
|
73 """ |
|
74 Public method to get the selected data. |
|
75 |
|
76 @return tuple containing the selected application name and migration |
|
77 @rtype tuple of two str |
|
78 """ |
|
79 return (self.applicationComboBox.currentText(), |
|
80 self.migrationsComboBox.currentText()) |