|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 - 2017 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 __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from .Ui_HgUserConfigHostMinimumProtocolDialog import \ |
|
16 Ui_HgUserConfigHostMinimumProtocolDialog |
|
17 |
|
18 |
|
19 class HgUserConfigHostMinimumProtocolDialog( |
|
20 QDialog, Ui_HgUserConfigHostMinimumProtocolDialog): |
|
21 """ |
|
22 Class implementing a dialog to enter the minimum protocol for a host. |
|
23 """ |
|
24 def __init__(self, allowedProtocols, parent=None, host="", protocol=""): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param allowedProtocols dictionary containing the allowed protocols |
|
29 with the value as key and the display string as value |
|
30 @type dict |
|
31 @param parent reference to the parent widget |
|
32 @type QWidget |
|
33 @param host host name |
|
34 @type str |
|
35 @param protocol name of the minimum protocol for the host |
|
36 @type str |
|
37 """ |
|
38 super(HgUserConfigHostMinimumProtocolDialog, self).__init__(parent) |
|
39 self.setupUi(self) |
|
40 |
|
41 self.minimumProtocolComboBox.addItem("", "") |
|
42 for minimumProtocol in sorted(allowedProtocols.keys()): |
|
43 self.minimumProtocolComboBox.addItem( |
|
44 allowedProtocols[minimumProtocol], minimumProtocol) |
|
45 |
|
46 self.hostEdit.setText(host) |
|
47 index = self.minimumProtocolComboBox.findData(protocol) |
|
48 if index == -1: |
|
49 index = 0 |
|
50 self.minimumProtocolComboBox.setCurrentIndex(index) |
|
51 |
|
52 msh = self.minimumSizeHint() |
|
53 self.resize(max(self.width(), msh.width()), msh.height()) |
|
54 |
|
55 self.__updateOkButton() |
|
56 |
|
57 def __updateOkButton(self): |
|
58 """ |
|
59 Private method to update the status of the Ok button. |
|
60 """ |
|
61 enabled = ( |
|
62 bool(self.hostEdit.text()) and |
|
63 self.minimumProtocolComboBox.currentIndex() > 0 |
|
64 ) |
|
65 self.buttonBox.button(QDialogButtonBox.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 ) |