202 lines
7.6 KiB
Python
202 lines
7.6 KiB
Python
|
|
# coding: utf-8
|
|||
|
|
|
|||
|
|
from loguru import logger
|
|||
|
|
from PyQt6.QtCore import QSize
|
|||
|
|
from PyQt6.QtGui import QColor, QIcon
|
|||
|
|
from PyQt6.QtWidgets import QApplication, QWidget
|
|||
|
|
from qfluentwidgets import NavigationAvatarWidget, NavigationItemPosition, SplashScreen
|
|||
|
|
|
|||
|
|
from app.core import cfg, qconfig, userConfig, GetUserAvatarThread,lang,signalBus
|
|||
|
|
from app.view.app_info_interface import AppInfoInterface
|
|||
|
|
from app.view.ownFiled_interface import OwnFiledInterface
|
|||
|
|
from app.view.setting_interface import SettingInterface
|
|||
|
|
from app.view.storagespace_interface import StoragespaceInterface
|
|||
|
|
from app.view.task_interface import TaskInterface
|
|||
|
|
from app.view.widgets.custom_fluent_window import CustomFluentWindow
|
|||
|
|
from app.view.widgets.preview_box import OptimizedPreviewBox, PreviewTextBox
|
|||
|
|
from app.view.widgets.share_folder_messageBox import ShareFolderMessageBox
|
|||
|
|
|
|||
|
|
|
|||
|
|
class MainWindow(CustomFluentWindow):
|
|||
|
|
|
|||
|
|
def __init__(self):
|
|||
|
|
logger.info("开始初始化主窗口")
|
|||
|
|
super().__init__()
|
|||
|
|
self.initWindow()
|
|||
|
|
|
|||
|
|
self.ownFiledInterface = OwnFiledInterface(self)
|
|||
|
|
self.storagespaceInterface = StoragespaceInterface(self)
|
|||
|
|
self.taskInterface = TaskInterface(self)
|
|||
|
|
self.appInfoInterface = AppInfoInterface(self)
|
|||
|
|
|
|||
|
|
self.connectSignalToSlot()
|
|||
|
|
|
|||
|
|
self.initNavigation()
|
|||
|
|
logger.info("主窗口初始化完成")
|
|||
|
|
|
|||
|
|
def connectSignalToSlot(self):
|
|||
|
|
logger.debug("连接信号和槽")
|
|||
|
|
signalBus.micaEnableChanged.connect(self.setMicaEffectEnabled)
|
|||
|
|
# 预览信号连接
|
|||
|
|
signalBus.imagePreviewSignal.connect(self.imagePreview)
|
|||
|
|
signalBus.txtPreviewSignal.connect(self.txtPreview)
|
|||
|
|
# 背景信号连接
|
|||
|
|
signalBus.backgroundChanged.connect(self.updateBackground)
|
|||
|
|
signalBus.opacityChanged.connect(self.updateBackground)
|
|||
|
|
# 下载上传任务信号连接
|
|||
|
|
signalBus.addUploadFileTask.connect(self.addUploadFileTask)
|
|||
|
|
signalBus.addDownloadFileTask.connect(self.addDownloadFileTask)
|
|||
|
|
|
|||
|
|
signalBus.shareFolderViewSignal.connect(self.shareFolderView)
|
|||
|
|
# 语言变更信号连接
|
|||
|
|
signalBus.languageChanged.connect(self.updateNavigation)
|
|||
|
|
|
|||
|
|
def updateNavigation(self):
|
|||
|
|
# 更新导航项文本
|
|||
|
|
self.navigationInterface.setItemText(self.ownFiledInterface, lang("我的文件"))
|
|||
|
|
self.navigationInterface.setItemText(
|
|||
|
|
self.storagespaceInterface, lang("存储配额")
|
|||
|
|
)
|
|||
|
|
self.navigationInterface.setItemText(self.taskInterface, lang("任务管理"))
|
|||
|
|
self.navigationInterface.setItemText(self.appInfoInterface, lang("应用信息"))
|
|||
|
|
...
|
|||
|
|
|
|||
|
|
def initNavigation(self):
|
|||
|
|
self.navigationInterface.setAcrylicEnabled(True)
|
|||
|
|
self.navigationInterface.setExpandWidth(200)
|
|||
|
|
logger.info("开始初始化导航界面")
|
|||
|
|
|
|||
|
|
self.addSubInterface(
|
|||
|
|
self.ownFiledInterface,
|
|||
|
|
QIcon(":app/icons/Myfile.svg"),
|
|||
|
|
lang("我的文件"),
|
|||
|
|
NavigationItemPosition.TOP,
|
|||
|
|
)
|
|||
|
|
self.addSubInterface(
|
|||
|
|
self.storagespaceInterface,
|
|||
|
|
QIcon(":app/icons/Storage.svg"),
|
|||
|
|
lang("存储配额"),
|
|||
|
|
NavigationItemPosition.TOP,
|
|||
|
|
)
|
|||
|
|
self.addSubInterface(
|
|||
|
|
self.taskInterface,
|
|||
|
|
QIcon(":app/icons/Task.svg"),
|
|||
|
|
lang("任务管理"),
|
|||
|
|
NavigationItemPosition.TOP,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
self.addSubInterface(
|
|||
|
|
self.appInfoInterface,
|
|||
|
|
QIcon(":app/icons/Application.svg"),
|
|||
|
|
lang("应用信息"),
|
|||
|
|
NavigationItemPosition.BOTTOM,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 创建默认头像widget,先使用本地默认头像
|
|||
|
|
self.avatarWidget = NavigationAvatarWidget(
|
|||
|
|
userConfig.userName, ":app/images/logo.png"
|
|||
|
|
)
|
|||
|
|
self.navigationInterface.addWidget(
|
|||
|
|
routeKey="settingInterface",
|
|||
|
|
widget=self.avatarWidget,
|
|||
|
|
position=NavigationItemPosition.BOTTOM,
|
|||
|
|
onClick=self.setPersonalInfoWidget,
|
|||
|
|
)
|
|||
|
|
self.settingInterface = SettingInterface(self)
|
|||
|
|
self.stackedWidget.addWidget(self.settingInterface)
|
|||
|
|
|
|||
|
|
self.splashScreen.finish()
|
|||
|
|
logger.info("导航界面初始化完成")
|
|||
|
|
|
|||
|
|
self.avatarThread = GetUserAvatarThread("l")
|
|||
|
|
self.avatarThread.avatarPixmap.connect(self.onAvatarDownloaded)
|
|||
|
|
self.avatarThread.start()
|
|||
|
|
|
|||
|
|
def shareFolderView(self, _id):
|
|||
|
|
w = ShareFolderMessageBox(_id, self)
|
|||
|
|
if w.exec():
|
|||
|
|
...
|
|||
|
|
|
|||
|
|
def addUploadFileTask(self, filePath):
|
|||
|
|
logger.info(f"添加上传文件任务: {filePath}")
|
|||
|
|
self.taskInterface.uploadScrollWidget.addUploadTask(filePath)
|
|||
|
|
self.stackedWidget.setCurrentWidget(self.taskInterface)
|
|||
|
|
self.navigationInterface.setCurrentItem("taskInterface")
|
|||
|
|
self.taskInterface._changePivot("Upload")
|
|||
|
|
|
|||
|
|
def addDownloadFileTask(self, suffix, fileName, _id):
|
|||
|
|
logger.info(f"添加下载文件任务: {fileName}")
|
|||
|
|
self.taskInterface.downloadScrollWidget.addDownloadTask(suffix, fileName, _id)
|
|||
|
|
self.stackedWidget.setCurrentWidget(self.taskInterface)
|
|||
|
|
self.navigationInterface.setCurrentItem("taskInterface")
|
|||
|
|
self.taskInterface._changePivot("Download")
|
|||
|
|
|
|||
|
|
def setPersonalInfoWidget(self):
|
|||
|
|
self.stackedWidget.setCurrentWidget(
|
|||
|
|
self.stackedWidget.findChild(QWidget, "settingInterface")
|
|||
|
|
)
|
|||
|
|
self.navigationInterface.setCurrentItem("settingInterface")
|
|||
|
|
|
|||
|
|
def onAvatarDownloaded(self, pixmap):
|
|||
|
|
|
|||
|
|
userConfig.setUserAvatarPixmap(pixmap)
|
|||
|
|
self.avatarWidget.setAvatar(pixmap)
|
|||
|
|
self.settingInterface.updateAvatar(pixmap)
|
|||
|
|
|
|||
|
|
def initWindow(self):
|
|||
|
|
logger.info("开始初始化窗口设置")
|
|||
|
|
self.resize(960, 780)
|
|||
|
|
self.setMinimumWidth(760)
|
|||
|
|
self.setWindowIcon(QIcon(":app/images/logo.png"))
|
|||
|
|
self.setWindowTitle(lang("LeonPan"))
|
|||
|
|
|
|||
|
|
logger.debug("已设置窗口基本属性")
|
|||
|
|
|
|||
|
|
self.setCustomBackgroundColor(QColor(240, 244, 249), QColor(32, 32, 32))
|
|||
|
|
self.setMicaEffectEnabled(cfg.get(cfg.micaEnabled))
|
|||
|
|
logger.debug("已设置窗口背景和Mica效果")
|
|||
|
|
self.setBackgroundImage(
|
|||
|
|
qconfig.get(cfg.customBackground), qconfig.get(cfg.customOpactity)
|
|||
|
|
) # create splash screen
|
|||
|
|
# 使用自定义的背景设置方法
|
|||
|
|
# create splash screen
|
|||
|
|
self.splashScreen = SplashScreen(self.windowIcon(), self)
|
|||
|
|
self.splashScreen.setIconSize(QSize(106, 106))
|
|||
|
|
self.splashScreen.raise_()
|
|||
|
|
logger.debug("已创建并设置启动屏幕")
|
|||
|
|
|
|||
|
|
desktop = QApplication.primaryScreen().availableGeometry()
|
|||
|
|
w, h = desktop.width(), desktop.height()
|
|||
|
|
self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)
|
|||
|
|
logger.debug("已移动窗口到屏幕中心")
|
|||
|
|
|
|||
|
|
self.show()
|
|||
|
|
QApplication.processEvents()
|
|||
|
|
logger.info("窗口初始化完成并显示")
|
|||
|
|
|
|||
|
|
def resizeEvent(self, e):
|
|||
|
|
super().resizeEvent(e)
|
|||
|
|
if hasattr(self, "splashScreen"):
|
|||
|
|
self.splashScreen.resize(self.size())
|
|||
|
|
# 窗口大小改变时更新背景
|
|||
|
|
|
|||
|
|
def imagePreview(self, _id):
|
|||
|
|
# 使用V4 API进行预览
|
|||
|
|
url = f"/file/preview/{_id}"
|
|||
|
|
self.previewBox = OptimizedPreviewBox(self, url)
|
|||
|
|
if self.previewBox.exec():
|
|||
|
|
pass
|
|||
|
|
|
|||
|
|
def txtPreview(self, _id):
|
|||
|
|
# 使用V4 API获取内容
|
|||
|
|
url = f"/file/content/{_id}"
|
|||
|
|
self.previewBox = PreviewTextBox(self, url, _id)
|
|||
|
|
if self.previewBox.exec():
|
|||
|
|
pass
|
|||
|
|
|
|||
|
|
def updateBackground(self):
|
|||
|
|
"""更新窗口背景"""
|
|||
|
|
self.setBackgroundImage(
|
|||
|
|
qconfig.get(cfg.customBackground), qconfig.get(cfg.customOpactity)
|
|||
|
|
)
|