ProjectDjangoTagsMenu/IeCommentDialog.py

Sun, 16 Feb 2014 16:12:58 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 16 Feb 2014 16:12:58 +0100
changeset 16
f2d493540f04
parent 10
ef5694c0bf3a
child 21
2f95d929282e
permissions
-rw-r--r--

Added Python2 compatibility code.

# -*- coding: utf-8 -*-

# Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to enter data for an IE comment.
"""

from __future__ import unicode_literals    # __IGNORE_WARNING__

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(IeCommentDialog, self).__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

eric ide

mercurial