Last years I had little time for programming. Most of that time was spent maintaining Bluefish and Jailkit. Last month I wanted to write some small utilities.
First utility I wrote was a gnome-shell extension to track how the time on the computer was spent. The extension polls the current active application and it’s window title every 10 seconds and appends that to a logfile. Although I have some experience with Javascript in websites, I found it very hard. Hardest was to find examples and documentation. A simple thing like how to append a single line to a logfile took me a lot of time.
Next utility I needed was a tool to parse the window activity logfile and show useful statistics. Because of the bad experience with Javascript I choose Python. I didn’t use Glade for years, but I decided to use it for the GUI. I was very surprised with the state of Python Gtk bindings and the combination of Python and Glade. It was excellent to see how quick one can write an application with the combination of python and glade. The documentation on Python and Gtk is good (https://python-gtk-3-tutorial.readthedocs.io/en/latest/) which helps. It surprises me that Glade is mentioned only in chapter 21 of that tutorial. I would have made it chapter 2, and I would have uses it everywhere else in the tutorial.
Because the combination worked very well for me, I also used it for my next utility: saving laptop batteries. Most of my family members keep their laptops always connected to the power at home (which currently is most of the time). I have a few Sonoff switches around with self-written firmware that I can switch on/off with a JSON call. The laptops now automatically switch off their power when their batteries are >95% charged, and switch on the power when their batteries reach < 10%. Then I improved the utility to read the status of the smart meter in house, so now the laptops prefer to charge when I have excess power from my solar panels.
I used pydbus to read the battery state from the system dbus. Paho MQTT was used to read the status of my Smart meter (I have a Raspberry Pi connected to it’s serial port that puts the values on an MQTT bus). Normal python libraries like requests for the JSON call and configparser for config file loading/saving. And again the combination of Glade with Gobject introspection for Gtk and Libnotify and I got everything working in < 250 lines of code. Very happy with the result 🙂