fix 33
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# mainwindow.py
|
||||
import sys
|
||||
import logging
|
||||
import re
|
||||
@@ -5,7 +6,7 @@ import os
|
||||
|
||||
from PySide6.QtWidgets import (QApplication, QMainWindow, QTreeWidgetItem,
|
||||
QMessageBox, QHeaderView, QMenu, QInputDialog, QDialog)
|
||||
from PySide6.QtCore import Qt, QPoint
|
||||
from PySide6.QtCore import Qt, QPoint, QThread # <--- 确保导入 QThread
|
||||
|
||||
# 导入自动生成的 UI 文件
|
||||
from ui_form import Ui_MainWindow
|
||||
@@ -35,9 +36,11 @@ class MainWindow(QMainWindow):
|
||||
|
||||
# 初始化管理器和操作类
|
||||
self.system_manager = SystemInfoManager()
|
||||
self.disk_ops = DiskOperations(self.system_manager)
|
||||
self.lvm_ops = LvmOperations() # <--- 先初始化 LvmOperations
|
||||
# <--- 将 lvm_ops 实例传递给 DiskOperations
|
||||
self.disk_ops = DiskOperations(self.system_manager, self.lvm_ops)
|
||||
self.raid_ops = RaidOperations()
|
||||
self.lvm_ops = LvmOperations() # LvmOperations 包含通用的 _execute_shell_command
|
||||
# self.lvm_ops = LvmOperations() # 这一行是重复的,可以删除
|
||||
|
||||
# 连接刷新按钮的信号到槽函数
|
||||
if hasattr(self.ui, 'refreshButton'):
|
||||
@@ -55,6 +58,11 @@ class MainWindow(QMainWindow):
|
||||
self.ui.treeWidget_lvm.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.ui.treeWidget_lvm.customContextMenuRequested.connect(self.show_lvm_context_menu)
|
||||
|
||||
# <--- 新增: 连接 DiskOperations 的格式化完成信号
|
||||
self.disk_ops.formatting_finished.connect(self.on_disk_formatting_finished)
|
||||
# 可选:连接格式化开始信号,用于显示进度或禁用相关操作
|
||||
# self.disk_ops.formatting_started.connect(self.on_disk_formatting_started)
|
||||
|
||||
# 初始化时刷新所有数据
|
||||
self.refresh_all_info()
|
||||
logger.info("所有设备信息已初始化加载。")
|
||||
@@ -195,6 +203,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
logger.warning(f"尝试擦除 {device_path} 上的分区表。")
|
||||
# 使用 LvmOperations 中通用的 _execute_shell_command 来执行 parted 命令
|
||||
# 这里不需要 show_dialog=False,因为这个操作本身就是同步且需要用户确认的
|
||||
success, _, stderr = self.lvm_ops._execute_shell_command(
|
||||
["parted", "-s", device_path, "mklabel", "gpt"], # 默认使用 gpt 分区表类型
|
||||
f"擦除 {device_path} 上的分区表失败"
|
||||
@@ -290,8 +299,21 @@ class MainWindow(QMainWindow):
|
||||
self.refresh_all_info()
|
||||
|
||||
def _handle_format_partition(self, device_path):
|
||||
if self.disk_ops.format_partition(device_path):
|
||||
self.refresh_all_info()
|
||||
"""
|
||||
调用 DiskOperations 的异步格式化方法。
|
||||
"""
|
||||
# DiskOperations.format_partition 会处理用户确认和启动后台线程
|
||||
self.disk_ops.format_partition(device_path)
|
||||
# 界面刷新将在格式化完成后由 on_disk_formatting_finished 槽函数触发,所以这里不需要 refresh_all_info()
|
||||
|
||||
# <--- 新增: 格式化完成后的槽函数
|
||||
def on_disk_formatting_finished(self, success, device_path, stdout, stderr):
|
||||
"""
|
||||
接收 DiskOperations 发出的格式化完成信号,并刷新界面。
|
||||
"""
|
||||
logger.info(f"格式化完成信号接收: 设备 {device_path}, 成功: {success}")
|
||||
# QMessageBox 已经在 DiskOperations 的 _on_formatting_finished 中处理
|
||||
self.refresh_all_info() # 刷新所有信息以显示更新后的文件系统类型等
|
||||
|
||||
# --- RAID 管理 Tab ---
|
||||
def refresh_raid_info(self):
|
||||
@@ -424,8 +446,12 @@ class MainWindow(QMainWindow):
|
||||
self.refresh_all_info()
|
||||
|
||||
def _handle_format_raid_array(self, array_path):
|
||||
if self.disk_ops.format_partition(array_path):
|
||||
self.refresh_all_info()
|
||||
"""
|
||||
处理 RAID 阵列的格式化。
|
||||
"""
|
||||
# 这将调用 DiskOperations 的异步格式化方法
|
||||
self.disk_ops.format_partition(array_path)
|
||||
# 刷新操作会在 on_disk_formatting_finished 中触发,所以这里不需要 refresh_all_info()
|
||||
|
||||
# --- LVM 管理 Tab ---
|
||||
def refresh_lvm_info(self):
|
||||
|
||||
Reference in New Issue
Block a user