터치 패널 축 단위와 PC 깨우기 잠금 개선

This commit is contained in:
seo committed 2026-07-30 13:09:14 +09:00
1 parent 9388122892
commit e0b384838d
2 files changed
+72 -31

No files matched your search

+70 -29
View File
@@ -132,6 +132,11 @@ def disk_io():
def write_sys(path, value):
if not path:
return False
try:
Path(path).write_text(str(value) + "\n", encoding="utf-8")
return True
except OSError:
return False
def send_magic_packet(mac):
@@ -147,11 +152,6 @@ def send_magic_packet(mac):
return True
except OSError:
return False
try:
Path(path).write_text(str(value) + "\n", encoding="utf-8")
return True
except OSError:
return False
class StatusDot(QWidget):
@@ -236,29 +236,32 @@ class StatusTile(QFrame):
self.error_dot.tick()
class PcWakeButton(QFrame):
class PcWakeButton(StatusTile):
def __init__(self):
super().__init__()
self.setObjectName("pcWake")
super().__init__("PC")
self.online = False
self.dot = StatusDot("#16a34a")
self.label = QLabel("PC")
self.label.setObjectName("pcLabel")
layout = QHBoxLayout(self)
layout.setContentsMargins(5, 4, 5, 4)
layout.setSpacing(5)
layout.addWidget(self.dot)
layout.addWidget(self.label)
layout.addStretch(1)
self.setFixedHeight(28)
self.last_wake_at = 0.0
def set_online(self, online):
self.online = online
self.dot.set_steady(online)
self.read_dot.set_steady(online)
self.error_dot.set_steady(False)
if online:
self.detail.setText("켜짐")
elif time.monotonic() - self.last_wake_at < 30:
remaining = int(30 - (time.monotonic() - self.last_wake_at))
self.detail.setText(f"대기 {remaining}s")
else:
self.detail.setText("꺼짐")
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton and not self.online:
send_magic_packet(PC_MAC)
if event.button() == Qt.LeftButton:
self.write_dot.blink()
if not self.online and time.monotonic() - self.last_wake_at >= 30:
self.last_wake_at = time.monotonic()
self.detail.setText("깨우는 중")
if not send_magic_packet(PC_MAC):
self.error_dot.set_steady(True)
super().mousePressEvent(event)
@@ -281,11 +284,12 @@ class MetricCard(QFrame):
class Sparkline(QFrame):
def __init__(self, title, color="#38bdf8", second_color=None):
def __init__(self, title, color="#38bdf8", second_color=None, y_unit=""):
super().__init__()
self.setObjectName("chartCard")
self.color = QColor(color)
self.second_color = QColor(second_color) if second_color else None
self.y_unit = y_unit
self.values = []
self.second_values = []
self.title = QLabel(title)
@@ -316,7 +320,7 @@ class Sparkline(QFrame):
del event
painter = QPainter(self.canvas)
painter.setRenderHint(QPainter.Antialiasing)
rect = self.canvas.rect().adjusted(2, 4, -2, -4)
rect = self.canvas.rect().adjusted(34, 4, -2, -13)
painter.fillRect(rect, QColor("#0f172a"))
painter.setPen(QPen(QColor("#263650"), 1))
painter.drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom())
@@ -327,10 +331,22 @@ class Sparkline(QFrame):
high = max(all_values)
if high <= low:
high = low + 1
painter.setPen(QColor("#93a4bd"))
painter.drawText(1, rect.top() + 10, self.axis_text(high))
painter.drawText(1, rect.bottom(), self.axis_text(low))
self.draw_series(painter, rect, self.values, low, high, self.color)
if self.second_color and self.second_values:
self.draw_series(painter, rect, self.second_values, low, high, self.second_color)
def axis_text(self, value):
if abs(value) >= 100:
text = f"{value:.0f}"
elif abs(value) >= 10:
text = f"{value:.1f}"
else:
text = f"{value:.2f}"
return f"{text}{self.y_unit}"
@staticmethod
def draw_series(painter, rect, values, low, high, color):
path = QPainterPath()
@@ -358,6 +374,7 @@ class TouchPanel(QMainWindow):
self.last_sample = None
self.last_graph = None
self.current_rates = {"wan": {"rx": 0.0, "tx": 0.0}}
self.disk_temp = None
self.current_pwm = read_int(self.fan["pwm"])
self.temp_history = deque(maxlen=80)
self.rpm_history = deque(maxlen=80)
@@ -382,11 +399,18 @@ class TouchPanel(QMainWindow):
self.pc_timer.timeout.connect(self.ping_pc)
self.pc_timer.start(1000)
self.disk_temp_proc = QProcess(self)
self.disk_temp_proc.finished.connect(self.disk_temp_finished)
self.disk_temp_timer = QTimer(self)
self.disk_temp_timer.timeout.connect(self.update_disk_temp)
self.disk_temp_timer.start(5000)
self.pulse_timer = QTimer(self)
self.pulse_timer.timeout.connect(self.tick_pulses)
self.pulse_timer.start(70)
self.sample()
self.ping_pc()
self.update_disk_temp()
def _build_ui(self):
root = QWidget()
@@ -410,7 +434,7 @@ class TouchPanel(QMainWindow):
left_layout.addWidget(tile)
left_layout.addStretch(1)
self.pc_button = PcWakeButton()
left_layout.addWidget(self.pc_button, 0, Qt.AlignLeft | Qt.AlignBottom)
left_layout.addWidget(self.pc_button)
right = QWidget()
right_layout = QVBoxLayout(right)
@@ -469,8 +493,8 @@ class TouchPanel(QMainWindow):
chart_grid.setHorizontalSpacing(8)
chart_grid.setVerticalSpacing(8)
for index, (key, chart) in enumerate([
("temp", Sparkline("온도 / RPM", "#f97316", "#38bdf8")),
("wan", Sparkline("WAN 트래픽", "#38bdf8", "#22c55e")),
("temp", Sparkline("온도 / RPM", "#f97316", "#38bdf8", "C")),
("wan", Sparkline("WAN 트래픽", "#38bdf8", "#22c55e", "M")),
]):
self.charts[key] = chart
chart_grid.addWidget(chart, index, 0)
@@ -519,7 +543,8 @@ class TouchPanel(QMainWindow):
self.render(temp, rpm, pwm, percent, enable, groups, rates, activity, io_read_activity, io_write_activity, disk_error)
def render(self, temp, rpm, pwm, percent, enable, groups, rates, activity, io_read_activity, io_write_activity, disk_error):
self.rows["io"].set_state(f"{temp:.1f} C", disk_error, io_read_activity, io_write_activity)
disk_temp_text = f"{self.disk_temp:.1f} C" if self.disk_temp is not None else "- C"
self.rows["io"].set_state(disk_temp_text, disk_error, io_read_activity, io_write_activity)
self.rows["wan"].set_state(self.iface_detail(groups["wan"]), self.iface_warn(groups["wan"]), activity["wan"]["read"], activity["wan"]["write"])
self.rows["lan"].set_state(self.iface_detail(groups["lan"]), self.iface_warn(groups["lan"]), activity["lan"]["read"], activity["lan"]["write"])
self.rows["wifi24"].set_state(self.iface_detail(groups["wifi24"]), self.iface_warn(groups["wifi24"]), activity["wifi24"]["read"], activity["wifi24"]["write"])
@@ -550,6 +575,22 @@ class TouchPanel(QMainWindow):
del exit_status
self.pc_button.set_online(exit_code == 0)
def update_disk_temp(self):
if self.disk_temp_proc.state() != QProcess.NotRunning:
return
self.disk_temp_proc.start("/usr/sbin/smartctl", ["-A", "-d", "sntasmedia", "/dev/sda"])
def disk_temp_finished(self, exit_code, exit_status):
del exit_code, exit_status
output = bytes(self.disk_temp_proc.readAllStandardOutput()).decode("utf-8", "ignore")
for line in output.splitlines():
if line.strip().startswith("Temperature:"):
parts = line.split()
for part in parts:
if part.isdigit():
self.disk_temp = float(part)
return
def update_graphs(self):
temp = getattr(self, "latest_temp", cpu_temp())
rpm = getattr(self, "latest_rpm", read_int(self.fan["rpm"]))
@@ -592,9 +633,9 @@ class TouchPanel(QMainWindow):
@staticmethod
def iface_detail(row):
if not row["carrier"]:
return "down"
return "꺼짐"
drops = row["rx_dropped"] + row["tx_dropped"]
return f"up D{drops}"
return "정상" if drops <= 0 else f"드롭 {drops}"
@staticmethod
def iface_warn(row):