Giter Club home page Giter Club logo

Comments (3)

yurtemre7 avatar yurtemre7 commented on September 26, 2024 1

You guys may want to look into what I made: https://github.com/yurtemre7/mouse-battery
:)

from rivalcfg.

flozz avatar flozz commented on September 26, 2024

Rivalcfg is currently only a CLI and a Python library, so it will not implement any GUI nor tray icon (at least not as a direct part of it, it can be a separated program).

Someone seems to be working on a GNOME Shell extension to display the battery level (see #198), and it should not be too difficult to implement a simple Python script that display a tray icon using TKinter

from rivalcfg.

flozz avatar flozz commented on September 26, 2024

Hum... It seems there is nothing in tk for handling systray... But I found a way to do it with pystray and Pillow:

pip install rivalcfg pystray pillow
import os

os.environ["PYSTRAY_BACKEND"] = "xorg"

import threading
import time

from PIL import Image, ImageDraw
import pystray
import rivalcfg


def create_image(
    percent,
    width=16,
    height=16,
    color_bg="black",
    color_high="lime",
    color_low="red",
):
    image = Image.new("RGB", (width, height), color_bg)
    dc = ImageDraw.Draw(image)
    bar_height = max(min(int(height * percent / 100), height), 1)
    dc.rectangle(
        (0, height - bar_height, width, height),
        fill=color_high if percent > 25 else color_low,
    )
    return image


mouse = rivalcfg.get_first_mouse()

icon = pystray.Icon(
    "test name",
    icon=create_image(0),
)
threading.Thread(target=icon.run).start()

while True:
    battery_info = mouse.battery
    level = 0
    if battery_info["level"]:
        level = battery_info["level"]
    icon.icon = create_image(level)
    time.sleep(60)

This code can be improved but it works :)

from rivalcfg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.