ProjectDjangoTagsMenu/IfTagInputDialog.py

Sat, 31 Dec 2016 13:50:51 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Dec 2016 13:50:51 +0100
changeset 34
78bda568c0a1
parent 31
8faca9e95f38
child 39
c75a95d5cfd4
permissions
-rw-r--r--

Updated copyright for 2017.

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

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

"""
Module implementing a dialog to enter the parameters for the if tag.
"""

from __future__ import unicode_literals

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog, QDialogButtonBox

from .Ui_IfTagInputDialog import Ui_IfTagInputDialog


class IfTagInputDialog(QDialog, Ui_IfTagInputDialog):
    """
    Class implementing a dialog to enter the parameters for the if tag.
    """
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        """
        super(IfTagInputDialog, self).__init__(parent)
        self.setupUi(self)
        
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
    
    @pyqtSlot(str)
    def on_ifEdit_textChanged(self, txt):
        """
        Private slot to handle changes of the 'if' expression.
        
        @param txt text of the line edit (string)
        """
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(bool(txt))
    
    def getTag(self):
        """
        Public method to retrieve the tag.
        
        @return tag (string)
        """
        tag = '{{% if {0} %}}\n'.format(self.ifEdit.text())
        elifText = self.elifEdit.toPlainText()
        if elifText:
            for expression in elifText.splitlines():
                if expression.strip():
                    tag += '{{% elif {0} %}}\n'.format(expression.strip())
        if self.elseCheckBox.isChecked():
            tag += '{% else %}\n'
        tag += '{% endif %}'
        
        return tag

eric ide

mercurial