-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgramMain v0.1.py
136 lines (113 loc) · 5.71 KB
/
ProgramMain v0.1.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
import clr
import serial
import time
import tkinter as tk
import webbrowser
from threading import Thread
import sounddevice as sd
import numpy as np
clr.AddReference('OpenHardwareMonitorLib')
from OpenHardwareMonitor.Hardware import Computer, HardwareType, SensorType
class MainGUI:
def __init__(self, master):
self.master = master
master.title("Analog Task Manager v0.1")
master.geometry("325x450")
# COM port entry
self.label_com = tk.Label(master, text="COM Port (e.g. COM4):")
self.label_com.pack()
self.entry_com = tk.Entry(master)
self.entry_com.pack()
# Baud rate entry
self.label_baud = tk.Label(master, text="Baud Rate (e.g. 9600):")
self.label_baud.pack()
self.entry_baud = tk.Entry(master)
self.entry_baud.pack()
# Update interval entry
self.label_interval = tk.Label(master, text="Update Interval (seconds):")
self.label_interval.pack()
self.entry_interval = tk.Entry(master)
self.entry_interval.pack()
# Button Frame
self.button_frame = tk.Frame(master)
self.button_frame.pack(fill=tk.X, expand=True)
# Read button
self.read_button = tk.Button(self.button_frame, text="Read", command=self.start_reading)
self.read_button.pack(side=tk.LEFT, fill=tk.X, expand=True)
# Stop button
self.stop_button = tk.Button(self.button_frame, text="Stop", command=self.stop_reading)
self.stop_button.pack(side=tk.LEFT, fill=tk.X, expand=True)
# Text widget for displaying readings
self.readings_display = tk.Text(master, height=9, width=50) # Increased height
self.readings_display.pack()
# Help link
self.help_text = tk.Text(master, height=3, width=50, bg=master.cget("bg"), relief=tk.FLAT, cursor="arrow")
self.help_text.insert(tk.END, "Need Help? Want to check out the code? All available ")
self.help_text.insert(tk.END, "here", "link")
self.help_text.insert(tk.END, ".")
self.help_text.tag_config("link", foreground="blue", underline=1)
self.help_text.tag_bind("link", "<Button-1>", lambda e: open_link("https://github.com/420Ayan420/analog-task-manager"))
self.help_text.config(state=tk.DISABLED)
self.help_text.pack()
# Credits link
self.credits_text = tk.Text(master, height=4, width=50, bg=master.cget("bg"), relief=tk.FLAT, cursor="arrow")
self.credits_text.insert(tk.END, "Produced by Ayan @ ")
self.credits_text.insert(tk.END, "ayanali.net", "link")
self.credits_text.insert(tk.END, ", contributing to the open-source code and getting the word out helps Ayan work on projects like these for longer.")
self.credits_text.tag_config("link", foreground="blue", underline=1)
self.credits_text.tag_bind("link", "<Button-1>", lambda e: open_link("http://ayanali.net"))
self.credits_text.config(state=tk.DISABLED)
self.credits_text.pack()
self.reading = False
def start_reading(self):
if not self.reading:
self.reading = True
com_port = self.entry_com.get()
baud_rate = int(self.entry_baud.get())
interval = float(self.entry_interval.get())
self.thread = Thread(target=self.read_data, args=(com_port, baud_rate, interval))
self.thread.start()
def read_data(self, com_port, baud_rate, interval):
ser = serial.Serial(com_port, baud_rate, timeout=1)
c = Computer()
c.CPUEnabled = True
c.GPUEnabled = True
c.Open()
num_cores = psutil.cpu_count(logical=False)
def callback(indata, frames, time, status):
if status:
print(status, flush=True)
volume_percent = np.linalg.norm(indata) * 10 # Adjust multiplier as needed
volume_percent = min(100, volume_percent)
self.update_display(f"Volume: {volume_percent:.2f}%")
with sd.InputStream(callback=callback):
while self.reading:
# Get CPU temperature and load
for hardware_item in c.Hardware:
if hardware_item.HardwareType == HardwareType.CPU:
hardware_item.Update()
temperatures = []
loads = []
for sensor in hardware_item.Sensors:
if sensor.SensorType == SensorType.Temperature:
temperatures.append(sensor.Value)
elif sensor.SensorType == SensorType.Load:
loads.append(sensor.Value)
for i in range(num_cores):
temp_str = f"{temperatures[i]:.1f}°C" if temperatures[i] is not None else "N/A"
load_str = f"{loads[i+1]:.1f}%" if loads[i+1] is not None else "N/A"
self.update_display(f"Core {i+1}: Temp = {temp_str}, Load = {load_str}")
cpu_total_load = f"{loads[0]:.1f}%" if loads[0] is not None else "N/A"
cpu_package_temp = f"{temperatures[-1]:.1f}°C" if temperatures[-1] is not None else "N/A"
self.update_display(f"CPU Total Load: {cpu_total_load}")
self.update_display(f"CPU Package Temp: {cpu_package_temp}")
break
time.sleep(interval)
def update_display(self, message):
self.readings_display.delete(1.0, tk.END) # Clear previous messages
self.readings_display.insert(tk.END, message + "\n")
self.readings_display.see(tk.END)
# Create the main window
root = tk.Tk()
app = MainGUI(root)
root.mainloop()