import sys from PyQt6.QtWidgets import ( QApplication, QMainWindow, QStackedWidget, QWidget, QVBoxLayout, QLabel, QSizePolicy ) from PyQt6.QtGui import QGuiApplication from PyQt6.QtCore import QTimer, QDateTime, Qt, QUrl from PyQt6.QtGui import QFont, QColor, QPalette from PyQt6.QtWebEngineWidgets import QWebEngineView # --- 1. 동영상 재생 화면 (QWebEngineView 사용) --- class VideoPlayerScreen(QWidget): def __init__(self, video_url): super().__init__() self.layout = QVBoxLayout(self) self.web_view = QWebEngineView() # 외부 URL을 로드합니다. (전체화면 지원) self.web_view.setUrl(QUrl(video_url)) self.layout.addWidget(self.web_view) self.layout.setContentsMargins(0, 0, 0, 0) # 배경색 설정 (선택 사항) self.setAutoFillBackground(True) palette = self.palette() palette.setColor(QPalette.ColorRole.Window, QColor(0, 0, 0)) # 검은색 배경 self.setPalette(palette) # 웹뷰가 전체를 차지하도록 설정 self.web_view.setSizePolicy( QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding ) # --- 2. 시계 + 사진 화면 (QLabel과 QTimer 사용) --- class ClockPhotoScreen(QWidget): def __init__(self, image_url): super().__init__() self.layout = QVBoxLayout(self) self.layout.setAlignment(Qt.AlignmentFlag.AlignCenter) self.layout.setSpacing(50) # 1. 시계 레이블 설정 self.time_label = QLabel() self.time_label.setFont(QFont("Arial", 120, QFont.Weight.Bold)) self.time_label.setStyleSheet("color: white;") self.time_label.setAlignment(Qt.AlignmentFlag.AlignCenter) self.layout.addWidget(self.time_label) # 2. 사진/배경 설정 # 이미지 대신 간단한 배경색과 중앙 텍스트를 사용합니다. # 실제 이미지 로딩은 QPixmap이나 QNetworkAccessManager를 사용해야 하며, # 복잡도를 낮추기 위해 여기서는 배경색을 사용합니다. self.setStyleSheet("background-color: #34495e;") # 진한 파란색 계열 배경 # 이미지 URL을 참고용으로만 표시 self.photo_info = QLabel("사진/배경 모드 (실제 이미지 URL: " + image_url + ")") self.photo_info.setFont(QFont("Arial", 20)) self.photo_info.setStyleSheet("color: #ecf0f1;") # 밝은 회색 텍스트 self.photo_info.setAlignment(Qt.AlignmentFlag.AlignCenter) self.layout.addWidget(self.photo_info) # 타이머 설정 (1초마다 시간 업데이트) self.timer = QTimer(self) self.timer.timeout.connect(self.update_time) self.timer.start(1000) self.update_time() def update_time(self): # 현재 시간을 'HH:MM:SS' 형식으로 표시 current_time = QDateTime.currentDateTime().toString("HH:mm:ss\nyyyy.MM.dd (ddd)") self.time_label.setText(current_time) # --- 3. 구글 캘린더 웹뷰 화면 (QWebEngineView 사용) --- class CalendarWebViewScreen(QWidget): def __init__(self, calendar_url): super().__init__() self.layout = QVBoxLayout(self) self.web_view = QWebEngineView() # 사용자의 공개 캘린더 임베드 URL로 변경해야 합니다. self.web_view.setUrl(QUrl(calendar_url)) self.layout.addWidget(self.web_view) self.layout.setContentsMargins(0, 0, 0, 0) # --- 메인 대시보드 창 (전체 화면 및 모드 전환 관리) --- class FullScreenDashboard(QMainWindow): def __init__(self): super().__init__() self.setFixedSize(960, 640) self.setWindowTitle("다이나믹 대시보드 샘플") # 샘플 리소스 URL 설정 VIDEO_URL = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" IMAGE_URL = "http://googleusercontent.com/image_collection/image_retrieval/7567987077819350991" # 실제 사용 시 {YOUR_CALENDAR_ID}를 사용자 캘린더 ID로 교체해야 합니다. CALENDAR_URL = "https://calendar.google.com/calendar/embed?mode=AGENDA&src=ko.south_korea%23holiday%40group.v.calendar.google.com&ctz=Asia/Seoul" # QStackedWidget 생성 (화면 전환을 위한 핵심 위젯) self.stacked_widget = QStackedWidget() self.setCentralWidget(self.stacked_widget) # 각 화면 인스턴스 생성 및 스택에 추가 self.video_screen = VideoPlayerScreen(VIDEO_URL) self.clock_photo_screen = ClockPhotoScreen(IMAGE_URL) self.calendar_screen = CalendarWebViewScreen(CALENDAR_URL) self.stacked_widget.addWidget(self.video_screen) # 인덱스 0 (모드 1) self.stacked_widget.addWidget(self.clock_photo_screen) # 인덱스 1 (모드 2) self.stacked_widget.addWidget(self.calendar_screen) # 인덱스 2 (모드 3) # 초기 화면 설정 (모드 1) self.stacked_widget.setCurrentIndex(0) # 전체 화면으로 표시 self.showFullScreen() # 키 입력 이벤트를 오버라이드하여 모드 전환 처리 def keyPressEvent(self, event): key = event.key() if key == Qt.Key.Key_Escape: # Esc 키를 누르면 애플리케이션 종료 self.close() elif key == Qt.Key.Key_1: # 1 키: 동영상 재생 화면 self.stacked_widget.setCurrentIndex(0) print("모드 전환: 1. 동영상 재생 샘플") elif key == Qt.Key.Key_2: # 2 키: 시계 + 사진 화면 self.stacked_widget.setCurrentIndex(1) print("모드 전환: 2. 시계 + 사진 샘플") elif key == Qt.Key.Key_3: # 3 키: 구글 캘린더 웹뷰 self.stacked_widget.setCurrentIndex(2) print("모드 전환: 3. 구글 캘린더 웹뷰") super().keyPressEvent(event) if __name__ == "__main__": app = QApplication(sys.argv) # window = FullScreenDashboard() # 윈도우 생성 dashboard = FullScreenDashboard() # 1. 사용 가능한 모니터 목록 가져오기 screens = QGuiApplication.screens() # 2. 더미 모니터 선택 (예: 두 번째 모니터, 인덱스 1) # target_screen_index = 1 if len(screens) > 1 else 0 # target_screen = screens[target_screen_index] target_screen_index = 0 if len(screens) > target_screen_index: target_screen = screens[target_screen_index] else: print(f"Warning: Monitor index {target_screen_index} not found.") # 3. 윈도우를 선택한 모니터의 좌측 상단으로 이동 geometry = target_screen.geometry() dashboard.move(geometry.x(), geometry.y()) # 4. 고정된 960x640 크기로 표시 dashboard.show() sys.exit(app.exec())