eric6/Plugins/VcsPlugins/vcsMercurial/HgUserConfigHostMinimumProtocolDialog.py

Tue, 02 Mar 2021 17:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 02 Mar 2021 17:17:09 +0100
changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8218
7c09585bd960
permissions
-rw-r--r--

Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.

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

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

"""
Module implementing a dialog to enter the minimum protocol for a host.
"""

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog, QDialogButtonBox

from .Ui_HgUserConfigHostMinimumProtocolDialog import (
    Ui_HgUserConfigHostMinimumProtocolDialog
)


class HgUserConfigHostMinimumProtocolDialog(
        QDialog, Ui_HgUserConfigHostMinimumProtocolDialog):
    """
    Class implementing a dialog to enter the minimum protocol for a host.
    """
    def __init__(self, allowedProtocols, parent=None, host="", protocol=""):
        """
        Constructor
        
        @param allowedProtocols dictionary containing the allowed protocols
            with the value as key and the display string as value
        @type dict
        @param parent reference to the parent widget
        @type QWidget
        @param host host name
        @type str
        @param protocol name of the minimum protocol for the host
        @type str
        """
        super(HgUserConfigHostMinimumProtocolDialog, self).__init__(parent)
        self.setupUi(self)
        
        self.minimumProtocolComboBox.addItem("", "")
        for minimumProtocol in sorted(allowedProtocols.keys()):
            self.minimumProtocolComboBox.addItem(
                allowedProtocols[minimumProtocol], minimumProtocol)
        
        self.hostEdit.setText(host)
        index = self.minimumProtocolComboBox.findData(protocol)
        if index == -1:
            index = 0
        self.minimumProtocolComboBox.setCurrentIndex(index)
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
        
        self.__updateOkButton()
    
    def __updateOkButton(self):
        """
        Private method to update the status of the Ok button.
        """
        enabled = (
            bool(self.hostEdit.text()) and
            self.minimumProtocolComboBox.currentIndex() > 0
        )
        self.buttonBox.button(
            QDialogButtonBox.StandardButton.Ok).setEnabled(enabled)
    
    @pyqtSlot(str)
    def on_hostEdit_textChanged(self, txt):
        """
        Private slot to handle changes of the host edit.
        
        @param txt current text
        @type str
        """
        self.__updateOkButton()
    
    @pyqtSlot(int)
    def on_minimumProtocolComboBox_currentIndexChanged(self, index):
        """
        Private slot to handle the selection of a minimum protocol.
        
        @param index index of the selected entry
        @type int
        """
        self.__updateOkButton()
    
    def getData(self):
        """
        Public method to retrieve the data.
        
        @return tuple containig the host name and the minimum protocol
        @rtype tuple of two str
        """
        return (
            self.hostEdit.text().strip(),
            self.minimumProtocolComboBox.itemData(
                self.minimumProtocolComboBox.currentIndex())
        )

eric ide

mercurial