61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
import sys
|
||
from PySide6.QtWidgets import QApplication, QMainWindow, QTabWidget
|
||
from PySide6.QtCore import QSize
|
||
from loguru import logger
|
||
|
||
from server_connection_tab import ServerConnectionTab
|
||
from remote_commands_tab import RemoteCommandsTab
|
||
|
||
class MainWindow(QMainWindow):
|
||
def __init__(self):
|
||
super().__init__()
|
||
|
||
logger.info("初始化主窗口")
|
||
self.setWindowTitle("服务器管理工具")
|
||
self.setMinimumSize(QSize(800, 600))
|
||
|
||
# 创建标签页组件
|
||
self.tabs = QTabWidget()
|
||
self.setCentralWidget(self.tabs)
|
||
|
||
# 添加服务器连接标签页
|
||
self.server_connection_tab = ServerConnectionTab()
|
||
self.tabs.addTab(self.server_connection_tab, "服务器连接")
|
||
|
||
# 添加远程命令标签页
|
||
self.remote_commands_tab = RemoteCommandsTab()
|
||
self.tabs.addTab(self.remote_commands_tab, "远程命令")
|
||
|
||
# 连接标签页切换信号
|
||
self.tabs.currentChanged.connect(self.on_tab_changed)
|
||
|
||
logger.info("主窗口初始化完成")
|
||
|
||
def on_tab_changed(self, index):
|
||
logger.info(f"标签页切换到: {index}")
|
||
|
||
# 当切换到远程命令标签页时,传递SSH客户端和服务器配置
|
||
if index == 1: # 远程命令标签页
|
||
ssh_client = self.server_connection_tab.get_ssh_client()
|
||
self.remote_commands_tab.set_ssh_client(ssh_client)
|
||
|
||
# 获取当前选中的服务器配置
|
||
current_alias = self.server_connection_tab.alias_combo.currentText()
|
||
if current_alias and current_alias in self.server_connection_tab.config_data:
|
||
server_config = self.server_connection_tab.config_data[current_alias]
|
||
git_url = server_config.get("git_url", "")
|
||
remote_dir = server_config.get("remote_dir", "")
|
||
self.remote_commands_tab.set_server_config(git_url, remote_dir)
|
||
else:
|
||
# 如果没有配置远程目录,初始化为默认目录
|
||
self.remote_commands_tab.current_dir_display.setText("~")
|
||
self.remote_commands_tab.refresh_directory()
|
||
|
||
if __name__ == "__main__":
|
||
logger.add("app.log", rotation="10 MB")
|
||
logger.info("启动应用程序")
|
||
|
||
app = QApplication(sys.argv)
|
||
window = MainWindow()
|
||
window.show()
|
||
sys.exit(app.exec()) |