51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
import logging
|
||
from PySide6.QtCore import Signal
|
||
from PySide6.QtWidgets import QDialog, QVBoxLayout, QDialogButtonBox
|
||
from widgets.serial_settings_widget import SerialSettingsWidget
|
||
from widgets.settings_widget import SettingsWidget
|
||
|
||
class SettingsWindow(QDialog):
|
||
"""设置窗口,直接使用SettingsWidget中的标签页"""
|
||
|
||
# 定义信号
|
||
settings_changed = Signal()
|
||
|
||
def __init__(self, parent=None):
|
||
super().__init__(parent)
|
||
logging.info("正在初始化SettingsWindow")
|
||
|
||
# 设置窗口标题和大小
|
||
self.setWindowTitle("系统设置")
|
||
self.resize(900, 700)
|
||
self.setModal(True)
|
||
|
||
# 创建主布局
|
||
main_layout = QVBoxLayout(self)
|
||
main_layout.setContentsMargins(10, 10, 10, 10)
|
||
|
||
# 创建设置部件
|
||
self.settings_widget = SettingsWidget(self)
|
||
main_layout.addWidget(self.settings_widget)
|
||
|
||
# 添加串口设置到标签页
|
||
self.serial_settings = SerialSettingsWidget(self)
|
||
self.settings_widget.tab_widget.addTab(self.serial_settings, "串口设置")
|
||
|
||
# 添加按钮
|
||
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||
self.button_box.accepted.connect(self.accept)
|
||
self.button_box.rejected.connect(self.reject)
|
||
main_layout.addWidget(self.button_box)
|
||
|
||
# 连接信号
|
||
self.serial_settings.settings_changed.connect(self.settings_changed.emit)
|
||
|
||
logging.info("SettingsWindow初始化完成")
|
||
|
||
def accept(self):
|
||
"""确认按钮处理,保存所有设置并发送设置变更信号"""
|
||
# 通知设置已变更
|
||
self.settings_changed.emit()
|
||
|
||
# 调用父类方法关闭对话框
|
||
super().accept() |