PyBrite/pybrite.py
2017-09-26 14:36:57 +02:00

104 lines
1.7 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Tkinter GUI to adjust xrandr brightness and gamma settings
on all connected screens on the fly
"""
from tkinter import *
import os, subprocess
config_file = os.path.expanduser('~') + "/.config/pybrite"
c = 80
d = 5
g = .8
h = .1
screens = []
try:
with open(config_file, "r") as f:
c, g = [float(a) for a in f.readline().split()]
except:
print("No config file found.")
def get_screens():
cmd = 'xrandr -q'
r = subprocess.check_output(cmd.split()).decode("utf-8")
for x in r.splitlines():
if " connected" in x:
screens.append(x.split(' ')[0])
def setbg():
lab.config(text = "%u%%" % c)
labg.config(text = "%.1f" % g)
for scr in screens:
os.system("xrandr --output %s --brightness %f --gamma %f:%f:%f" % (
scr, c / 100, g, g, g))
with open(config_file, "w") as f:
f.write("%u %.1f" % (c, g))
def mb():
global c
if c > d:
c -= d
setbg()
def pb():
global c
if c < 200 - d / 2:
c += d
setbg()
def mg():
global g
if g > 1.5 * h:
g -= h
setbg()
def pg():
global g
if g < 3 - h / 2:
g += h
setbg()
get_screens()
master = Tk()
f1 = Frame(master)
f1.pack(side = TOP, fill = Y)
f2 = Frame(master)
f2.pack(side = TOP, fill = Y)
f3 = Frame(master)
f3.pack(side = BOTTOM, fill = Y)
minus_but = Button(f1, text = " ", command = mb)
minus_but.pack(side = LEFT)
plus_but = Button(f1, text = " + ", command = pb)
plus_but.pack(side = RIGHT)
mg_but = Button(f2, text = " ", command = mg)
mg_but.pack(side = LEFT)
pb_but = Button(f2, text = " + ", command = pg)
pb_but.pack(side = RIGHT)
lab = Label(f3, text = '')
lab.pack(side = TOP)
labg = Label(f3, text = '')
labg.pack(side = TOP)
setbg()
master.title("PyBrite")
master.resizable(0, 0)
mainloop()