src/eric7/EricNetwork/EricIPv4InputWidget.py

branch
mpy_network
changeset 9830
6c91fdb0e55b
parent 9797
3be7b2326e2c
child 10024
3bbf6dbec0bd
equal deleted inserted replaced
9829:cafb132fe3bb 9830:6c91fdb0e55b
7 Module implementing a widget to enter an IPv4 address. 7 Module implementing a widget to enter an IPv4 address.
8 """ 8 """
9 9
10 import ipaddress 10 import ipaddress
11 11
12 from PyQt6.QtCore import pyqtSignal, pyqtSlot, QRegularExpression, QEvent, Qt 12 from PyQt6.QtCore import QEvent, QRegularExpression, Qt, pyqtSignal, pyqtSlot
13 from PyQt6.QtGui import QRegularExpressionValidator 13 from PyQt6.QtGui import QRegularExpressionValidator
14 from PyQt6.QtWidgets import QWidget 14 from PyQt6.QtWidgets import QWidget
15 15
16 from eric7.EricGui import EricPixmapCache 16 from eric7.EricGui import EricPixmapCache
17 17
22 """ 22 """
23 Class implementing a widget to enter an IPv4 address. 23 Class implementing a widget to enter an IPv4 address.
24 24
25 @signal addressChanged() emitted to indicate a change of the entered IPv4 address 25 @signal addressChanged() emitted to indicate a change of the entered IPv4 address
26 """ 26 """
27
27 addressChanged = pyqtSignal() 28 addressChanged = pyqtSignal()
28 29
29 def __init__(self, parent=None): 30 def __init__(self, parent=None):
30 """ 31 """
31 Constructor 32 Constructor
69 70
70 @param obj reference to the object 71 @param obj reference to the object
71 @type QObject 72 @type QObject
72 @param evt reference to the event object 73 @param evt reference to the event object
73 @type QEvent 74 @type QEvent
75 @return flag indicating, that the event was handled
76 @rtype bool
74 """ 77 """
75 if evt.type() == QEvent.Type.KeyPress: 78 if evt.type() == QEvent.Type.KeyPress and evt.text() == ".":
76 if evt.text() == '.': 79 if obj is self.ip1Edit:
77 if obj is self.ip1Edit: 80 nextWidget = self.ip2Edit
78 nextWidget = self.ip2Edit 81 elif obj is self.ip2Edit:
79 elif obj is self.ip2Edit: 82 nextWidget = self.ip3Edit
80 nextWidget = self.ip3Edit 83 elif obj is self.ip3Edit:
81 elif obj is self.ip3Edit: 84 nextWidget = self.ip4Edit
82 nextWidget = self.ip4Edit 85 else:
83 else: 86 nextWidget = None
84 nextWidget = None 87 if nextWidget:
85 if nextWidget: 88 nextWidget.setFocus(Qt.FocusReason.TabFocusReason)
86 nextWidget.setFocus(Qt.FocusReason.TabFocusReason) 89 return True
87 return True
88 90
89 return super().eventFilter(obj, evt) 91 return super().eventFilter(obj, evt)
90 92
91 def hasAcceptableInput(self): 93 def hasAcceptableInput(self):
92 """ 94 """
126 """ 128 """
127 Public method to set the IPv4 address given a string. 129 Public method to set the IPv4 address given a string.
128 130
129 @param address IPv4 address 131 @param address IPv4 address
130 @type str 132 @type str
133 @exception ValueError raised to indicate an invalid IPv4 address
131 """ 134 """
132 if address: 135 if address:
133 try: 136 try:
134 ipaddress.IPv4Address(address) 137 ipaddress.IPv4Address(address)
135 except ipaddress.AddressValueError as err: 138 except ipaddress.AddressValueError as err:
147 """ 150 """
148 Public method to get the IPv4 address as an ipaddress.IPv4Address object. 151 Public method to get the IPv4 address as an ipaddress.IPv4Address object.
149 152
150 @return IPv4 address 153 @return IPv4 address
151 @rtype ipaddress.IPv4Address 154 @rtype ipaddress.IPv4Address
155 @exception ValueError raised to indicate an invalid IPv4 address
152 """ 156 """
153 try: 157 try:
154 return ipaddress.IPv4Address(self.text()) 158 return ipaddress.IPv4Address(self.text())
155 except ipaddress.AddressValueError as err: 159 except ipaddress.AddressValueError as err:
156 raise ValueError(str(err)) 160 raise ValueError(str(err))

eric ide

mercurial