ProjectDjango/DjangoMigrationSelectionDialog.py

Mon, 19 Dec 2016 19:26:40 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 19 Dec 2016 19:26:40 +0100
changeset 74
f33822c3eb47
child 75
0165ce437462
permissions
-rw-r--r--

Added some forgotten files.

# -*- coding: utf-8 -*-

# Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to select an application and migration.
"""

from __future__ import unicode_literals
try:
    str = unicode    # __IGNORE_WARNING__
except NameError:
    pass

import os

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QDialog

from .Ui_DjangoMigrationSelectionDialog import \
    Ui_DjangoMigrationSelectionDialog


class DjangoMigrationSelectionDialog(QDialog,
                                     Ui_DjangoMigrationSelectionDialog):
    """
    Class implementing a dialog to select an application and migration.
    """
    def __init__(self, migrations, parent=None):
        """
        Constructor
        
        @param pythonExecutable Python executable to be used
        @type str
        @param sitePath path of the site
        @type str
        @param parent reference to the parent widget
        @type QWidget
        """
        super(DjangoMigrationSelectionDialog, self).__init__(parent)
        self.setupUi(self)
        
        self.__appliedIcon = QIcon(os.path.join(
            os.path.dirname(__file__), "icons", "applied.png"))
        
        self.__migrations = migrations
        self.applicationComboBox.addItems(sorted(self.__migrations.keys()))
        self.on_applicationComboBox_activated(
            self.applicationComboBox.currentText())
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    @pyqtSlot(str)
    def on_applicationComboBox_activated(self, app):
        """
        Private slot to update the migrations combo box.
        
        @param app name of the selected application
        @type str
        """
        self.migrationsComboBox.clear()
        self.migrationsComboBox.addItem("")
        for applied, migration in self.__migrations[app]:
            if applied:
                self.migrationsComboBox.addItem(self.__appliedIcon, migration)
            else:
                self.migrationsComboBox.addItem(migration)
    
    def getData(self):
        """
        Public method to get the selected data.
        
        @return tuple containing the selected application name and migration
        @rtype tuple of two str
        """
        return (self.applicationComboBox.currentText(),
                self.migrationsComboBox.currentText())

eric ide

mercurial