Plugins/VcsPlugins/vcsMercurial/HgUserConfigHostMinimumProtocolDialog.py

changeset 5641
3ced21e990eb
child 6048
82ad8ec9548c
diff -r 2e046f1818ed -r 3ced21e990eb Plugins/VcsPlugins/vcsMercurial/HgUserConfigHostMinimumProtocolDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/HgUserConfigHostMinimumProtocolDialog.py	Tue Mar 21 19:34:33 2017 +0100
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2016 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to enter the minimum protocol for a host.
+"""
+
+from __future__ import unicode_literals
+
+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.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