Re-implementing xbattbar in Python

One of my favourite accessory programs for X is 'xbattbar' which puts a 3px wide line all along one side of your X screen with part of it red and part of it blue to indicate how much battery remains. Obviously there are many other battery indicators, and it's also obvious that this one has fallen out of favour: the original author vanished years ago (last updates circa 2010) and now it's no longer supported in Debian because the maintainer there has evidently lost interest. I'm not sure it was ever supported as a package in Fedora. By some judicious hacking of both the C and Python components from the most recent Debian source package, I've convinced it to build on Fedora 31. I'm not particularly happy with this solution as I'm well aware of my complete lack of C knowledge and only basic Python skills. What I'd like to do is to re-implement this idea in pure Python with a more flexible vision. 'xbattbar' already allows you to use an accessory script (a couple are provided, in Python) to feed values to xbattbar. So I was thinking of re-implementing it without the idea that it's just for batteries, but could show you hard drive usage or network throughput (although sample rate becomes an issue then: xbattbar allows adjustment of sample rate, but by default it's every 5 or 10 seconds). I think this is a good idea, but my limited Python experience barely extends beyond basic CLI and administrative scripts. So the questions for all of you are, has someone already done this, and if not, where do I start on figuring out how to draw a bar on an X screen without a window around it? -- Giles https://www.gilesorr.com/ gilesorr@gmail.com

On Mon, Jan 06, 2020 at 03:41:59PM -0500, Giles Orr via talk wrote:
One of my favourite accessory programs for X is 'xbattbar' which puts a 3px wide line all along one side of your X screen with part of it red and part of it blue to indicate how much battery remains. Obviously there are many other battery indicators, and it's also obvious that this one has fallen out of favour: the original author vanished years ago (last updates circa 2010) and now it's no longer supported in Debian because the maintainer there has evidently lost interest. I'm not sure it was ever supported as a package in Fedora.
By some judicious hacking of both the C and Python components from the most recent Debian source package, I've convinced it to build on Fedora 31. I'm not particularly happy with this solution as I'm well aware of my complete lack of C knowledge and only basic Python skills. What I'd like to do is to re-implement this idea in pure Python with a more flexible vision. 'xbattbar' already allows you to use an accessory script (a couple are provided, in Python) to feed values to xbattbar. So I was thinking of re-implementing it without the idea that it's just for batteries, but could show you hard drive usage or network throughput (although sample rate becomes an issue then: xbattbar allows adjustment of sample rate, but by default it's every 5 or 10 seconds).
I think this is a good idea, but my limited Python experience barely extends beyond basic CLI and administrative scripts. So the questions for all of you are, has someone already done this, and if not, where do I start on figuring out how to draw a bar on an X screen without a window around it?
I think the xpymon project could be a good starting point. https://github.com/h-ohsaki/xpymon/blob/master/xpymon It unfortunately uses x11util and perlcompat python modules that don't appear to be commonly packaged, but you could probably copy the required functions from those modules to use as needed. -- Len Sorensen

On Thu, 9 Jan 2020 at 12:07, Lennart Sorensen <lsorense@csclub.uwaterloo.ca> wrote:
On Mon, Jan 06, 2020 at 03:41:59PM -0500, Giles Orr via talk wrote:
One of my favourite accessory programs for X is 'xbattbar' which puts a 3px wide line all along one side of your X screen with part of it red and part of it blue to indicate how much battery remains. Obviously there are many other battery indicators, and it's also obvious that this one has fallen out of favour: the original author vanished years ago (last updates circa 2010) and now it's no longer supported in Debian because the maintainer there has evidently lost interest. I'm not sure it was ever supported as a package in Fedora.
By some judicious hacking of both the C and Python components from the most recent Debian source package, I've convinced it to build on Fedora 31. I'm not particularly happy with this solution as I'm well aware of my complete lack of C knowledge and only basic Python skills. What I'd like to do is to re-implement this idea in pure Python with a more flexible vision. 'xbattbar' already allows you to use an accessory script (a couple are provided, in Python) to feed values to xbattbar. So I was thinking of re-implementing it without the idea that it's just for batteries, but could show you hard drive usage or network throughput (although sample rate becomes an issue then: xbattbar allows adjustment of sample rate, but by default it's every 5 or 10 seconds).
I think this is a good idea, but my limited Python experience barely extends beyond basic CLI and administrative scripts. So the questions for all of you are, has someone already done this, and if not, where do I start on figuring out how to draw a bar on an X screen without a window around it?
I think the xpymon project could be a good starting point.
https://github.com/h-ohsaki/xpymon/blob/master/xpymon
It unfortunately uses x11util and perlcompat python modules that don't appear to be commonly packaged, but you could probably copy the required functions from those modules to use as needed.
You're right - that's an excellent starting point. I found, and was hoping to use, python-xlib: https://github.com/python-xlib/python-xlib/tree/master/examples . But this is a more complete example. I'd definitely like to excise the perlcompat ... Anyway, between the two I might actually get somewhere with this idea. Thanks! -- Giles https://www.gilesorr.com/ gilesorr@gmail.com

On Fri, Jan 10, 2020 at 08:48:26AM -0500, Giles Orr via talk wrote:
You're right - that's an excellent starting point. I found, and was hoping to use, python-xlib: https://github.com/python-xlib/python-xlib/tree/master/examples . But this is a more complete example. I'd definitely like to excise the perlcompat ... Anyway, between the two I might actually get somewhere with this idea. Thanks!
I find it somewhat horrible that someone even thought to make a perlcompat module for python. -- Len Sorensen

On Fri, 10 Jan 2020 at 15:35, Lennart Sorensen <lsorense@csclub.uwaterloo.ca> wrote:
On Fri, Jan 10, 2020 at 08:48:26AM -0500, Giles Orr via talk wrote:
You're right - that's an excellent starting point. I found, and was hoping to use, python-xlib: https://github.com/python-xlib/python-xlib/tree/master/examples . But this is a more complete example. I'd definitely like to excise the perlcompat ... Anyway, between the two I might actually get somewhere with this idea. Thanks!
I find it somewhat horrible that someone even thought to make a perlcompat module for python.
That's not the worst of it: I thought "why did he use 'perlcompat' just for 'die' and 'getopts'?" So I replaced those commands with the Python equivalents and removed the library. Only to discover that "x11utils" requires "perlcompat". Seriously? And "pip3" doesn't even know it's a dependency so you have to install it by hand. Kinda unimpressive. -- Giles https://www.gilesorr.com/ gilesorr@gmail.com

On Sun, Jan 12, 2020 at 10:53:16AM -0500, Giles Orr via talk wrote:
That's not the worst of it: I thought "why did he use 'perlcompat' just for 'die' and 'getopts'?" So I replaced those commands with the Python equivalents and removed the library. Only to discover that "x11utils" requires "perlcompat". Seriously? And "pip3" doesn't even know it's a dependency so you have to install it by hand. Kinda unimpressive.
x11utils and perlcompat did appear like they were by the same author, and I guess they are. Seems like they are modules written by a perl fan that is having issues getting used to python. Looks like the same person did x11utils, perlcompat, xpymon, xpywm, xpylog and a few other things. -- Len Sorensen

On Tue, 14 Jan 2020 at 11:15, Lennart Sorensen <lsorense@csclub.uwaterloo.ca> wrote:
On Sun, Jan 12, 2020 at 10:53:16AM -0500, Giles Orr via talk wrote:
That's not the worst of it: I thought "why did he use 'perlcompat' just for 'die' and 'getopts'?" So I replaced those commands with the Python equivalents and removed the library. Only to discover that "x11utils" requires "perlcompat". Seriously? And "pip3" doesn't even know it's a dependency so you have to install it by hand. Kinda unimpressive.
x11utils and perlcompat did appear like they were by the same author, and I guess they are.
Seems like they are modules written by a perl fan that is having issues getting used to python. Looks like the same person did x11utils, perlcompat, xpymon, xpywm, xpylog and a few other things.
Heh - a Window Manager written in Python I didn't know about. Excellent: I've added it to my list of WMs. -- Giles https://www.gilesorr.com/ gilesorr@gmail.com
participants (2)
-
Giles Orr
-
lsorense@csclub.uwaterloo.ca