eric7/Plugins/VcsPlugins/vcsMercurial/HgUserConfigHostMinimumProtocolDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the minimum protocol for a host.
8 """
9
10 from PyQt5.QtCore import pyqtSlot
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
12
13 from .Ui_HgUserConfigHostMinimumProtocolDialog import (
14 Ui_HgUserConfigHostMinimumProtocolDialog
15 )
16
17
18 class HgUserConfigHostMinimumProtocolDialog(
19 QDialog, Ui_HgUserConfigHostMinimumProtocolDialog):
20 """
21 Class implementing a dialog to enter the minimum protocol for a host.
22 """
23 def __init__(self, allowedProtocols, parent=None, host="", protocol=""):
24 """
25 Constructor
26
27 @param allowedProtocols dictionary containing the allowed protocols
28 with the value as key and the display string as value
29 @type dict
30 @param parent reference to the parent widget
31 @type QWidget
32 @param host host name
33 @type str
34 @param protocol name of the minimum protocol for the host
35 @type str
36 """
37 super().__init__(parent)
38 self.setupUi(self)
39
40 self.minimumProtocolComboBox.addItem("", "")
41 for minimumProtocol in sorted(allowedProtocols.keys()):
42 self.minimumProtocolComboBox.addItem(
43 allowedProtocols[minimumProtocol], minimumProtocol)
44
45 self.hostEdit.setText(host)
46 index = self.minimumProtocolComboBox.findData(protocol)
47 if index == -1:
48 index = 0
49 self.minimumProtocolComboBox.setCurrentIndex(index)
50
51 msh = self.minimumSizeHint()
52 self.resize(max(self.width(), msh.width()), msh.height())
53
54 self.__updateOkButton()
55
56 def __updateOkButton(self):
57 """
58 Private method to update the status of the Ok button.
59 """
60 enabled = (
61 bool(self.hostEdit.text()) and
62 self.minimumProtocolComboBox.currentIndex() > 0
63 )
64 self.buttonBox.button(
65 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled)
66
67 @pyqtSlot(str)
68 def on_hostEdit_textChanged(self, txt):
69 """
70 Private slot to handle changes of the host edit.
71
72 @param txt current text
73 @type str
74 """
75 self.__updateOkButton()
76
77 @pyqtSlot(int)
78 def on_minimumProtocolComboBox_currentIndexChanged(self, index):
79 """
80 Private slot to handle the selection of a minimum protocol.
81
82 @param index index of the selected entry
83 @type int
84 """
85 self.__updateOkButton()
86
87 def getData(self):
88 """
89 Public method to retrieve the data.
90
91 @return tuple containig the host name and the minimum protocol
92 @rtype tuple of two str
93 """
94 return (
95 self.hostEdit.text().strip(),
96 self.minimumProtocolComboBox.itemData(
97 self.minimumProtocolComboBox.currentIndex())
98 )

eric ide

mercurial