Skip to content

Commit a5b0756

Browse files
authored
Merge pull request #189 from trimclain/wifi-ipaddr
feat(wifi): add `{ip_addr}` as a replacement option in labels
2 parents 1df0e32 + 687d77a commit a5b0756

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

docs/widgets/(Widget)-WiFi.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| Option | Type | Default | Description |
44
|---------------------|---------|-------------------------------------------------------------------------|-----------------------------------------------------------------------------|
5-
| `label` | string | `"{icon}"` | The label format for the WiFi widget. |
5+
| `label` | string | `"{wifi_icon}"` | The label format for the WiFi widget. |
66
| `label_alt` | string | `"{wifi_name} {wifi_strength}%"` | The alternative label format for the WiFi widget. |
77
| `update_interval` | integer | `1000` | Update interval in milliseconds. |
88
| `wifi_icons` | list | `[ "\udb82\udd2e", "\udb82\udd1f", "\udb82\udd22", "\udb82\udd25", "\udb82\udd28" ]` | Icons for different WiFi signal strengths. |
@@ -11,6 +11,8 @@
1111
| `animation` | dict | `{'enabled': True, 'type': 'fadeInOut', 'duration': 200}` | Animation settings for the widget. |
1212
| `container_padding` | dict | `{'top': 0, 'left': 0, 'bottom': 0, 'right': 0}` | Explicitly set padding inside widget container. |
1313

14+
> **Note:** Available label replacements: "{wifi_icon}", "{wifi_name}", "{wifi_strength}", "{ip_addr}"
15+
1416
## Example Configuration
1517

1618
```yaml

src/core/widgets/yasb/wifi.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import re
3+
import socket
34
from winsdk.windows.networking.connectivity import NetworkInformation, NetworkConnectivityLevel
45
from core.widgets.base import BaseWidget
56
from core.validation.widgets.yasb.wifi import VALIDATION_SCHEMA
@@ -82,7 +83,7 @@ def process_content(content, is_alt=False):
8283
else:
8384
label = QLabel(part)
8485
label.setProperty("class", "label alt" if is_alt else "label")
85-
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
86+
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
8687
self._widget_container_layout.addWidget(label)
8788
widgets.append(label)
8889
if is_alt:
@@ -93,7 +94,7 @@ def process_content(content, is_alt=False):
9394
self._widgets = process_content(content)
9495
self._widgets_alt = process_content(content_alt, is_alt=True)
9596

96-
97+
9798
def _update_label(self):
9899
active_widgets = self._widgets_alt if self._show_alt_label else self._widgets
99100
active_label_content = self._label_alt_content if self._show_alt_label else self._label_content
@@ -102,6 +103,7 @@ def _update_label(self):
102103
widget_index = 0
103104
try:
104105
connection_info = NetworkInformation.get_internet_connection_profile()
106+
ip_addr = socket.gethostbyname(socket.gethostname())
105107

106108
# If no connection or WiFi connection, check WiFi connection
107109
# (it will set the icon to the 0% icon (no connection) if no WiFi connection is found)
@@ -120,15 +122,16 @@ def _update_label(self):
120122
label_options = {
121123
"{wifi_icon}": wifi_icon,
122124
"{wifi_name}": wifi_name,
123-
"{wifi_strength}": wifi_strength
125+
"{wifi_strength}": wifi_strength,
126+
"{ip_addr}": ip_addr
124127
}
125128
for part in label_parts:
126129
part = part.strip()
127130
if part:
128131
formatted_text = part
129132
for option, value in label_options.items():
130133
formatted_text = formatted_text.replace(option, str(value))
131-
134+
132135
if '<span' in part and '</span>' in part:
133136
# Update icon QLabel
134137
if widget_index < len(active_widgets) and isinstance(active_widgets[widget_index], QLabel):
@@ -137,7 +140,7 @@ def _update_label(self):
137140
# Update normal QLabel
138141
if widget_index < len(active_widgets) and isinstance(active_widgets[widget_index], QLabel):
139142
active_widgets[widget_index].setText(formatted_text)
140-
143+
141144
widget_index += 1
142145

143146
def _get_wifi_strength(self):

0 commit comments

Comments
 (0)