# main.py from PyQt6.QtWidgets import QApplication, QWidget, QGridLayout, QVBoxLayout from PyQt6.QtCore import QTimer from PyQt6.QtGui import QGuiApplication import sys from loading_overlay import LoadingOverlay from monitor_data import get_monitor_data from monitor_card import MonitorCard # 카드 UI는 따로 분리해도 좋음 class Dashboard(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Server Monitor Dashboard") self.setFixedSize(960, 640) self.setStyleSheet("background-color: black;") self.cards = {} theme = "normal" # "light", "normal", "dark" colors = { "cpu": {"light": "#ffcccc", "normal": "#cc6666", "dark": "#662222"}, "ram": {"light": "#cceeff", "normal": "#66aacc", "dark": "#224455"}, "disk": {"light": "#e6e6e6", "normal": "#999999", "dark": "#2e2e2e"}, "uptime": {"light": "#e0ccff", "normal": "#a080e0", "dark": "#3a2a5a"}, "cpu_temp": {"light": "#ffd9cc", "normal": "#ff9966", "dark": "#66331f"}, "gpu_temp": {"light": "#ffe6cc", "normal": "#ffb366", "dark": "#66441f"}, "gpu_usage": {"light": "#cce6ff", "normal": "#66aadd", "dark": "#1f3a4f"}, "swap": {"light": "#ccffe6", "normal": "#66ccaa", "dark": "#1f4f3a"}, "download": {"light": "#ccd9ff", "normal": "#6688cc", "dark": "#1f2a4f"}, "upload": {"light": "#e0ccff", "normal": "#a080e0", "dark": "#3a2a5a"}, "alive": {"light": "#ccffcc", "normal": "#66cc66", "dark": "#1f4f1f"}, "processes": {"light": "#f0ccff", "normal": "#cc66cc", "dark": "#4f1f4f"}, } self.titles = [ {"id": key, "title": title, "bg_color": colors[key][theme]} for key, title in [ ("cpu", "CPU🔲"), ("ram", "RAM🎟"), ("disk", "DISK🖥"), ("uptime", "UP🕒"), ("cpu_temp", "CPU🌡️"), ("gpu_temp", "GPU🌡️"), ("gpu_usage", "GPU📊"), ("swap", "SWAP♻️"), ("download", "DN📥"), ("upload", "UP📤"), ("alive", "Alive🔥"), ("processes", "PS📈"), ] ] """ self.titles = [ {"id": "cpu", "title": "CPU🔲", "bg_color": "#2e2324"}, {"id": "ram", "title": "RAM🎟", "bg_color": "#2e3e43"}, {"id": "disk", "title": "DISK🖥", "bg_color": "#2e2e2e"}, {"id": "uptime", "title": "UP🕒", "bg_color": "#2e2a36"}, {"id": "cpu_temp", "title": "CPU🌡️", "bg_color": "#3a1f1f"}, {"id": "gpu_temp", "title": "GPU🌡️", "bg_color": "#3a2f1f"}, {"id": "gpu_usage", "title": "GPU📊", "bg_color": "#1f2f3a"}, {"id": "swap", "title": "SWAP♻️", "bg_color": "#1f3a2f"}, {"id": "download", "title": "DN📥", "bg_color": "#1f1f3a"}, {"id": "upload", "title": "UP📤", "bg_color": "#1f1f2a"}, {"id": "alive", "title": "Alive🔥", "bg_color": "#1f3a1f"}, {"id": "processes", "title": "PS📈", "bg_color": "#2a1f3a"}, ] """ # 메인 레이아웃 self.layout = QVBoxLayout(self) self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.layout) # 카드 그리드 self.grid = QGridLayout() self.grid.setSpacing(5) self.grid.setContentsMargins(0, 0, 0, 0) # (left, top, right, bottom) self.layout.addLayout(self.grid) # 카드 생성 for i, item in enumerate(self.titles): row = i // 4 col = i % 4 card = MonitorCard(item['title'], bg_color=item['bg_color']) self.grid.addWidget(card, row, col) self.cards[item['id']] = card # ✅ 올바른 키 등록 # 오버레이 생성 self.overlay = LoadingOverlay(self) self.overlay.start() # 데이터 수신 후 QTimer.singleShot(2000, self.finish_loading) # 주기적 업데이트 self.timer = QTimer() self.timer.timeout.connect(self.update_data) self.timer.start(3000) def finish_loading(self): self.overlay.stop() self.update_data() def update_data(self): data = get_monitor_data() for item in self.titles: value = data.get(item['id'], "--") self.cards[item['id']].update_value(value) if __name__ == "__main__": app = QApplication(sys.argv) dashboard = Dashboard() # 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())