from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QLineEdit, QPushButton, QHBoxLayout from utils.config import ConfigManager from qfluentwidgets import SwitchButton class PercentySettingsDialog(QDialog): def __init__(self, config: ConfigManager): super().__init__() self.config = config self.setWindowTitle('퍼센티 설정') self.init_ui() def init_ui(self): layout = QVBoxLayout() self.user_id_label = QLabel('사용자 아이디:') self.user_id_input = QLineEdit(self) layout.addWidget(self.user_id_label) layout.addWidget(self.user_id_input) self.password_label = QLabel('비밀번호:') self.password_input = QLineEdit(self) self.password_input.setEchoMode(QLineEdit.Password) self.switchLayout = QHBoxLayout() self.headlessSwitchButton_Label = QLabel('브라우저 보기않기') self.headlessSwitchButton = SwitchButton() self.headlessSwitchButton.move(48, 24) self.headlessSwitchButton.checkedChanged.connect(self.onCheckedChanged) self.switchLayout.addWidget(self.headlessSwitchButton_Label) self.switchLayout.addWidget(self.headlessSwitchButton) layout.addWidget(self.password_label) layout.addWidget(self.password_input) layout.addLayout(self.switchLayout) button_layout = QHBoxLayout() save_button = QPushButton('저장') save_button.clicked.connect(self.save_settings) cancel_button = QPushButton('취소') cancel_button.clicked.connect(self.reject) button_layout.addWidget(save_button) button_layout.addWidget(cancel_button) layout.addLayout(button_layout) self.setLayout(layout) # 기존 설정 불러오기 self.load_settings() def onCheckedChanged(self, isChecked: bool): text = 'On' if isChecked else 'Off' self.headlessSwitchButton.setText(text) def load_settings(self): user_id = self.config.get('Percenty_Setting', 'user_id', fallback='') encrypted_password = self.config.get('Percenty_Setting', 'password', fallback='') headless = self.config.get('Percenty_Setting', 'headless', fallback='') if headless == 'True': headless = True else: headless = False # print(f"headless : {headless}") password = self.config.decrypt(encrypted_password) if encrypted_password else '' self.user_id_input.setText(user_id) self.password_input.setText(password) self.headlessSwitchButton.setChecked(headless) def save_settings(self): user_id = self.user_id_input.text() password = self.password_input.text() headless = self.headlessSwitchButton.isChecked() # print(f"headless : {headless}") if headless == True: headless = 'True' else: headless = 'False' self.config.set('Percenty_Setting', 'user_id', user_id) self.config.set('Percenty_Setting', 'password', self.config.encrypt(password)) self.config.set('Percenty_Setting', 'headless', headless) self.accept()