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 """ |
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)) |