-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjust.py
61 lines (52 loc) · 1.95 KB
/
adjust.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
57
58
59
60
61
#!/usr/bin/python
import sys
import gi
import math
gi.require_version('Notify', '0.7')
from gi.repository import Notify
# Change these
BRIGHTNESS_BASE = "/sys/class/backlight/intel_backlight/"
BRIGHTNESS_MAX = "max_brightness"
BRIGHTNESS_ACTUAL = "actual_brightness"
BRIGHTNESS_SET = "brightness"
MAX_BRIGHTNESS_DIVIDED_BY = 10
NOTIFICATIONS = True
def get_max_brightness():
f = open(BRIGHTNESS_BASE + BRIGHTNESS_MAX, "rt")
value = f.readline().strip()
return int(value)
def get_actual_brightness():
f = open(BRIGHTNESS_BASE + BRIGHTNESS_ACTUAL, "rt")
value = f.readline().strip()
return int(value)
def adjust_brightness(new_brightness):
f = open(BRIGHTNESS_BASE + BRIGHTNESS_SET, "w")
f.write(str(new_brightness))
def show_notification(header, content):
if NOTIFICATIONS:
Notify.init(header)
notification = Notify.Notification.new(header, content, "dialog-information")
notification.show()
def main():
args = sys.argv
step = math.floor(get_max_brightness() / MAX_BRIGHTNESS_DIVIDED_BY)
if len(args) < 2:
show_notification("Screen brightness error", "Incorrect arguments!")
else:
if args[1] == 'inc':
#increase screen brightness
if(get_max_brightness() >= (get_actual_brightness() + step)):
adjust_brightness(get_actual_brightness() + step)
else:
show_notification("Screen brightness", "Full brightness already!")
adjust_brightness(get_max_brightness())
else:
#decrease screen brightness
if((get_actual_brightness() - step) >= 0):
adjust_brightness(get_actual_brightness() - step)
else:
show_notification("Screen brightness", "Minimum brightness already!")
#adjust_brightness(0)
show_notification("Screen brightness", "Brightness: " + str(get_actual_brightness()))
if __name__ == '__main__':
main()