123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- from PyQt6.QtCore import QUrl, QSize, QFileInfo
- from PyQt6.QtGui import QIcon, QDesktopServices, QColor
- from PyQt6.QtWidgets import QApplication
- from qfluentwidgets import (NavigationAvatarWidget, NavigationItemPosition, MessageBox, FluentWindow,MSFluentWindow,SplashScreen)
- from qfluentwidgets import FluentIcon as FIF
- from .main_video import MainVideo
- from .main_video_cate import MainVideoCate
- from .main_setting import MainSetting
- from .common.config import ZH_SUPPORT_URL, EN_SUPPORT_URL, cfg
- from .common.icon import Icon
- from .common.signal_bus import signalBus
- from .common.translator import Translator
- from demeter.core import *
- class MainWindow(MSFluentWindow):
- def __init__(self):
- super().__init__()
- self.initWindow()
-
- self.videoInterface = MainVideo(self)
- self.videoCateInterface = MainVideoCate(self)
- self.settingInterface = MainSetting(self)
-
-
- self.setCustomBackgroundColor(QColor(240, 244, 249), QColor(32, 32, 32))
- self.connectSignalToSlot()
-
- self.initNavigation()
- self.splashScreen.finish()
- def connectSignalToSlot(self):
- signalBus.micaEnableChanged.connect(self.setMicaEffectEnabled)
- signalBus.switchToSampleCard.connect(self.switchToSample)
- signalBus.supportSignal.connect(self.onSupport)
- def initNavigation(self):
-
- t = Translator()
- self.addSubInterface(self.videoInterface, FIF.MOVIE, '影片', FIF.MOVIE)
- self.addSubInterface(self.videoCateInterface, FIF.COPY, '分类')
-
- '''
- self.navigationInterface.addItem(
- routeKey='price',
- icon=Icon.PRICE,
- text=t.price,
- onClick=self.onSupport,
- selectable=False,
- #tooltip=t.price,
- position=NavigationItemPosition.BOTTOM
- )'''
- self.addSubInterface(
- self.settingInterface, FIF.SETTING, '设置', FIF.SETTING, NavigationItemPosition.BOTTOM)
- self.stackedWidget.currentChanged.connect(self.initData)
- def initData(self):
- widget = self.stackedWidget.currentWidget()
- if (widget and hasattr(widget, 'initData')):
- widget.initData()
- def initWindow(self):
- Demeter.model('video_cate').init()
- root = QFileInfo(__file__).absolutePath()
- self.setWindowIcon(QIcon(Demeter.path + 'gui/resource/images/logo.png'))
- self.setWindowTitle('灵镜')
- self.setMicaEffectEnabled(cfg.get(cfg.micaEnabled))
-
- self.splashScreen = SplashScreen(self.windowIcon(), self)
- self.splashScreen.setIconSize(QSize(106, 106))
- self.splashScreen.raise_()
- desktop = QApplication.screens()[0].size()
- w, h = desktop.width(), desktop.height()
- self.resize(w-576, h-114)
- self.setMinimumWidth(760)
- self.move(w//2 - self.width()//2, h//2 - self.height()//2)
- self.show()
- QApplication.processEvents()
- def onSupport(self):
- language = cfg.get(cfg.language).value
- if language.name() == "zh_CN":
- QDesktopServices.openUrl(QUrl(ZH_SUPPORT_URL))
- else:
- QDesktopServices.openUrl(QUrl(EN_SUPPORT_URL))
- def resizeEvent(self, e):
- super().resizeEvent(e)
- if hasattr(self, 'splashScreen'):
- self.splashScreen.resize(self.size())
- def switchToSample(self, routeKey, index):
- """ switch to sample """
- interfaces = self.findChildren(GalleryInterface)
- for w in interfaces:
- if w.objectName() == routeKey:
- self.stackedWidget.setCurrentWidget(w, False)
- w.scrollToCard(index)
|