-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha-better-redshift.py
executable file
·144 lines (115 loc) · 4.19 KB
/
a-better-redshift.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/python3
import os
import gi
import signal
import time
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk as gtk
from gi.repository import AppIndicator3 as appindicator
gi.require_version('Notify', '0.7')
from gi.repository import Notify as notify
from set_temperature import TemperatureWindow
from set_brightness import BrightnessWindow
def main():
cwd = os.path.dirname(__file__) + '/icon_white_themes.png'
print(cwd)
indicator = appindicator.Indicator.new("Bettershift", os.path.abspath(
cwd), appindicator.IndicatorCategory.SYSTEM_SERVICES)
indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
indicator.set_menu(build_menu())
gtk.main()
def build_menu():
menu = gtk.Menu()
info = gtk.MenuItem("Click to refresh stats")
info.connect('activate', refresh, info)
menu.append(info)
init()
temperature = gtk.MenuItem('Set Temperature')
temperature.connect('activate', set_temperature)
menu.append(temperature)
brightness = gtk.MenuItem('Set Brightness')
brightness.connect('activate', set_brightness)
menu.append(brightness)
item_quit = gtk.MenuItem('Quit')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def init():
config_path = os.path.abspath(os.path.dirname(__file__)) + "/config"
file_name = config_path + "/brightness.txt"
brightness = "10"
if os.path.exists(file_name):
with open(file_name, 'rb') as f:
try:
brightness = f.read()
except Exception as e: # whatever reader errors you care about
print("ERROR "+e)
# setting temperature
print("BRIGHTNESS _ A-BETTER-REDSHIFT "+str(int(brightness)))
brightness=str(int(brightness))
if brightness == "10":
brightness = "1"
else:
brightness = "0." + str(int(brightness))
file_name = config_path + "/temperature.txt"
int_temperature = 7000
if os.path.exists(file_name):
with open(file_name, 'rb') as f:
try:
temperature = f.readline()
int_temperature = int(temperature)
except(e): # whatever reader errors you care about
print("ERROR "+e)
# setting temperature
os.system("killall -q redshift")
command = "redshift -l 40:40 -t " + str(int_temperature) + ":" + str(int_temperature) + " -b " + brightness + ":" + brightness + " &"
os.system(command)
print(command)
def refresh(_, info):
config_path = os.path.abspath(os.path.dirname(__file__)) + "/config"
file_name = config_path + "/brightness.txt"
brightness = "10"
if os.path.exists(file_name):
with open(file_name, 'rb') as f:
try:
brightness = f.read()
except Exception as e: # whatever reader errors you care about
print("ERROR "+e)
# setting temperature
print("BRIGHTNESS _ A-BETTER-REDSHIFT "+str(int(brightness)))
brightness=str(int(brightness))
if brightness == "10":
brightness = "1"
else:
brightness = "0." + str(int(brightness))
file_name = config_path + "/temperature.txt"
int_temperature = 7000
if os.path.exists(file_name):
with open(file_name, 'rb') as f:
try:
temperature = f.readline()
int_temperature = int(temperature)
except(e): # whatever reader errors you care about
print("ERROR "+e)
# setting temperature
info.set_label("b: "+brightness+"; t: "+str(int_temperature))
def set_temperature(_):
win1 = TemperatureWindow()
win1.set_position(gtk.WindowPosition.CENTER)
win1.show_all()
win1.set_resizable(False)
def set_brightness(_):
win1 = BrightnessWindow()
win1.set_position(gtk.WindowPosition.CENTER)
win1.show_all()
win1.set_resizable(False)
def quit(_):
os.system("killall -q redshift")
abs_path = os.path.abspath(os.path.dirname(__file__))
os.system("rm -r "+abs_path+"/__pycache__")
gtk.main_quit()
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL)
main()