ProjectDjangoTagsMenu/IfTagInputDialog.py

changeset 8
7e8f788fe340
child 10
ef5694c0bf3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectDjangoTagsMenu/IfTagInputDialog.py	Sat Feb 08 18:58:33 2014 +0100
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to enter the parameters for the if tag.
+"""
+
+from PyQt4.QtCore import pyqtSlot
+from PyQt4.QtGui 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().__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.
+        """
+        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