ProjectDjangoTagsMenu/IeCommentDialog.py

Sun, 30 May 2021 11:51:44 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 30 May 2021 11:51:44 +0200
branch
eric7
changeset 55
5390ef66c327
parent 52
c264091162a2
child 60
85d3931419d3
permissions
-rw-r--r--

Ported the plug-in to PyQt6 for eric7.

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

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

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

from PyQt6.QtWidgets 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
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)
        
        for condStr, condData in [("==", ""), ("<=", " lte"), ("<", " lt"),
                                  (">", " gt"), (">=", " gte")]:
            self.conditionalComboBox.addItem(condStr, condData)
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
        
    def getData(self):
        """
        Public method to retrieve the entered data.
        
        @return tuple of condition and version
        @rtype tuple of (str, int)
        """
        return (self.conditionalComboBox.itemData(
            self.conditionalComboBox.currentIndex()),
            self.versionSpinBox.value())
    
    @staticmethod
    def getTag(selectedText):
        """
        Public static method to get the formatted tag.
        
        @param selectedText selected text to embed
        @type str
        @return formatted tag and  a flag indicating the acceptance state
        @rtype tuple of (str, bool)
        """
        dlg = IeCommentDialog()
        if dlg.exec() == QDialog.DialogCode.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