Waybar icon indicating copy to clipboard operation
Waybar copied to clipboard

Python Script not working as expected

Open ClarkAndrews opened this issue 1 year ago • 1 comments

Hey, I was playing around with Waybar a bit and wanted to create a Python-Script dynamically choosing Icons for the integrated Network module. I tested the script itself, it works as expected, but when using it for the module it doesn't display anything.

this is my config: { "layer": "top", "position": "top", "height": 40, "width": 2400, "margin-top": 7,

"modules-left": [
	"sway/workspaces"
],

"modules-right": [
	"network",
	"memory",
	"clock"
],

"sway/workspaces": {
	"disable-scroll": true,
	"format": "{name}"
},

"clock": {
	"format": "{:%a %d %b %H:%M}",
	"tooltip": false
},
"memory": {
	"interval": 30,
	"format": "{icon} {percentage}%",
	"format-icons": "\uefc5"


},
"network": {
"exec": "python3 $HOME/.config/waybar/modules/wifi_custom.py ",
"interval": 30,
"format-wifi": "{}",
	"format-disconnected": "󰤮"

} }

this is the python file:

import subprocess

-f used to specify the output data (SIGNAL in this case)

WIFI= subprocess.check_output(["nmcli", "-t" ,"-f" ,"SIGNAL" ,"device" ,"wifi" ,"list"], text = True).split()

def get_max_signal(wifi): max_signal_strength = 0 for signal in wifi: signal_int = int(signal) if signal_int > max_signal_strength: max_signal_strength = signal_int
return max_signal_strength

def get_icon_unicode(signal_strength): if signal_strength >= 75: icon_unicode="󰤨" elif signal_strength >= 50: icon_unicode="󰤥" elif signal_strength >= 25: icon_unicode="󰤢" elif signal_strength > 0: icon_unicode="󰤟" return icon_unicode

unicode = get_icon_unicode(get_max_signal(WIFI)) print(unicode)

also added Nerd-Fonts to the style.css file (got the Icons from Nerd Fonts):

*{ font-size: 15px;

}

#memory, #network{ font-family: "Symbols Nerd Font"; }

the file is executable tho.

would appreciate your help :)

ClarkAndrews avatar Jun 21 '24 07:06 ClarkAndrews

Might want to try an explicit flush for output, e.g. see #2358

RobertMueller2 avatar Jun 21 '24 15:06 RobertMueller2