forked from TheArcaneBrony/OpenFreezeCenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicator.py
340 lines (262 loc) · 12.5 KB
/
indicator.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#! /usr/bin/python3
import signal
import os
import subprocess
import webbrowser
import fileinput
#################################################################################################### Indicator Making
APPINDICATOR_ID = 'openfreezecenter'
iconpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "openfreezecenter.png")
path_to_script = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(path_to_script, "conf.txt")
is_installed = os.path.exists(config_path)
if not is_installed:
print("Oops! Looks like we haven't ran before! Make sure dependencies are installed if you see any errors!")
open(config_path, "w").close()
subprocess.call(['chmod', '0777', config_path])
conf_file = open(config_path, "w")
conf_file.writelines("1\n0\n")
temp_ = [140,0,20,40,45,50,60,70,0,20,40,45,50,60,70]
for val in temp_:
conf_file.write("%i," % val)
conf_file.write("\n100\n")
temp_ = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for val in temp_:
conf_file.write("%i," % val)
conf_file.write("\n")
temp_ = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
conf_file.write("12,")
for val in temp_:
conf_file.write("%i," % val)
conf_file.write("\n0")
conf_file.close()
os.system("python3 read_temp_set.py")
import gi.repository
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
def reading():
conf_file = open(config_path, "r")
all_lines = conf_file.readlines()
conf_file.close()
return all_lines
def corrections(lines):
conf_file = open(config_path, "w")
conf_file.writelines(lines)
conf_file.close()
str_1 = ''
for line in fileinput.FileInput(config_path, inplace=1):
if line.rstrip():
str_1 = str_1 + line
conf_file = open(config_path, "w")
conf_file.writelines(str_1)
conf_file.close()
os.system("python3 write_EC.py")
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def main():
indicator = appindicator.Indicator.new(APPINDICATOR_ID, iconpath, appindicator.IndicatorCategory.SYSTEM_SERVICES)
indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
indicator.set_menu(build_menu())
gtk.main()
def build_menu():
menu = gtk.Menu()
basic_submenu = gtk.Menu()
cpu_submenu = gtk.Menu()
battery_charge_threshold_submenu = gtk.Menu()
flip_board_submenu = gtk.Menu()
backlight_submenu = gtk.Menu()
item_github = gtk.MenuItem.new_with_label('Visit Project')
item_github.connect('activate', github)
menu.append(item_github)
Separator = gtk.SeparatorMenuItem() ################################## Fan Mode
menu.append(Separator)
item_auto = gtk.MenuItem.new_with_label('Auto') ################# Auto
item_auto.connect('activate', auto)
menu.append(item_auto)
item_basic = gtk.MenuItem.new_with_label('Basic') ################# Basic
item_basic.set_submenu(basic_submenu)
basic_slowest = gtk.MenuItem.new_with_label('Slowest')
basic_slowest.connect('activate', slowest)
basic_submenu.append(basic_slowest)
basic_slower = gtk.MenuItem.new_with_label('Slower')
basic_slower.connect('activate', slower)
basic_submenu.append(basic_slower)
basic_slow = gtk.MenuItem.new_with_label('Slow')
basic_slow.connect('activate', slow)
basic_submenu.append(basic_slow)
basic_normal = gtk.MenuItem.new_with_label('Normal')
basic_normal.connect('activate', normal)
basic_submenu.append(basic_normal)
basic_fast = gtk.MenuItem.new_with_label('Fast')
basic_fast.connect('activate', fast)
basic_submenu.append(basic_fast)
basic_faster = gtk.MenuItem.new_with_label('Faster')
basic_faster.connect('activate', faster)
basic_submenu.append(basic_faster)
basic_fastest = gtk.MenuItem.new_with_label('Fastest')
basic_fastest.connect('activate', fastest)
basic_submenu.append(basic_fastest)
menu.append(item_basic)
item_advanced = gtk.MenuItem.new_with_label('Advanced') ################# Advanced
item_advanced.connect('activate', advanced)
menu.append(item_advanced)
item_cooler_booster = gtk.MenuItem.new_with_label('Cooler Booster') ################# Cooler Booster
item_cooler_booster.connect('activate', cooler_booster)
menu.append(item_cooler_booster)
Separator = gtk.SeparatorMenuItem() ################################# Monitering & Battery Charging Threshold
menu.append(Separator)
item_monitor = gtk.MenuItem.new_with_label('Monitoring') ################# Monitering
item_monitor.connect('activate', monitoring)
menu.append(item_monitor)
item_cpu = gtk.MenuItem.new_with_label('CPU Profiles') ################# CPU profiles
item_cpu.set_submenu(cpu_submenu)
cpu_powersaver = gtk.MenuItem.new_with_label('PowerSaver')
cpu_powersaver.connect('activate', powersaver)
cpu_submenu.append(cpu_powersaver)
cpu_balanced = gtk.MenuItem.new_with_label('Balanced')
cpu_balanced.connect('activate', balanced)
cpu_submenu.append(cpu_balanced)
cpu_performance = gtk.MenuItem.new_with_label('Performance')
cpu_performance.connect('activate', performance)
cpu_submenu.append(cpu_performance)
cpu_manual = gtk.MenuItem.new_with_label('Manual')
cpu_manual.connect('activate', manual)
cpu_submenu.append(cpu_manual)
menu.append(item_cpu)
item_battery_charge_threashold = gtk.MenuItem.new_with_label('Battery Charge Threashold') ################# Battery Profiles
item_battery_charge_threashold.set_submenu(battery_charge_threshold_submenu)
mx_50 = gtk.MenuItem.new_with_label('50%')
mx_50.connect('activate', battery_charge_threashold_50)
battery_charge_threshold_submenu.append(mx_50)
mx_60 = gtk.MenuItem.new_with_label('60%')
mx_60.connect('activate', battery_charge_threashold_60)
battery_charge_threshold_submenu.append(mx_60)
mx_70 = gtk.MenuItem.new_with_label('70%')
mx_70.connect('activate', battery_charge_threashold_70)
battery_charge_threshold_submenu.append(mx_70)
mx_80 = gtk.MenuItem.new_with_label('80%')
mx_80.connect('activate', battery_charge_threashold_80)
battery_charge_threshold_submenu.append(mx_80)
mx_90 = gtk.MenuItem.new_with_label('90%')
mx_90.connect('activate', battery_charge_threashold_90)
battery_charge_threshold_submenu.append(mx_90)
mx_100 = gtk.MenuItem.new_with_label('100%')
mx_100.connect('activate', battery_charge_threashold_100)
battery_charge_threshold_submenu.append(mx_100)
menu.append(item_battery_charge_threashold)
Separator = gtk.SeparatorMenuItem() ################################# EC Dump
menu.append(Separator)
item_ec = gtk.MenuItem.new_with_label('EC Mapping')
item_ec.connect('activate', ec_map)
menu.append(item_ec)
item_flip_board = gtk.MenuItem.new_with_label('Intel 11th Gen') ################# CPU fan monitor choose "ca" and "c8"
item_flip_board.set_submenu(flip_board_submenu)
item_flip_board_1 = gtk.MenuItem.new_with_label('On')
item_flip_board_1.connect('activate', flip_board_1)
flip_board_submenu.append(item_flip_board_1)
item_flip_board_2 = gtk.MenuItem.new_with_label('Off')
item_flip_board_2.connect('activate', flip_board_2)
flip_board_submenu.append(item_flip_board_2)
menu.append(item_flip_board)
Separator = gtk.SeparatorMenuItem() ################################# Quit
menu.append(Separator)
item_quit = gtk.MenuItem.new_with_label('Quit')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def github(source):
webbrowser.open("https://github.com/YoCodingMonster/MSI-Dragon-Center-for-Linux")
def auto(source):
all_lines = reading()
lines = str(1) + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def slowest(source):
all_lines = reading()
lines = str(2) + "\n" + "-30" + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def slower(source):
all_lines = reading()
lines = str(2) + "\n" + "-20" + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def slow(source):
all_lines = reading()
lines = str(2) + "\n" + "-10" + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def normal(source):
all_lines = reading()
lines = str(2) + "\n" + "0" + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def fast(source):
all_lines = reading()
lines = str(2) + "\n" + "10" + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def faster(source):
all_lines = reading()
lines = str(2) + "\n" + "20" + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def fastest(source):
all_lines = reading()
lines = str(2) + "\n" + "30" + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def advanced(source):
command_w = "nohup python3 ${pkgdir}advanced.py >/dev/null 2>&1"
os.popen((command_w), 'w')
def cooler_booster(source):
all_lines = reading()
lines = str(4) + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def monitoring(source):
os.system("python3 monitor.py")
def powersaver(source):
f = 0
def balanced(source):
f = 0
def performance(source):
f = 0
def manual(source):
f = 0
def cpu(source):
f = 0
def battery_charge_threashold_50(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + "50" + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def battery_charge_threashold_60(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + "60" + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def battery_charge_threashold_70(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + "70" + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def battery_charge_threashold_80(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + "80" + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def battery_charge_threashold_90(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + "90" + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def battery_charge_threashold_100(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + "100" + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + all_lines[6]
corrections(lines)
def ec_map(source):
os.system("python3 ec_dump.py")
def flip_board_1(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + str(1)
corrections(lines)
def flip_board_2(source):
all_lines = reading()
lines = all_lines[0] + "\n" + all_lines[1] + "\n" + all_lines[2] + "\n" + all_lines[3] + "\n" + all_lines[4] + "\n" + all_lines[5] + "\n" + str(0)
corrections(lines)
def quit(source):
gtk.main_quit()
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL)
main()