初始化项目:添加Proxmox GUI管理平台
This commit is contained in:
92
config_dialog.py
Normal file
92
config_dialog.py
Normal file
@@ -0,0 +1,92 @@
|
||||
from PySide6.QtWidgets import (QDialog, QVBoxLayout, QFormLayout, QLineEdit,
|
||||
QCheckBox, QPushButton, QHBoxLayout, QMessageBox)
|
||||
from PySide6.QtCore import Qt
|
||||
from vm_manager import VMManager
|
||||
|
||||
class ConfigDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.vm_manager = VMManager()
|
||||
self.setup_ui()
|
||||
self.load_current_config()
|
||||
|
||||
def setup_ui(self):
|
||||
self.setWindowTitle("配置连接信息")
|
||||
self.setMinimumWidth(400)
|
||||
layout = QVBoxLayout(self)
|
||||
form_layout = QFormLayout()
|
||||
form_layout.setSpacing(15)
|
||||
form_layout.setLabelAlignment(Qt.AlignmentFlag.AlignRight)
|
||||
|
||||
self.host_edit = QLineEdit()
|
||||
self.host_edit.setPlaceholderText("例如: 192.168.1.100")
|
||||
form_layout.addRow("PVE 主机 IP:", self.host_edit)
|
||||
|
||||
self.user_edit = QLineEdit()
|
||||
self.user_edit.setPlaceholderText("例如: root@pam")
|
||||
form_layout.addRow("用户名:", self.user_edit)
|
||||
|
||||
self.password_edit = QLineEdit()
|
||||
self.password_edit.setPlaceholderText("输入 PVE 密码")
|
||||
self.password_edit.setEchoMode(QLineEdit.EchoMode.Password)
|
||||
form_layout.addRow("密码:", self.password_edit)
|
||||
|
||||
self.node_edit = QLineEdit()
|
||||
self.node_edit.setPlaceholderText("例如: pve")
|
||||
self.node_edit.setText("pve")
|
||||
form_layout.addRow("节点名称:", self.node_edit)
|
||||
|
||||
self.ssl_checkbox = QCheckBox("验证 SSL 证书")
|
||||
self.ssl_checkbox.setChecked(False)
|
||||
form_layout.addRow("", self.ssl_checkbox)
|
||||
|
||||
layout.addLayout(form_layout)
|
||||
layout.addSpacing(20)
|
||||
|
||||
button_layout = QHBoxLayout()
|
||||
button_layout.addStretch()
|
||||
|
||||
self.save_button = QPushButton("保存配置")
|
||||
self.save_button.clicked.connect(self.save_config)
|
||||
button_layout.addWidget(self.save_button)
|
||||
|
||||
self.cancel_button = QPushButton("取消")
|
||||
self.cancel_button.clicked.connect(self.reject)
|
||||
button_layout.addWidget(self.cancel_button)
|
||||
|
||||
layout.addLayout(button_layout)
|
||||
layout.addSpacing(10)
|
||||
|
||||
def load_current_config(self):
|
||||
config = self.vm_manager.get_config()
|
||||
self.host_edit.setText(config.get('host', ''))
|
||||
self.user_edit.setText(config.get('user', ''))
|
||||
self.password_edit.setText(config.get('password', ''))
|
||||
self.node_edit.setText(config.get('node', 'pve'))
|
||||
self.ssl_checkbox.setChecked(config.get('verify_ssl', False))
|
||||
|
||||
def save_config(self):
|
||||
host = self.host_edit.text().strip()
|
||||
user = self.user_edit.text().strip()
|
||||
password = self.password_edit.text()
|
||||
node = self.node_edit.text().strip() or 'pve'
|
||||
verify_ssl = self.ssl_checkbox.isChecked()
|
||||
|
||||
if not host or not user or not password:
|
||||
QMessageBox.warning(self, "警告", "请填写完整的连接信息!")
|
||||
return
|
||||
|
||||
config = {
|
||||
'host': host,
|
||||
'user': user,
|
||||
'password': password,
|
||||
'node': node,
|
||||
'verify_ssl': verify_ssl
|
||||
}
|
||||
|
||||
self.vm_manager.save_config(config)
|
||||
QMessageBox.information(self, "成功", "配置已保存!")
|
||||
self.accept()
|
||||
|
||||
def get_config(self):
|
||||
return self.vm_manager.get_config()
|
||||
Reference in New Issue
Block a user