Added the exact percentage of the battery capacity to the About section

The About section is found here:

~/launcher/Menu/GameShell/10_Settings/About

And in the file __init__.py I added the function:

def BatteryLevel(self):
    with open("/sys/class/power_supply/axp20x-battery/capacity") as f:
        battery = {}
        battery["key"] = "battery"
        battery["label"] = "Battery:"
        battery["value"] = f.read().replace("\n", "") + "%"
        self._AList["battery"] = battery

And in GenList() I added ,"battery" to the list in the for-loop.
Also, I entered the function self.BatteryLevel() in Init() before the line self.GenList().

That’s it.
Maybe you’ve fun adding this also.

–

Update: 2 typos now correct.

6 Likes

Because of the first likes I wanted to add that i can help you when you’ve got questions or other ideas.

Thanks, this looks like a very useful mod, but for some reason it didn’t work for me.
I’m not very familiar with python, so I have a question where the function definition should go? I’ve tried adding it to the end of the file and inside the AboutPage class and both times I was getting stuck on the “loading” screen unless I removed the BatteryLevel function. Just removing “battery” from for-loop and commenting out self.BatteryLevel() didn’t help, so I guess that it’s something within the function itself that was causing my problem

Hello @edward ,

no problem. I explain in detail:

In the file there are the functions calculating or getting the data at first. So, I put the BatteryLevel from above between the OsImageVersion function and the GenList function.

In the GenListfunction I added the “battery”-string in this list:

for i,u in enumerate( ["processor","armcores","cpuscalemhz","features","memory","uname","launcher_ver","os_image_ver","battery"] )

At first I had it at the end like in the line above but I changed it after “cpuscalemhz” to see it without scrolling in the About section.

But to get it working the function BatteryLevel has to be called, so the _AList is filled with the battery data. This is done in the Init function. I put it between these:

    <...>
    self.OsImageVersion()
    self.BatteryLevel()
    self.GenList()
    <...>

That’s it:

  1. The function BatteryLevel to generate the output for the About screen.
  2. Call it in Init.
  3. Add the “battery” string in GenList to show it at the place you want.

I hope you will get it work now.
If not, just ask again. No problem.

–

Additional thoughts:

  • Like everything in the Launcher, you’ve to use “Reload UI” to see changes in the battery level. But after playing a game, the launcher gets reloaded automatically, so it’s useful for me as it is.
  • And I also added additional notifications to get an info when the battery is full, 80%, 60%, 40% and 20%, additionally to the “low battery” at 10 and 5%.

Thanks for explaining everything.

It took me a while to make it work, in the end all I needed is to pay some attention and not blindly copy your code, as it has 2 typos :grinning:

Just in case anybody else tries it: battery{"label"] should have opening square bracket instead of curly one (thanks vscode, as nano didn’t highlight this), and self._Alist["battery"] should have a capital L in AList.

1 Like

You’re welcome.

I’m sorry, I edited the typos in the post above.

1 Like