diff -r 7e8f788fe340 -r 1b11bf54b3b2 ProjectDjangoTagsMenu/IeCommentDialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ProjectDjangoTagsMenu/IeCommentDialog.py Sun Feb 09 18:21:45 2014 +0100 @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +""" +Module implementing a dialog to enter data for an IE comment. +""" + +from PyQt4.QtGui import QDialog + +from .Ui_IeCommentDialog import Ui_IeCommentDialog + + +class IeCommentDialog(QDialog, Ui_IeCommentDialog): + """ + Class implementing a dialog to enter data for an IE comment. + """ + def __init__(self, parent=None): + """ + Constructor + + @param parent reference to the parent widget (QWidget) + """ + super().__init__(parent) + self.setupUi(self) + + for condStr, condData in [("==", ""), ("<=", " lte"), ("<", " lt"), + (">", " gt"), (">=", " gte")]: + self.conditionalComboBox.addItem(condStr, condData) + + def getData(self): + """ + Public method to retrieve the entered data. + + @return tuple of condition (string) and version (integer) + """ + return (self.conditionalComboBox.itemData( + self.conditionalComboBox.currentIndex()), + self.versionSpinBox.value()) + + @staticmethod + def getTag(selectedText): + """ + Static method to get the formatted tag. + + @param selectedText selected text to embed (string) + @return formatted tag (string) and a flag indicating the acceptance + state (boolean) + """ + dlg = IeCommentDialog() + if dlg.exec_() == QDialog.Accepted: + condition, version = dlg.getData() + tag = '[if{0} IE {1}]> {2} <![endif]'.format( + condition, version, selectedText) + return tag, True + else: + return "", False