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