ProjectDjangoTagsMenu/IfTagInputDialog.py

Sat, 08 Feb 2014 18:58:33 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 08 Feb 2014 18:58:33 +0100
changeset 8
7e8f788fe340
child 10
ef5694c0bf3a
permissions
-rw-r--r--

Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.

8
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to enter the parameters for the if tag.
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt4.QtCore import pyqtSlot
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt4.QtGui import QDialog, QDialogButtonBox
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .Ui_IfTagInputDialog import Ui_IfTagInputDialog
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 class IfTagInputDialog(QDialog, Ui_IfTagInputDialog):
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Class implementing a dialog to enter the parameters for the if tag.
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 def __init__(self, parent=None):
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Constructor
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @param parent reference to the parent widget (QWidget)
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 super().__init__(parent)
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 self.setupUi(self)
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @pyqtSlot(str)
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 def on_ifEdit_textChanged(self, txt):
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Private slot to handle changes of the 'if' expression.
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(bool(txt))
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def getTag(self):
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Public method to retrieve the tag.
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @return tag (string)
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 tag = '{{% if {0} %}}\n'.format(self.ifEdit.text())
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 elifText = self.elifEdit.toPlainText()
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 if elifText:
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 for expression in elifText.splitlines():
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 if expression.strip():
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 tag += '{{% elif {0} %}}\n'.format(expression.strip())
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 if self.elseCheckBox.isChecked():
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 tag += '{% else %}\n'
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 tag += '{% endif %}'
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
7e8f788fe340 Finished the filter tags and implemented the 'humanize', 'web design' and 'static' tags and the various 'if' tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 return tag

eric ide

mercurial