ProjectDjangoTagsMenu/IfTagInputDialog.py

Sat, 23 Dec 2023 15:48:51 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Dec 2023 15:48:51 +0100
branch
eric7
changeset 70
ce1c2effa0e0
parent 69
9acb6987ce60
child 74
a25b858e18a7
permissions
-rw-r--r--

Updated copyright for 2024.

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
70
ce1c2effa0e0 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 69
diff changeset
3 # Copyright (c) 2014 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
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
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
55
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
10 from PyQt6.QtCore import pyqtSlot
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
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
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 """
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
20
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
21 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
22 """
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 Constructor
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
24
55
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
25 @param parent reference to the parent widget
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
26 @type QWidget
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
27 """
52
c264091162a2 - implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 51
diff changeset
28 super().__init__(parent)
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
29 self.setupUi(self)
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
30
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
31 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
32
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
33 @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
34 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
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 Private slot to handle changes of the 'if' expression.
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
37
55
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
38 @param txt text of the line edit
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
39 @type str
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
40 """
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
41 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt))
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
42
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
43 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
44 """
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 Public method to retrieve the tag.
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
46
55
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
47 @return tag
5390ef66c327 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
48 @rtype str
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
49 """
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
50 tag = "{{% if {0} %}}\n".format(self.ifEdit.text())
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
51 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
52 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
53 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
54 if expression.strip():
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
55 tag += "{{% elif {0} %}}\n".format(expression.strip())
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
56 if self.elseCheckBox.isChecked():
63
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
57 tag += "{% else %}\n"
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
58 tag += "{% endif %}"
85418cf03fdb Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 60
diff changeset
59
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
60 return tag

eric ide

mercurial