You are not logged in.

#1 2022-05-10 01:37:58

Gabachin
Member
Registered: 2022-05-06
Posts: 91

Custom Qtile Widget Output Rendering out of Position on Bar (Solved)

I have a Qtile wm setup on a vanilla Arch install. As my laptop is old, I want to monitor the fan speed, so I created this simple widget:

 

widget.GenPollText(update_interval=1, func=lambda: subprocess.check_output("/home/paul/.config/qtile/scripts/fan.sh").decode("utf-8"), fmt='{}'), 

I haven't tweaked it yet but it runs with no error. The output is a four digit number followed by a space then RPM, like this: 2490 RPM. The problem is, it is rendered out of position on the bar. It is based half-way up the width of the bar. I think I need to adjust

  .decode("utf-8") 

but I don't know how. How do I get the output centered?

Last edited by Gabachin (2022-05-14 00:27:45)

Offline

#2 2022-05-10 09:33:54

SweepingBishops
Member
Registered: 2022-02-14
Posts: 30

Re: Custom Qtile Widget Output Rendering out of Position on Bar (Solved)

> The problem is, it is rendered out of position on the bar. It is based half-way up the width of the bar.


Is the text shown outside the widget, or inside?
If it is inside, you should be able to use string formatting to get the output centered within the widget. Try doing

.decode("utf-8").strip()

This removes the newline character at the end.

If it is outside, something is wrong. What is the string output given by your fan.sh script?

Offline

#3 2022-05-11 17:59:02

Gabachin
Member
Registered: 2022-05-06
Posts: 91

Re: Custom Qtile Widget Output Rendering out of Position on Bar (Solved)

The output was half-in, half-out of the widget, displaced vertically. When I changed utf-8 to utf-16, it centered properly, but of course, the characters were not rendered properly. Your suggestion worked. Can you explain what "This removes the newline character at the end" means? Thanks!

Offline

#4 2022-05-12 09:23:30

SweepingBishops
Member
Registered: 2022-02-14
Posts: 30

Re: Custom Qtile Widget Output Rendering out of Position on Bar (Solved)

Gabachin wrote:

Can you explain what "This removes the newline character at the end" means?

The output of a command usually has a newline character (a "\n") at the end. So the widget was actually showing the fan speed and an empty line. .strip() is a python string method to remove all whitespace before and after the string, this includes newlines.
Happy to have been of help!

Offline

#5 2022-05-14 00:27:13

Gabachin
Member
Registered: 2022-05-06
Posts: 91

Re: Custom Qtile Widget Output Rendering out of Position on Bar (Solved)

Got it!

Offline

Board footer

Powered by FluxBB