139 lines
5.2 KiB
Python
139 lines
5.2 KiB
Python
# qr_dialog.py
|
|
from PySide6.QtWidgets import QDialog, QVBoxLayout, QLabel, QPushButton
|
|
from PySide6.QtGui import QPixmap, QFont
|
|
from PySide6.QtCore import QTimer, QCoreApplication, Qt
|
|
import re
|
|
|
|
class QRDialog(QDialog):
|
|
"""
|
|
QR 코드 로그인 다이얼로그.
|
|
90초 카운트다운을 포함하며, 시간이 지나면 창을 자동으로 닫습니다.
|
|
"""
|
|
def __init__(self, qr_image_path, inner_text, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("네이버 QR 로그인")
|
|
self.setFixedSize(350, 500) # 창 크기 조정
|
|
|
|
# 90초 카운트다운 설정
|
|
self.countdown_time = 180
|
|
|
|
layout = QVBoxLayout(self)
|
|
|
|
# QR 코드 이미지 표시
|
|
self.qr_label = QLabel()
|
|
self.qr_label.setPixmap(QPixmap(qr_image_path).scaled(176, 176, Qt.KeepAspectRatio, Qt.SmoothTransformation))
|
|
layout.addWidget(self.qr_label, alignment=Qt.AlignCenter)
|
|
|
|
# 로그인 안내 메시지
|
|
self.info_label = QLabel("📷 QR 코드를 스캔하여 로그인하세요!")
|
|
self.info_label.setAlignment(Qt.AlignCenter)
|
|
self.info_label.setFont(QFont("Arial", 12, QFont.Bold))
|
|
layout.addWidget(self.info_label)
|
|
|
|
|
|
match = re.search(r'(\d+)', inner_text)
|
|
if match:
|
|
number_str = match.group(1)
|
|
# 최대 한 번 분리하여 앞, 뒤로 나눔
|
|
parts = re.split(r'\d+', inner_text, maxsplit=1)
|
|
text_before = parts[0].strip()
|
|
text_after = parts[1].strip() if len(parts) > 1 else ""
|
|
else:
|
|
number_str = ""
|
|
text_before = inner_text
|
|
text_after = ""
|
|
|
|
# 앞부분 텍스트 라벨
|
|
self.before_label = QLabel(text_before)
|
|
self.before_label.setAlignment(Qt.AlignCenter)
|
|
self.before_label.setFont(QFont("Arial", 10))
|
|
layout.addWidget(self.before_label)
|
|
|
|
# 추출한 숫자를 크게 굵게 표시하는 라벨
|
|
self.number_label = QLabel(number_str)
|
|
self.number_label.setAlignment(Qt.AlignCenter)
|
|
self.number_label.setFont(QFont("Arial", 30, QFont.Bold))
|
|
layout.addWidget(self.number_label)
|
|
|
|
# 뒷부분 텍스트 라벨
|
|
self.after_label = QLabel(text_after)
|
|
self.after_label.setAlignment(Qt.AlignCenter)
|
|
self.after_label.setFont(QFont("Arial", 10))
|
|
layout.addWidget(self.after_label)
|
|
|
|
# 카운트다운 라벨
|
|
self.countdown_label = QLabel()
|
|
self.countdown_label.setAlignment(Qt.AlignCenter)
|
|
self.countdown_label.setFont(QFont("Arial", 20, QFont.Bold))
|
|
self.countdown_label.setStyleSheet("color: red;")
|
|
layout.addWidget(self.countdown_label)
|
|
|
|
# 닫기 버튼
|
|
self.ok_button = QPushButton("❌ 닫기")
|
|
self.ok_button.setFont(QFont("Arial", 12))
|
|
self.ok_button.setStyleSheet("background-color: #d9534f; color: white; padding: 8px;")
|
|
self.ok_button.clicked.connect(self.reject)
|
|
layout.addWidget(self.ok_button)
|
|
|
|
self.setLayout(layout)
|
|
|
|
# 타이머 설정 (1초마다 update_countdown 호출)
|
|
self.timer = QTimer(self)
|
|
self.timer.timeout.connect(self.update_countdown)
|
|
self.timer.start(1000)
|
|
self.update_countdown()
|
|
|
|
def update_countdown(self):
|
|
"""카운트다운 업데이트"""
|
|
if self.countdown_time > 0:
|
|
minutes = self.countdown_time // 60
|
|
seconds = self.countdown_time % 60
|
|
self.countdown_label.setText(f"⏳ 남은 시간: {minutes}:{seconds:02d}")
|
|
self.countdown_time -= 1
|
|
QCoreApplication.processEvents()
|
|
else:
|
|
self.timer.stop()
|
|
self.reject()
|
|
|
|
|
|
|
|
class LoginSuccessDialog(QDialog):
|
|
"""로그인 성공 시 표시되는 다이얼로그 (1초 후 자동 닫힘)"""
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("로그인 성공")
|
|
self.setFixedSize(300, 150)
|
|
layout = QVBoxLayout(self)
|
|
label = QLabel("네이버 로그인에 성공했습니다.")
|
|
label.setAlignment(Qt.AlignCenter)
|
|
label.setFont(QFont("Arial", 12, QFont.Bold))
|
|
layout.addWidget(label)
|
|
self.setLayout(layout)
|
|
|
|
# 타이머 설정 (1초 후 자동 닫힘)
|
|
self.timer = QTimer(self)
|
|
self.timer.setSingleShot(True)
|
|
self.timer.timeout.connect(self.accept)
|
|
self.timer.start(1000)
|
|
|
|
class LoginInProgressDialog(QDialog):
|
|
"""
|
|
qrcode-success 요소가 나타난 후,
|
|
"잠시만 기다려주세요. 로그인 중입니다." 메시지를 10초 동안 표시하는 다이얼로그.
|
|
"""
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("로그인 중")
|
|
self.setFixedSize(300, 150)
|
|
layout = QVBoxLayout(self)
|
|
label = QLabel("휴대폰의 로그인버튼을 누른 후\n 잠시만 기다려주세요. \n 로그인 중입니다.")
|
|
label.setAlignment(Qt.AlignCenter)
|
|
label.setFont(QFont("Arial", 12, QFont.Bold))
|
|
layout.addWidget(label)
|
|
self.setLayout(layout)
|
|
|
|
self.timer = QTimer(self)
|
|
self.timer.setSingleShot(True)
|
|
self.timer.timeout.connect(self.accept)
|
|
self.timer.start(12000) # 12초 후 자동 닫힘
|