0

This is what I have done cause I can't figure out how to use the dbus library This script polls my mouse's DPI for when it gets changed by the button on the mouse and sets it to something usable then prints the current DPI to a KDE widget but I am using the subprocess library cause I can't figure out how to use the dbus library

#!/usr/bin/env python3
from openrazer.client import DeviceManager
from time import sleep
from subprocess import run as call
from sys import argv
if len(argv) == 1:
    print("No DIY bar ID given!")
    quit()
ID='/id_'+argv[1]
dev=DeviceManager().devices[0]
l_out=0
while True:
    if not dev:
        sleep(3)
        if DeviceManager().devices[0]:
            dev=DeviceManager().devices[0]
        continue;
    dpi=dev.dpi
    if dpi[0] == dpi[1]:
        if dpi[0] == 1800:
            dev.dpi=(900,900)
        elif dpi[0] == 4500:
            dev.dpi=(1000,1000)
        elif dpi[0] == 9000:
            dev.dpi=(1100,1100)
        elif dpi[0] == 16000:
            dev.dpi=(1200,1200)
        out=str(dev.dpi[0])
    else:
        out=str(dpi[0])+','+str(dpi[1])
    if not l_out == out:
        call(['qdbus','org.kde.plasma.doityourselfbar',ID,'org.kde.plasma.doityourselfbar.pass','|A|<img src="/usr/local/share/icons/diybar/mouse.svg" height="22"/>'+out+' DPI|'+dev.name+'||'])
    l_out=out
    sleep(0.7)

example shell command

qdbus org.kde.plasma.doityourselfbar /id_10 org.kde.plasma.doityourselfbar.pass '|A|<img src="/usr/local/share/icons/diybar/mouse.svg" height="22"/>900 DPI|Razer DeathAdder Elite||'

I have looked at the documentation for dbus, but i have given up trying to figure it out

1 Answers1

0

As it says at the top of the dbus documentation you linked to:

dbus-python might not be the best D-Bus binding for you to use.

It may be better to use a more modern library like pydbus

I don't have your setup to test but my best guess of how to convert the command:

qdbus org.kde.plasma.doityourselfbar /id_10 org.kde.plasma.doityourselfbar.pass '|A|<img src="/usr/local/share/icons/diybar/mouse.svg" height="22"/>900 DPI|Razer DeathAdder Elite||'

using pydbus would be

from pydbus import SessionBus

bus = SessionBus()
bar = bus.get('org.kde.plasma.doityourselfbar', '/id_10')

bar.pass('|A|<img src="/usr/local/share/icons/diybar/mouse.svg" height="22"/>900 DPI|Razer DeathAdder Elite||')

ukBaz
  • 6,985
  • 2
  • 8
  • 31