helloSystem / Menu

Global menu bar written in Qt
43 stars 14 forks source link

If the computer has a battery, Display battery meter in the upper right corner #69

Closed louies0623 closed 3 years ago

louies0623 commented 3 years ago

When the laptop has no power supply, it can display the current battery level image image

kettle-7 commented 3 years ago

I made a battery applet a long time ago!

But not a PR...

probonopd commented 3 years ago

@linuxkettle thank you very much, I found it at https://github.com/linuxkettle/Utilities/tree/battery-status-icon/System and wlll check it out!

probonopd commented 3 years ago

This does NOT need to be run on startup, as I haven't an idea how it'll behave on PCs that don't have batteries. If anyone has such a PC, please test to see what happens.

This:

image

Should be easy to wrap it in a try: except: statement:

class BatteryApplet(QObject):
    def refresh(self):
        battery = psutil.sensors_battery()
        try:
            seconds = battery.secsleft
        except:
            sys.stderr.write("No battery found in this computer")
            exit(1)

Works for me.

This applet depends on the python psutil module, which is installed by default in helloSystem to satisfy the requirements of another package, although I'm not sure which one.

Typing h psutil in the Falkon browser address bar brings up:

kettle-7 commented 3 years ago

Okay. Thanks :)

probonopd commented 3 years ago

...added: https://github.com/helloSystem/Utilities/commit/6877579ed2ed5a428b22a52746351a9088a85b6f Thanks @linuxkettle Will be on the next experimental ISOs, build 0F27+.

kettle-7 commented 3 years ago

Is this closed now?

probonopd commented 3 years ago

...once @louies0623 confirms that it is working for him :)

louies0623 commented 3 years ago

There is a display icon, this is a great start. Next is the realization of the menu

kettle-7 commented 3 years ago

The only thing stopping that is that you can't put text in the system tray, like the percentage. Click on the menubar so that search goes blue, then hover the mouse over the battery icon for now.

probonopd commented 3 years ago

I can confirm that this works very nicely for me on an Acer TravelMate B. :+1:

probonopd commented 3 years ago

How about this?

image

kettle-7 commented 3 years ago

Looks good.

It'll be easier not having to click the menubar then do the mouse hover thing, but I hope there's a way to at some point implement more sophisticated tray icons that can show the battery percentage etc. Then we could decouple the clock and simplify it a bit, and add settings and stuff.

kettle-7 commented 3 years ago

Ayatana comes to mind.

probonopd commented 3 years ago

I don't think text instead/in addition to an icon is possible using QSystemTrayIcon.

Closing this issue as implemented. Feel free to open new issues for further refinements.

kettle-7 commented 3 years ago

Maybe I could have a closer look at Ayatana.

louies0623 commented 3 years ago

It will be more comfortable to turn the battery icon 90° to the right.

kettle-7 commented 3 years ago

That's up to elementary-xfce to do that.

probonopd commented 3 years ago

We are using an older version of their icon set, so it is unlikely to be changed there. But we can ship our own icon as part of the .app bundle and use that, independently of the icon theme.