-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from wiki-Bird/WIFI_WIDGET
Added WIFI widget & fixed weather
- Loading branch information
Showing
4 changed files
with
202 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
DEFAULTS = { | ||
# 'label': '\uf017 {%H:%M:%S}', | ||
# 'label_alt': '\uf017 {%d-%m-%y %H:%M:%S}', | ||
'label': "{wifi_icon}", | ||
'label_alt': "{wifi_icon} {wifi_name}", | ||
'update_interval': 1000, | ||
'callbacks': { | ||
'on_left': 'toggle_label', | ||
'on_middle': 'do_nothing', | ||
'on_right': 'do_nothing' | ||
}, | ||
'wifi_icons': [ | ||
"\udb82\udd2e", # Icon for 0% strength | ||
"\udb82\udd1f", # Icon for 1-25% strength | ||
"\udb82\udd22", # Icon for 26-50% strength | ||
"\udb82\udd25", # Icon for 51-75% strength | ||
"\udb82\udd28" # Icon for 76-100% strength | ||
] | ||
} | ||
|
||
VALIDATION_SCHEMA = { | ||
'label': { | ||
'type': 'string', | ||
'default': DEFAULTS['label'] | ||
}, | ||
'label_alt': { | ||
'type': 'string', | ||
'default': DEFAULTS['label_alt'] | ||
}, | ||
'update_interval': { | ||
'type': 'integer', | ||
'default': DEFAULTS['update_interval'], | ||
'min': 0, | ||
'max': 60000 | ||
}, | ||
'wifi_icons': { | ||
'type': 'list', | ||
'default': DEFAULTS['wifi_icons'], | ||
"schema": { | ||
'type': 'string', | ||
'required': False | ||
} | ||
}, | ||
'callbacks': { | ||
'type': 'dict', | ||
'schema': { | ||
'on_left': { | ||
'type': 'string', | ||
'default': DEFAULTS['callbacks']['on_left'], | ||
}, | ||
'on_middle': { | ||
'type': 'string', | ||
'default': DEFAULTS['callbacks']['on_middle'], | ||
}, | ||
'on_right': { | ||
'type': 'string', | ||
'default': DEFAULTS['callbacks']['on_right'], | ||
} | ||
}, | ||
'default': DEFAULTS['callbacks'] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from core.widgets.base import BaseWidget | ||
from core.validation.widgets.yasb.wifi import VALIDATION_SCHEMA | ||
from PyQt6.QtWidgets import QLabel | ||
import os | ||
|
||
|
||
class WifiWidget(BaseWidget): | ||
validation_schema = VALIDATION_SCHEMA | ||
|
||
def __init__( | ||
self, | ||
label: str, | ||
label_alt: str, | ||
update_interval: int, | ||
wifi_icons: list[str], | ||
callbacks: dict[str, str], | ||
): | ||
super().__init__(update_interval, class_name="wifi-widget") | ||
self._wifi_icons = wifi_icons | ||
|
||
self._show_alt_label = False | ||
self._label_content = label | ||
self._label_alt_content = label_alt | ||
|
||
self._label = QLabel() | ||
self._label_alt = QLabel() | ||
self._label.setProperty("class", "label") | ||
self._label_alt.setProperty("class", "label alt") | ||
self.widget_layout.addWidget(self._label) | ||
self.widget_layout.addWidget(self._label_alt) | ||
|
||
self.register_callback("toggle_label", self._toggle_label) | ||
self.register_callback("update_label", self._update_label) | ||
|
||
self.callback_left = callbacks['on_left'] | ||
self.callback_right = callbacks['on_right'] | ||
self.callback_middle = callbacks['on_middle'] | ||
self.callback_timer = "update_label" | ||
|
||
self._label.show() | ||
self._label_alt.hide() | ||
|
||
self.start_timer() | ||
|
||
def _toggle_label(self): | ||
self._show_alt_label = not self._show_alt_label | ||
|
||
if self._show_alt_label: | ||
self._label.hide() | ||
self._label_alt.show() | ||
else: | ||
self._label.show() | ||
self._label_alt.hide() | ||
|
||
self._update_label() | ||
|
||
def _update_label(self): | ||
wifi_icon, _ = self._get_wifi_icon() | ||
wifi_name = self._get_wifi_name() | ||
|
||
# Determine which label is active | ||
active_label = self._label_alt if self._show_alt_label else self._label | ||
|
||
if self._show_alt_label: | ||
updated_content = f"{wifi_icon} {wifi_name}" | ||
else: | ||
updated_content = f"{wifi_icon}" | ||
|
||
active_label.setText(updated_content) | ||
|
||
def _get_wifi_strength(self): | ||
# Get the wifi strength from the system | ||
result = result = os.popen('netsh wlan show interfaces').read() | ||
|
||
# Return 0 if no wifi interface is found | ||
if "There is no wireless interface on the system." in result: | ||
return 0 | ||
|
||
# Extract signal strength from the result | ||
for line in result.split('\n'): | ||
if "Signal" in line: | ||
strength = line.split(":")[1].strip().split(' ')[0].replace('%', '') | ||
return int(strength) | ||
|
||
return 0 | ||
|
||
def _get_wifi_name(self): | ||
result = result = os.popen('netsh wlan show interfaces').read() | ||
|
||
for line in result.split('\n'): | ||
if "SSID" in line: | ||
return line.split(":")[1].strip() | ||
|
||
return "No WiFi" | ||
|
||
def _get_wifi_icon(self): | ||
# Map strength to its corresponding icon | ||
strength = self._get_wifi_strength() | ||
|
||
if strength == 0: | ||
return self._wifi_icons[0], strength | ||
elif strength <= 25: | ||
return self._wifi_icons[1], strength | ||
elif strength <= 50: | ||
return self._wifi_icons[2], strength | ||
elif strength <= 75: | ||
return self._wifi_icons[3], strength | ||
else: | ||
return self._wifi_icons[4], strength |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters