From ad766020f25c20b4739c10aa8177e0da9c78a9ce Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sat, 24 Mar 2018 19:52:58 +0100 Subject: switch to python3 --- tp-key-handler | 66 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'tp-key-handler') diff --git a/tp-key-handler b/tp-key-handler index 3c3856e..a47f8f8 100755 --- a/tp-key-handler +++ b/tp-key-handler @@ -1,20 +1,22 @@ -#!/usr/bin/python -import gtk +#!/usr/bin/python3 +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk import dbus import dbus.service import subprocess import time from dbus.mainloop.glib import DBusGMainLoop -import pynotify +import notify2 class KeyhandlerDBUSService(dbus.service.Object): def __init__(self): bus_name = dbus.service.BusName('org.elektranox.keyhandler', bus=dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, '/org/elektranox/keyhandler') - self.bnotice = pynotify.Notification("Backlight", "", "display-brightness-symbolic") - self.vnotice = pynotify.Notification("Volume", "", "") - self.wnotice = pynotify.Notification("WLAN", "", "") - self.mnotice = pynotify.Notification("Mouse", "", "") + self.bnotice = notify2.Notification("Backlight", "", "display-brightness-symbolic") + self.vnotice = notify2.Notification("Volume", "", "") + self.wnotice = notify2.Notification("WLAN", "", "") + self.mnotice = notify2.Notification("Mouse", "", "") def _lid_status_open(self): lidstatus = "state: unknown" @@ -62,17 +64,17 @@ class KeyhandlerDBUSService(dbus.service.Object): popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'get', 'Master'], stdout = subprocess.PIPE) popen.wait() (stdout,stderr) = popen.communicate(None) - lines = stdout.split("\n") + lines = stdout.decode("utf-8").split("\n") state = int(lines[-2].split()[3][1:-2]) muted = lines[-2].split()[5][1:-1] == "off" if muted: - self.vnotice.set_property("icon-name", "audio-volume-muted") + self.vnotice.icon = "audio-volume-muted" elif state < 20: - self.vnotice.set_property("icon-name", "audio-volume-low") + self.vnotice.icon = "audio-volume-low" elif state < 60: - self.vnotice.set_property("icon-name", "audio-volume-medium") + self.vnotice.icon = "audio-volume-medium" else: - self.vnotice.set_property("icon-name", "audio-volume-high") + self.vnotice.icon = "audio-volume-high" self.vnotice.set_hint_int32("value", state) self.vnotice.set_hint_string("synchronous", "volume") self.vnotice.show() @@ -81,23 +83,23 @@ class KeyhandlerDBUSService(dbus.service.Object): popen = subprocess.Popen(['/usr/sbin/rfkill', 'list', rfid], stdout = subprocess.PIPE) popen.wait() (stdout,stderr) = popen.communicate() - return stdout.split("\n")[1].split(" ")[2] == "no" + return stdout.decode("utf-8").split("\n")[1].split(" ")[2] == "no" def _showMicState(self): popen = subprocess.Popen(['/usr/bin/amixer', '-c', 'PCH', 'get', 'Capture'], stdout = subprocess.PIPE) popen.wait() (stdout,stderr) = popen.communicate(None) - lines = stdout.split("\n") + lines = stdout.decode("utf-8").split("\n") state = int(lines[-2].split()[4][1:-2]) muted = lines[-2].split()[6][1:-1] == "off" if muted: - self.vnotice.set_property("icon-name", "microphone-sensitivity-muted") + self.vnotice.icon = "microphone-sensitivity-muted" elif state < 20: - self.vnotice.set_property("icon-name", "microphone-sensitivity-low") + self.vnotice.icon = "microphone-sensitivity-low" elif state < 60: - self.vnotice.set_property("icon-name", "microphone-sensitivity-medium") + self.vnotice.icon = "microphone-sensitivity-medium" else: - self.vnotice.set_property("icon-name", "microphone-sensitivity-high") + self.vnotice.icon = "microphone-sensitivity-high" self.vnotice.set_hint_int32("value", state) self.vnotice.set_hint_string("synchronous", "volume") self.vnotice.show() @@ -175,11 +177,11 @@ class KeyhandlerDBUSService(dbus.service.Object): # button itself is handled by systemd state = self._rfkill_get("wlan") if state: - self.wnotice.set_property("icon-name", "network-wireless-symbolic") - self.wnotice.set_property("summary", "enabled") + self.wnotice.icon = "network-wireless-symbolic" + self.wnotice.summary = "enabled" else: - self.wnotice.set_property("icon-name", "network-wireless-offline-symbolic") - self.wnotice.set_property("summary", "disabled") + self.wnotice.icon = "network-wireless-offline-symbolic" + self.wnotice.summary = "disabled" self.wnotice.show() @dbus.service.method('org.elektranox.keyhandler') @@ -187,12 +189,12 @@ class KeyhandlerDBUSService(dbus.service.Object): popen = subprocess.Popen(['/usr/local/bin/toggle-mouse-wheel-emulation'], stdout = subprocess.PIPE) popen.wait() (stdout,stderr) = popen.communicate(None) - enabled = (stdout.find("enabled") != -1) - self.mnotice.set_property("icon-name", "/usr/share/icons/mate/48x48/devices/input-mouse.png") + enabled = (stdout.decode("utf-8").find("enabled") != -1) + self.mnotice.icon = "/usr/share/icons/mate/48x48/devices/input-mouse.png" if enabled: - self.mnotice.set_property("summary", "Mouse Wheel Emulation enabled") + self.mnotice.summary = "Mouse Wheel Emulation enabled" else: - self.mnotice.set_property("summary", "Mouse Wheel Emulation disabled") + self.mnotice.summary = "Mouse Wheel Emulation disabled" self.mnotice.show() @dbus.service.method('org.elektranox.keyhandler') @@ -214,12 +216,12 @@ class KeyhandlerDBUSService(dbus.service.Object): state = self._rfkill_get("bluetooth") if state: subprocess.call(['/usr/sbin/rfkill','block', 'bluetooth']) - self.wnotice.set_property("icon-name", "/usr/share/icons/gnome/scalable/status/bluetooth-disabled-symbolic.svg") - self.wnotice.set_property("summary", "RF blocked") + self.wnotice.icon = "/usr/share/icons/gnome/scalable/status/bluetooth-disabled-symbolic.svg" + self.wnotice.summary = "Bluetooth blocked" else: subprocess.call(['/usr/sbin/rfkill','unblock', 'bluetooth']) - self.wnotice.set_property("icon-name", "/usr/share/icons/gnome/scalable/status/bluetooth-active-symbolic.svg") - self.wnotice.set_property("summary", "RF unblocked") + self.wnotice.icon = "/usr/share/icons/gnome/scalable/status/bluetooth-active-symbolic.svg" + self.wnotice.summary = "Bluetooth unblocked" self.wnotice.show() if not state: time.sleep(1) @@ -227,5 +229,5 @@ class KeyhandlerDBUSService(dbus.service.Object): DBusGMainLoop(set_as_default=True) service = KeyhandlerDBUSService() -pynotify.init("TP Keyhandler") -gtk.main() +notify2.init("TP Keyhandler") +Gtk.main() -- cgit v1.2.3