57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
|
|
import logging
|
||
|
|
|
||
|
|
try:
|
||
|
|
from PySide6.QtWidgets import QDialog, QVBoxLayout, QTabWidget, QDialogButtonBox
|
||
|
|
from PySide6.QtCore import Qt
|
||
|
|
except ImportError:
|
||
|
|
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QTabWidget, QDialogButtonBox
|
||
|
|
from PyQt5.QtCore import Qt
|
||
|
|
|
||
|
|
|
||
|
|
class SettingsDialog(QDialog):
|
||
|
|
"""设置对话框,用于显示和管理各种设置页面"""
|
||
|
|
|
||
|
|
def __init__(self, parent=None):
|
||
|
|
super().__init__(parent)
|
||
|
|
|
||
|
|
# 设置对话框标题和大小
|
||
|
|
self.setWindowTitle("系统设置")
|
||
|
|
self.resize(800, 600)
|
||
|
|
|
||
|
|
# 创建布局
|
||
|
|
self.layout = QVBoxLayout(self)
|
||
|
|
|
||
|
|
# 创建选项卡控件
|
||
|
|
self.tab_widget = QTabWidget()
|
||
|
|
self.layout.addWidget(self.tab_widget)
|
||
|
|
|
||
|
|
# 创建按钮盒
|
||
|
|
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||
|
|
self.button_box.accepted.connect(self.accept)
|
||
|
|
self.button_box.rejected.connect(self.reject)
|
||
|
|
self.layout.addWidget(self.button_box)
|
||
|
|
|
||
|
|
# 设置窗口模态
|
||
|
|
self.setModal(True)
|
||
|
|
|
||
|
|
logging.info("设置对话框已创建")
|
||
|
|
|
||
|
|
def add_settings_page(self, widget, title):
|
||
|
|
"""添加设置页面
|
||
|
|
|
||
|
|
Args:
|
||
|
|
widget: 设置页面部件
|
||
|
|
title: 页面标题
|
||
|
|
"""
|
||
|
|
self.tab_widget.addTab(widget, title)
|
||
|
|
logging.info(f"已添加设置页面: {title}")
|
||
|
|
|
||
|
|
def accept(self):
|
||
|
|
"""确认按钮处理"""
|
||
|
|
logging.info("设置已保存")
|
||
|
|
super().accept()
|
||
|
|
|
||
|
|
def reject(self):
|
||
|
|
"""取消按钮处理"""
|
||
|
|
logging.info("设置已取消")
|
||
|
|
super().reject()
|