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