阅读这段代码，我需要你帮我修改import sys
import json
from PyQt5.QtWidgets import (
    QApplication, QMainWindow, QPushButton, QVBoxLayout,
    QWidget, QDialog, QTableWidget, QLabel, QLineEdit, QHBoxLayout,
    QTableWidgetItem, QFileDialog, QMessageBox
)
from PyQt5.QtGui import QIcon, QFont, QFontDatabase, QColor
from PyQt5.QtCore import Qt, QPoint

class StudentEditor(QDialog):
    def __init__(self, parent):
        super().__init__(parent)
        self.setWindowTitle("编辑学生姓名")
        self.setGeometry(300, 300, 400, 300)

        self.layout = QVBoxLayout()
        self.student_names = []
        
        self.table_widget = QTableWidget()
        self.table_widget.setColumnCount(2)
        self.table_widget.setHorizontalHeaderLabels(["学号", "姓名"])
        
        self.layout.addWidget(self.table_widget)

        self.add_button = QPushButton("添加学生")
        self.add_button.clicked.connect(self.add_student)
        self.layout.addWidget(self.add_button)

        self.setLayout(self.layout)

    def add_student(self):
        row_position = self.table_widget.rowCount()
        self.table_widget.insertRow(row_position)
        self.table_widget.setItem(row_position, 0, QTableWidgetItem(str(row_position + 1)))  # 学号自动生成
        self.student_names.append("")  # 添加一个空字符串以保存学生姓名

class ConfigEditor(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("班级随机排座位系统")
        self.setGeometry(300, 300, 1000, 800)  # 增大窗体

        # 加载字体
        font_db = QFontDatabase()
        font_id = font_db.addApplicationFont("gui/SDK_SC_Web65.ttf")
        font_family = font_db.applicationFontFamilies(font_id)[0]
        self.setFont(QFont(font_family, 12, QFont.Bold))

        # 创建主体布局
        main_layout = QHBoxLayout()

        # 左侧的表格
        self.table_widget = QTableWidget()
        self.table_widget.setRowCount(5)  # 默认行数
        self.table_widget.setColumnCount(2)  # 默认列数
        self.table_widget.setHorizontalHeaderLabels(["学号", "姓名"])
        for row in range(self.table_widget.rowCount()):
            self.table_widget.setItem(row, 0, QTableWidgetItem(str(row + 1)))  # 设置学号
        main_layout.addWidget(self.table_widget)

        # 右侧的编辑区
        edit_layout = QVBoxLayout()

        # 编辑班级名
        class_name_label = QLabel("班级名:")
        class_name_label.setFont(QFont(font_family, 12, QFont.Bold))
        self.class_name_edit = QLineEdit()
        self.class_name_edit.setFont(QFont(font_family, 12, QFont.Bold))
        self.class_name_edit.setStyleSheet("QLineEdit { border: 2px solid black; border-radius: 3px; padding: 5px; }")
        self.class_name_edit.textChanged.connect(self.update_class_name)
        edit_layout.addWidget(class_name_label)
        edit_layout.addWidget(self.class_name_edit)

        # 创建基本操作按钮
        self.create_button("增加行", self.add_row, edit_layout, font_family)
        self.create_button("减少行", self.remove_row, edit_layout, font_family)
        self.create_button("增加列", self.add_column, edit_layout, font_family)
        self.create_button("减少列", self.remove_column, edit_layout, font_family)

        # 添加新按钮：设置为过道、设置为讲台、设置为墙、设置为门
        self.create_button("设置为过道", self.mark_as_aisle, edit_layout, font_family)
        self.create_button("设置为讲台", self.mark_as_desk, edit_layout, font_family)
        self.create_button("设置为墙", self.mark_as_wall, edit_layout, font_family)
        self.create_button("设置为门", self.mark_as_door, edit_layout, font_family)

        # 编辑班级人员
        self.create_button("编辑班级人员", self.edit_class_members, edit_layout, font_family)

        # 保存配置
        self.create_button("保存配置", self.save_config, edit_layout, font_family)

        # 打开配置
        self.create_button("打开配置", self.open_config, edit_layout, font_family)

        # 设置为排座格
        mark_seating_button = QPushButton("设置为排座格")
        mark_seating_button.setFont(QFont(font_family, 12, QFont.Bold))
        mark_seating_button.setStyleSheet("QPushButton { background-color: white; border: 2px solid black; border-radius: 10px; height: 50px; }")
        mark_seating_button.clicked.connect(self.mark_as_seating)
        edit_layout.addWidget(mark_seating_button)

        # 将按钮添加到布局
        main_layout.addLayout(edit_layout)

        # 创建底部布局
        bottom_layout = QHBoxLayout()
        bottom_layout.setAlignment(Qt.AlignBottom | Qt.AlignCenter)
        version_label = QLabel("RandomSeat Ver 1.0")
        version_label.setStyleSheet("QLabel { color: gray; }")
        bottom_layout.addWidget(version_label)

        # 创建开始排座和导出为PNG按钮
        start_seating_button = QPushButton("开始排座")
        start_seating_button.setFont(QFont(font_family, 12, QFont.Bold))
        start_seating_button.setStyleSheet("QPushButton { color: red; background-color: white; border: 2px solid black; border-radius: 10px; height: 50px; }")
        start_seating_button.clicked.connect(self.start_seating)
        edit_layout.addWidget(start_seating_button)

        export_png_button = QPushButton("导出为PNG")
        export_png_button.setFont(QFont(font_family, 12, QFont.Bold))
        export_png_button.setStyleSheet("QPushButton { color: red; background-color: white; border: 2px solid black; border-radius: 10px; height: 50px; }")
        export_png_button.clicked.connect(self.export_to_png)
        edit_layout.addWidget(export_png_button)

        # 设置内容窗口部件
        container = QWidget()
        container.setLayout(main_layout)
        self.setCentralWidget(container)

        # 设置底部布局
        bottom_container = QWidget()
        bottom_container.setLayout(bottom_layout)
        self.statusBar().addPermanentWidget(bottom_container)

        self.selected_cells = []  # 用于保存选中的单元格
        self.cell_types = {}  # 用于存储单元格类型及其颜色
        self.class_members = {}  # 用于存储班级成员

        # 更新初始化班级名
        self.update_class_name()

    def create_button(self, text, callback, layout, font_family):
        button = QPushButton(text)
        button.setFont(QFont(font_family, 12, QFont.Bold))  # 确保字体一致
        button.setStyleSheet("QPushButton { background-color: white; border: 2px solid black; border-radius: 10px; height: 50px; }")
        button.clicked.connect(callback)
        layout.addWidget(button)

    def update_class_name(self):
        # 通过合并操作显示班级名，合并2行
        if self.table_widget.rowCount() >= 2:
            self.table_widget.setSpan(0, 0, 2, self.table_widget.columnCount())

        # 更新班级名显示
        class_name = self.class_name_edit.text()
        if class_name:
            label_item = QLabel(class_name)
            label_item.setAlignment(Qt.AlignCenter)
            label_item.setStyleSheet("QLabel { border: 2px solid black; padding: 5px; }")  # 黑色实心边框
            self.table_widget.setCellWidget(0, 0, label_item)

        # 更新表格中的显示
        for (row, col), (cell_type, color) in self.cell_types.items():
            self.update_cell_visual(row, col, cell_type, color)

        # 更新班级成员
        for row, name in self.class_members.items():
            self.table_widget.setItem(row - 1, 1, QTableWidgetItem(name))

    def update_cell_visual(self, row, col, cell_type, color):
        if cell_type:  # 只在 cell_type 有值时更新显示
            label_item = QLabel(cell_type)
            label_item.setAlignment(Qt.AlignCenter)
            label_item.setStyleSheet(f"background-color: {color.name()}; border: none; padding: 5px;") 
            self.table_widget.setCellWidget(row, col, label_item)

    def add_row(self):
        current_row_count = self.table_widget.rowCount()
        self.table_widget.insertRow(current_row_count)
        self.table_widget.setItem(current_row_count, 0, QTableWidgetItem(str(current_row_count + 1)))  # 设置学号
        self.cell_types[(current_row_count, 1)] = (None, QColor(255, 255, 255))  # 初始化类型和颜色

    def remove_row(self):
        current_row_count = self.table_widget.rowCount()
        if current_row_count > 1:
            self.table_widget.removeRow(current_row_count - 1)
            del self.cell_types[(current_row_count - 1, 1)]  # 移除类型及颜色

    def add_column(self):
        current_col_count = self.table_widget.columnCount()
        self.table_widget.insertColumn(current_col_count)
        for row in range(self.table_widget.rowCount()):
            self.cell_types[(row, current_col_count)] = (None, QColor(255, 255, 255))  # 初始化类型和颜色

    def remove_column(self):
        current_col_count = self.table_widget.columnCount()
        if current_col_count > 1:
            self.table_widget.removeColumn(current_col_count - 1)
            for row in range(self.table_widget.rowCount()):
                del self.cell_types[(row, current_col_count - 1)]  # 移除类型及颜色

    def mark_as_aisle(self):
        self.mark_cells("过道", QColor(144, 238, 144))  # 浅绿色

    def mark_as_desk(self):
        self.mark_cells("讲台", QColor(210, 180, 140))  # 浅棕色

    def mark_as_wall(self):
        self.mark_cells("墙", QColor(169, 169, 169))  # 灰色

    def mark_as_door(self):
        self.mark_cells("门", QColor(255, 255, 224))  # 浅黄色

    def mark_cells(self, cell_type, color):
        if not self.selected_cells:
            return

        # 合并选择的单元格
        first_row, first_col = self.selected_cells[0].row(), self.selected_cells[0].column()
        last_row, last_col = self.selected_cells[-1].row(), self.selected_cells[-1].column()

        # 更新cell_types字典
        for row in range(first_row, last_row + 1):
            for col in range(first_col, last_col + 1):
                self.cell_types[(row, col)] = (cell_type, color)  # 保存类型和颜色

        # 更新区域显示
        for (row, col), (cell_type, color) in self.cell_types.items():
            if row >= first_row and row <= last_row and col >= first_col and col <= last_col:
                self.update_cell_visual(row, col, cell_type, color)

        # 清空选中的单元格
        self.selected_cells.clear()

    def mark_as_seating(self):
        for cell in self.selected_cells:
            item = QTableWidgetItem()
            item.setBackground(QColor(180, 180, 180))  # 设置背景颜色为灰色
            item.setTextAlignment(Qt.AlignCenter)
            self.table_widget.setItem(cell.row(), cell.column(), item)
            self.table_widget.item(cell.row(), cell.column()).setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) 

        self.selected_cells.clear()  # 清空选中的单元格

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.start_point = self.table_widget.indexAt(event.pos())
            if self.start_point.isValid():
                self.selected_cells = [self.start_point]

    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton:
            end_point = self.table_widget.indexAt(event.pos())
            if end_point.isValid() and end_point != self.start_point:
                rows = range(min(self.start_point.row(), end_point.row()), max(self.start_point.row(), end_point.row()) + 1)
                cols = range(min(self.start_point.column(), end_point.column()), max(self.start_point.column(), end_point.column()) + 1)
                self.selected_cells = [QPoint(row, col) for row in rows for col in cols]
                self.table_widget.clearSelection()
                for cell in self.selected_cells:
                    if self.table_widget.item(cell.row(), cell.column()):
                        self.table_widget.item(cell.row(), cell.column()).setSelected(True)

    def edit_class_members(self):
        dialog = QDialog(self)
        dialog.setWindowTitle("编辑班级人员")
        dialog.setGeometry(300, 300, 400, 300)

        # 创建布局管理器
        layout = QVBoxLayout()

        # 创建输入框
        id_label = QLabel("学号:")
        layout.addWidget(id_label)
        self.current_id_edit = QLineEdit()
        self.current_id_edit.setText(str(self.table_widget.rowCount() + 1))
        self.current_id_edit.setReadOnly(True)
        layout.addWidget(self.current_id_edit)

        name_label = QLabel("姓名:")
        layout.addWidget(name_label)
        self.current_name_edit = QLineEdit()
        layout.addWidget(self.current_name_edit)

        # 创建按钮
        add_button = QPushButton("添加")
        add_button.clicked.connect(self.add_class_member)
        layout.addWidget(add_button)

        dialog.setLayout(layout)
        dialog.exec_()

    def add_class_member(self):
        name = self.current_name_edit.text().strip()
        if name:
            current_row_count = self.table_widget.rowCount()
            self.table_widget.insertRow(current_row_count)
            self.table_widget.setItem(current_row_count, 0, QTableWidgetItem(str(current_row_count + 1)))  # 设置学号
            self.table_widget.setItem(current_row_count, 1, QTableWidgetItem(name))  # 设置姓名
            self.current_id_edit.setText(str(current_row_count + 2))
            self.class_members[current_row_count + 1] = name

    def save_config(self):
        options = QFileDialog.Options()
        file_path, _ = QFileDialog.getSaveFileName(self, "保存配置", "", "JSON Files (*.json);;All Files (*)", options=options)
        if file_path:
            config_data = {
                "row_count": self.table_widget.rowCount(),
                "column_count": self.table_widget.columnCount(),
                "class_name": self.class_name_edit.text(),
                "cell_types": self.cell_types,
                "class_members": self.class_members
            }
            with open(file_path, 'w') as file:
                json.dump(config_data, file, indent=4)
            QMessageBox.information(self, "保存成功", f"配置已成功保存到 {file_path}")

    def open_config(self):
        options = QFileDialog.Options()
        file_path, _ = QFileDialog.getOpenFileName(self, "打开配置", "", "JSON Files (*.json);;All Files (*)", options=options)
        if file_path:
            with open(file_path, 'r') as file:
                config_data = json.load(file)
                self.table_widget.setRowCount(config_data["row_count"])
                self.table_widget.setColumnCount(config_data["column_count"])
                self.class_name_edit.setText(config_data["class_name"])
                self.cell_types = config_data["cell_types"]
                self.class_members = config_data["class_members"]

                # 更新表格中的显示
                for (row, col), (cell_type, color) in self.cell_types.items():
                    self.update_cell_visual(row, col, cell_type, color)

                # 更新班级成员
                for row, name in self.class_members.items():
                    self.table_widget.setItem(row - 1, 1, QTableWidgetItem(name))
            QMessageBox.information(self, "加载成功", f"配置已成功从 {file_path} 加载")

    def start_seating(self):
        # 暂时未实现开始排座功能
        QMessageBox.information(self, "功能提示", "开始排座功能暂未实现")

    def export_to_png(self):
        # 暂时未实现导出为PNG功能
        QMessageBox.information(self, "功能提示", "导出为PNG功能暂未实现")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    # 加载字体
    font_db = QFontDatabase()
    font_id = font_db.addApplicationFont("gui/SDK_SC_Web65.ttf")
    font_family = font_db.applicationFontFamilies(font_id)[0]
    app.setFont(QFont(font_family, 12, QFont.Bold))  # 设置全局字体
    window = ConfigEditor()
    window.show()
    sys.exit(app.exec_())