layout source code

This commit is contained in:
westnife3 2025-08-27 18:27:30 +09:00
parent 03ddabd80d
commit f6af247743
1 changed files with 73 additions and 0 deletions

73
qtDash/layout.py Normal file
View File

@ -0,0 +1,73 @@
from PyQt6.QtWidgets import (
QApplication, QWidget, QGridLayout, QLabel, QVBoxLayout
)
from PyQt6.QtCore import Qt, QTimer
import sys
class MonitorCard(QWidget):
def __init__(self, title, bg_color="#2e2e2e"):
super().__init__()
self.setStyleSheet(f"background-color: {bg_color}; border-radius: 10px;")
layout = QVBoxLayout()
self.title = QLabel(title)
self.title.setStyleSheet("font-weight: bold; font-size: 16px; color: white;")
self.value = QLabel("--")
self.value.setStyleSheet("font-size: 24px; font-weight: bold; color: white;")
self.title.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.value.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(self.title)
layout.addWidget(self.value)
self.setLayout(layout)
def update_value(self, text):
self.value.setText(text)
class Dashboard(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Server Monitor Dashboard")
self.setFixedSize(960, 640)
self.grid = QGridLayout()
self.grid.setSpacing(10)
self.cards = {}
titles = [
"CPU", "RAM", "Disk", "Uptime",
"CPU Temp", "GPU Temp", "GPU Usage", "Swap",
"Download", "Upload", "Alive", "Processes"
]
for i, title in enumerate(titles):
row = i // 4
col = i % 4
card = MonitorCard(title)
self.grid.addWidget(card, row, col)
self.cards[title] = card
self.setLayout(self.grid)
# 타이머로 데이터 갱신 예정
self.timer = QTimer()
self.timer.timeout.connect(self.update_data)
self.timer.start(3000)
def update_data(self):
# 여기서 psutil 등으로 실제 데이터를 가져와서 업데이트
self.cards["CPU"].update_value("15%")
self.cards["RAM"].update_value("42%")
self.cards["Disk"].update_value("68%")
self.cards["Uptime"].update_value("2d 04h 12m")
self.cards["CPU Temp"].update_value("54°C")
self.cards["GPU Temp"].update_value("48°C")
self.cards["GPU Usage"].update_value("23%")
self.cards["Swap"].update_value("12%")
self.cards["Download"].update_value("1.2 MB/s")
self.cards["Upload"].update_value("0.8 MB/s")
self.cards["Alive"].update_value("True")
self.cards["Processes"].update_value("142")
if __name__ == "__main__":
app = QApplication(sys.argv)
dashboard = Dashboard()
dashboard.show()
sys.exit(app.exec())