src/eric7/MicroPython/EthernetDialogs/IPv4AddressDialog.py

branch
mpy_network
changeset 9878
a82014a9e57b
child 10153
ffe7432f716b
equal deleted inserted replaced
9877:dad1f6d37366 9878:a82014a9e57b
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter an IPv4 address.
8 """
9
10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
12
13 from .Ui_IPv4AddressDialog import Ui_IPv4AddressDialog
14
15
16 class IPv4AddressDialog(QDialog, Ui_IPv4AddressDialog):
17 """
18 Class implementing a dialog to enter an IPv4 address.
19 """
20
21 def __init__(self, withDhcp=False, parent=None):
22 """
23 Constructor
24
25 @param withDhcp flag indicating to allow the DHCP selection
26 @type bool
27 @param parent reference to the parent widget (defaults to None)
28 @type QWidget (optional)
29 """
30 super().__init__(parent)
31 self.setupUi(self)
32
33 self.__withDhcp = withDhcp
34 self.dhcpCheckBox.setVisible(withDhcp)
35 if withDhcp:
36 self.dhcpCheckBox.clicked.connect(self.__updateOk)
37 self.dhcpCheckBox.clicked.connect(self.ipAddressGroup.setDisabled)
38
39 self.addressEdit.addressChanged.connect(self.__updateOk)
40 self.netmaskEdit.addressChanged.connect(self.__updateOk)
41 self.gatewayEdit.addressChanged.connect(self.__updateOk)
42 self.dnsEdit.addressChanged.connect(self.__updateOk)
43
44 self.__updateOk()
45
46 msh = self.minimumSizeHint()
47 self.resize(max(self.width(), msh.width()), msh.height())
48
49 @pyqtSlot()
50 def __updateOk(self):
51 """
52 Private method to update the enabled state of the OK button.
53 """
54 enable = (self.__withDhcp and self.dhcpCheckBox.isChecked()) or (
55 self.addressEdit.hasAcceptableInput()
56 and self.netmaskEdit.hasAcceptableInput()
57 and self.gatewayEdit.hasAcceptableInput()
58 and self.dnsEdit.hasAcceptableInput()
59 )
60
61 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
62
63 def getIPv4Address(self):
64 """
65 Public method to get the entered IPv4 address.
66
67 @return tuple containing the IPv4 address, the netmask, the gateway address and
68 the resolver address or the string 'dhcp' if dynamic addressing was selected
69 @rtype tuple (str, str, str, str) or str
70 """
71 if self.dhcpCheckBox.isChecked():
72 return "dhcp"
73 else:
74 return (
75 self.addressEdit.text(),
76 self.netmaskEdit.text(),
77 self.gatewayEdit.text(),
78 self.dnsEdit.text(),
79 )

eric ide

mercurial