-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
56 lines (42 loc) · 2.15 KB
/
utils.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
51
52
53
54
55
56
import subprocess
class SessionAction(object):
@classmethod
def lock(cls):
return 'dbus-send --session --type=method_call --dest=org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.Lock uint32:1'
@classmethod
def logout(cls):
return 'dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1/user/self org.freedesktop.login1.User.Terminate'
@classmethod
def reboot(cls):
return 'dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Reboot boolean:false'
@classmethod
def power_off(cls):
return 'dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:false'
@classmethod
def suspend(cls):
return 'dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Suspend boolean:false'
@classmethod
def dnd_on(cls):
return 'gsettings set org.pantheon.desktop.gala.notifications do-not-disturb true'
@classmethod
def dnd_off(cls):
return 'gsettings set org.pantheon.desktop.gala.notifications do-not-disturb false'
@classmethod
def show_battery_percentage(cls):
return 'gsettings set org.pantheon.desktop.wingpanel.indicators.power show-percentage true'
@classmethod
def hide_battery_percentage(cls):
return 'gsettings set org.pantheon.desktop.wingpanel.indicators.power show-percentage false'
@classmethod
def get_dnd_state(cls):
schema_name = 'org.pantheon.desktop.gala.notifications'
dnd_key = 'do-not-disturb'
return cls._get_state(schema_name, dnd_key)
@classmethod
def get_battery_percentage_state(cls):
schema_name = 'org.pantheon.desktop.wingpanel.indicators.power'
battery_percentage_key = 'show-percentage'
return cls._get_state(schema_name, battery_percentage_key)
@staticmethod
def _get_state(schema_name, key):
return subprocess.check_output(["gsettings", "get", schema_name, key])[:-1] == 'true'