Created
April 10, 2020 16:01
-
-
Save ungive/86efc57646337f834f7e7ba5b2cfe107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys, subprocess, os | |
from subprocess import PIPE, Popen | |
from threading import Thread | |
from queue import Queue, Empty | |
def enqueue_output(out, queue): | |
for line in iter(out.readline, b''): | |
queue.put(line) | |
out.close() | |
def popen_stdout(args): | |
p = subprocess.Popen(args, stdout=subprocess.PIPE) | |
return p.communicate()[0] | |
def set_brightness(opval): | |
int_val = int(opval) | |
with open(brightness_file, 'w') as fh: | |
fh.write("%d" % int_val) | |
brightness_file = "/sys/class/backlight/radeon_bl0/brightness" | |
low = 1 | |
high = 255 | |
curr = int(popen_stdout(["cat",brightness_file]).strip()) | |
p = Popen([ | |
"zenity","--scale","--print-partial", "--value=%d" % curr, | |
"--title","Screen Brightness","--text","","--min-value=%d" % low, | |
"--max-value=%d" % high, "--step=1" | |
], stdout=PIPE, close_fds=True) | |
q = Queue() | |
t = Thread(target=enqueue_output, args=(p.stdout, q)) | |
t.daemon = True | |
t.start() | |
while True: | |
try: line = q.get_nowait() | |
except Empty: | |
if not t.is_alive(): | |
p.wait() | |
if p.returncode == 1: | |
set_brightness(curr) | |
break | |
else: | |
set_brightness(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment