-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier.py
50 lines (42 loc) · 1.76 KB
/
notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import dbus
class Notifier(object):
def __init__(self, bus):
self._app_name = 'auto_brightness_service'
self._bus = bus
self._proxy = self._bus.get_object('org.freedesktop.Notifications',
'/org/freedesktop/Notifications')
self._interface = dbus.Interface(self._proxy,
'org.freedesktop.Notifications')
def _get_brightness_icon(self, value):
icons = ('notification-display-brightness-off',
'notification-display-brightness-low',
'notification-display-brightness-medium',
'notification-display-brightness-high',
'notification-display-brightness-full')
if value < 10:
return icons[0]
elif value < 30:
return icons[1]
elif value < 70:
return icons[2]
elif value < 90:
return icons[3]
else:
return icons[4]
def notify(self, title, text, icon):
self._interface.Notify(self._app_name, 0, icon,
title, text, [], {}, -1)
def brightness(self, level):
icon = self._get_brightness_icon(level)
data = {'x-canonical-private-synchronous': 'brightness', 'value': level}
self._interface.Notify(self._app_name, 0, icon, ' ', '', [], data, -1)
def auto_brightness(self, on):
if on:
icon = self._get_brightness_icon(50)
text = 'Auto brightness ON'
else:
icon = self._get_brightness_icon(0)
text = 'Auto brightness OFF'
data = {'x-canonical-private-synchronous': ''}
self._interface.Notify(self._app_name, 0, icon, text, '', [], data, -1)