|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 """ |
|
4 Module implementing a dialog to enter data for an IE comment. |
|
5 """ |
|
6 |
|
7 from PyQt4.QtGui import QDialog |
|
8 |
|
9 from .Ui_IeCommentDialog import Ui_IeCommentDialog |
|
10 |
|
11 |
|
12 class IeCommentDialog(QDialog, Ui_IeCommentDialog): |
|
13 """ |
|
14 Class implementing a dialog to enter data for an IE comment. |
|
15 """ |
|
16 def __init__(self, parent=None): |
|
17 """ |
|
18 Constructor |
|
19 |
|
20 @param parent reference to the parent widget (QWidget) |
|
21 """ |
|
22 super().__init__(parent) |
|
23 self.setupUi(self) |
|
24 |
|
25 for condStr, condData in [("==", ""), ("<=", " lte"), ("<", " lt"), |
|
26 (">", " gt"), (">=", " gte")]: |
|
27 self.conditionalComboBox.addItem(condStr, condData) |
|
28 |
|
29 def getData(self): |
|
30 """ |
|
31 Public method to retrieve the entered data. |
|
32 |
|
33 @return tuple of condition (string) and version (integer) |
|
34 """ |
|
35 return (self.conditionalComboBox.itemData( |
|
36 self.conditionalComboBox.currentIndex()), |
|
37 self.versionSpinBox.value()) |
|
38 |
|
39 @staticmethod |
|
40 def getTag(selectedText): |
|
41 """ |
|
42 Static method to get the formatted tag. |
|
43 |
|
44 @param selectedText selected text to embed (string) |
|
45 @return formatted tag (string) and a flag indicating the acceptance |
|
46 state (boolean) |
|
47 """ |
|
48 dlg = IeCommentDialog() |
|
49 if dlg.exec_() == QDialog.Accepted: |
|
50 condition, version = dlg.getData() |
|
51 tag = '[if{0} IE {1}]> {2} <![endif]'.format( |
|
52 condition, version, selectedText) |
|
53 return tag, True |
|
54 else: |
|
55 return "", False |