qtdash monitor select
This commit is contained in:
westnife3 2025-08-28 13:43:43 +09:00
parent 0a63ae00d7
commit c90fdc4d25
5 changed files with 54 additions and 60 deletions

2
.gitignore vendored
View File

@ -158,5 +158,5 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ .idea/

View File

@ -1,6 +1,7 @@
# main.py # main.py
from PyQt6.QtWidgets import QApplication, QWidget, QGridLayout, QVBoxLayout from PyQt6.QtWidgets import QApplication, QWidget, QGridLayout, QVBoxLayout
from PyQt6.QtCore import QTimer from PyQt6.QtCore import QTimer
from PyQt6.QtGui import QGuiApplication
import sys import sys
from loading_overlay import LoadingOverlay from loading_overlay import LoadingOverlay
from monitor_data import get_monitor_data from monitor_data import get_monitor_data
@ -14,9 +15,18 @@ class Dashboard(QWidget):
self.cards = {} self.cards = {}
self.titles = [ self.titles = [
"CPU", "RAM", "Disk", "Uptime", {"id": "cpu", "title": "CPU🔲", "bg_color": "#2e2324"},
"CPU Temp", "GPU Temp", "GPU Usage", "Swap", {"id": "ram", "title": "RAM🎟", "bg_color": "#2e3e43"},
"Download", "Upload", "Alive", "Processes" {"id": "disk", "title": "DISK🖥", "bg_color": "#2e2e2e"},
{"id": "uptime", "title": "UP🕒", "bg_color": "#2e2e2e"},
{"id": "cpu_temp", "title": "CPU🌡", "bg_color": "#2e2e2e"},
{"id": "gpu_temp", "title": "GPU🌡", "bg_color": "#2e2e2e"},
{"id": "gpu_usage", "title": "GPU📊", "bg_color": "#2e2e2e"},
{"id": "swap", "title": "SWAP♻", "bg_color": "#2e2e2e"},
{"id": "download", "title": "DN📥", "bg_color": "#2e2e2e"},
{"id": "upload", "title": "UP📤", "bg_color": "#2e2e2e"},
{"id": "alive", "title": "Alive🔥", "bg_color": "#2e2e2e"},
{"id": "processes", "title": "PS📈", "bg_color": "#2e2e2e"},
] ]
# 메인 레이아웃 # 메인 레이아웃
@ -25,16 +35,16 @@ class Dashboard(QWidget):
# 카드 그리드 # 카드 그리드
self.grid = QGridLayout() self.grid = QGridLayout()
self.grid.setSpacing(10) self.grid.setContentsMargins(0, 0, 0, 0) # (left, top, right, bottom)
self.grid.setSpacing(5)
self.layout.addLayout(self.grid) self.layout.addLayout(self.grid)
# 카드 생성 # 카드 생성
for i, title in enumerate(self.titles): for i, item in enumerate(self.titles):
row = i // 4 row = i // 4
col = i % 4 col = i % 4
card = MonitorCard(title) card = MonitorCard(item['title'], bg_color=item['bg_color'])
self.grid.addWidget(card, row, col) self.grid.addWidget(card, row, col)
self.cards[title] = card self.cards[item['id']] = card # ✅ 올바른 키 등록
# 오버레이 생성 # 오버레이 생성
self.overlay = LoadingOverlay(self) self.overlay = LoadingOverlay(self)
@ -54,12 +64,29 @@ class Dashboard(QWidget):
def update_data(self): def update_data(self):
data = get_monitor_data() data = get_monitor_data()
for key in self.titles: for item in self.titles:
self.cards[key].update_value(data.get(key, "--")) value = data.get(item['id'], "--")
self.cards[item['id']].update_value(value)
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication(sys.argv) app = QApplication(sys.argv)
dashboard = Dashboard() dashboard = Dashboard()
dashboard.show() # dashboard.show()
# 사용 가능한 모니터 목록 가져오기
screens = QGuiApplication.screens()
print("사용 가능한 모니터 수:", len(screens))
# 예: 두 번째 모니터 선택 (인덱스 1)
target_screen_index = 1 if len(screens) > 1 else 0
target_screen = screens[target_screen_index]
# 선택한 모니터의 geometry로 이동
geometry = target_screen.geometry()
dashboard.setGeometry(geometry)
# 전체화면으로 표시
dashboard.showFullScreen()
sys.exit(app.exec()) sys.exit(app.exec())

View File

@ -11,14 +11,14 @@ class MonitorCard(QWidget):
border-radius: 10px; border-radius: 10px;
border: 1px solid #444; border: 1px solid #444;
""") """)
layout = QVBoxLayout()
layout = QVBoxLayout()
self.title = QLabel(title) self.title = QLabel(title)
self.title.setStyleSheet("font-weight: bold; font-size: 16px; color: white;") self.title.setStyleSheet("font-weight: bold; font-size: 50px; color: white;")
self.title.setAlignment(Qt.AlignmentFlag.AlignCenter) self.title.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.value = QLabel("--") self.value = QLabel("--")
self.value.setStyleSheet("font-size: 24px; font-weight: bold; color: white;") self.value.setStyleSheet("font-size: 40px; font-weight: bold; color: white;")
self.value.setAlignment(Qt.AlignmentFlag.AlignCenter) self.value.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.spinner = QLabel() self.spinner = QLabel()

View File

@ -58,17 +58,16 @@ def check_alive(ip="192.168.0.101"):
def get_monitor_data(): def get_monitor_data():
download, upload = get_net_speed() download, upload = get_net_speed()
return { return {
"CPU": f"{psutil.cpu_percent()}%", "cpu": f"{psutil.cpu_percent()}%",
"RAM": f"{psutil.virtual_memory().percent}%", "ram": f"{psutil.virtual_memory().percent}%",
"Disk": f"{psutil.disk_usage('/').percent}%", "disk": f"{psutil.disk_usage('/').percent}%",
"Uptime": format_uptime(), "uptime": format_uptime(),
"CPU Temp": get_cpu_temp(), "cpu_temp": get_cpu_temp(),
"GPU Temp": get_gpu_temp(), "gpu_temp": get_gpu_temp(),
"GPU Usage": get_gpu_usage(), "gpu_usage": get_gpu_usage(),
"Swap": f"{psutil.swap_memory().percent}%", "swap": f"{psutil.swap_memory().percent}%",
"Download": download, "download": download,
"Upload": upload, "upload": upload,
"Alive": check_alive(), "alive": check_alive(),
"Processes": str(len(psutil.pids())) "processes": str(len(psutil.pids()))
} }

View File

@ -1,32 +0,0 @@
# main.py
# main.py
from PyQt6.QtWidgets import QApplication, QWidget, QGridLayout
from PyQt6.QtCore import QTimer
import sys
from monitor_data import get_monitor_data
from monitor_card import MonitorCard # 카드 UI는 따로 분리해도 좋음
from loading_overlay import LoadingOverlay
class Dashboard(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
# 카드들 배치
self.layout = QVBoxLayout(self)
self.setLayout(self.layout)
# 오버레이 생성
self.overlay = LoadingOverlay(self)
# 로딩 시작
self.overlay.start()
# 데이터 수신 후
QTimer.singleShot(2000, self.finish_loading)
def finish_loading(self):
self.overlay.stop()
# 카드들에 값 업데이트