-
Notifications
You must be signed in to change notification settings - Fork 21
/
fan.py
executable file
·73 lines (57 loc) · 1.91 KB
/
fan.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
#!/usr/bin/python3
import tkinter as tk
import subprocess
from time import sleep
from threading import Thread
def get_info():
info_lines = subprocess.check_output("sensors").decode("utf-8").split("\n")
result = []
count = 0
for i in info_lines:
if "Core" in i:
result.append("Core %d: " % count + i.split(":")[-1].split("(")[0].strip())
count += 1
if "fan" in i:
result.append("Fan : " + i.split(":")[-1].strip())
return result
def set_speed(speed=None):
"""
Set speed of fan by changing level at /proc/acpi/ibm/fan
speed: 0-7, auto, disengaged, full-speed
"""
print("set level to %r" % speed)
return subprocess.check_output(
'echo level {0} | sudo tee "/proc/acpi/ibm/fan"'.format(speed),
shell=True
).decode()
class MainApplication(tk.Frame):
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
self.parent.minsize(width=100, height=100)
main_label = tk.Label(parent, text="")
main_label.grid(row=0, column=0)
row1 = tk.Frame()
row1.grid()
for i in range(8):
tk.Button(row1, text=str(i), command=lambda x=i: set_speed(x)).grid(
row=0, column=i + 1
)
row2 = tk.Frame()
row2.grid()
tk.Button(row2, text="Auto", command=lambda: set_speed("auto")).grid(
row=0, column=0
)
tk.Button(row2, text="Full", command=lambda: set_speed("full-speed")).grid(
row=0, column=1
)
def display_loop():
while True:
sleep(0.5)
main_label["text"] = "\n".join(get_info())
Thread(target=display_loop).start()
if __name__ == "__main__":
root = tk.Tk()
root.title("Thinkfan Control")
MainApplication(root).grid()
root.mainloop()