main_window.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # coding: utf-8
  2. from PyQt6.QtCore import QUrl, QSize, QFileInfo
  3. from PyQt6.QtGui import QIcon, QDesktopServices, QColor
  4. from PyQt6.QtWidgets import QApplication
  5. from qfluentwidgets import (NavigationAvatarWidget, NavigationItemPosition, MessageBox, FluentWindow,MSFluentWindow,SplashScreen)
  6. from qfluentwidgets import FluentIcon as FIF
  7. from .main_video import MainVideo
  8. from .main_video_cate import MainVideoCate
  9. from .main_setting import MainSetting
  10. from .common.config import ZH_SUPPORT_URL, EN_SUPPORT_URL, cfg
  11. from .common.icon import Icon
  12. from .common.signal_bus import signalBus
  13. from .common.translator import Translator
  14. from demeter.core import *
  15. class MainWindow(MSFluentWindow):
  16. def __init__(self):
  17. super().__init__()
  18. self.initWindow()
  19. # create sub interface
  20. self.videoInterface = MainVideo(self)
  21. self.videoCateInterface = MainVideoCate(self)
  22. self.settingInterface = MainSetting(self)
  23. # enable acrylic effect
  24. #self.navigationInterface.setAcrylicEnabled(True)
  25. self.setCustomBackgroundColor(QColor(240, 244, 249), QColor(32, 32, 32))
  26. self.connectSignalToSlot()
  27. # add items to navigation interface
  28. self.initNavigation()
  29. self.splashScreen.finish()
  30. def connectSignalToSlot(self):
  31. signalBus.micaEnableChanged.connect(self.setMicaEffectEnabled)
  32. signalBus.switchToSampleCard.connect(self.switchToSample)
  33. signalBus.supportSignal.connect(self.onSupport)
  34. def initNavigation(self):
  35. # add navigation items
  36. t = Translator()
  37. self.addSubInterface(self.videoInterface, FIF.MOVIE, '影片', FIF.MOVIE)
  38. self.addSubInterface(self.videoCateInterface, FIF.COPY, '分类')
  39. # add custom widget to bottom
  40. '''
  41. self.navigationInterface.addItem(
  42. routeKey='price',
  43. icon=Icon.PRICE,
  44. text=t.price,
  45. onClick=self.onSupport,
  46. selectable=False,
  47. #tooltip=t.price,
  48. position=NavigationItemPosition.BOTTOM
  49. )'''
  50. self.addSubInterface(
  51. self.settingInterface, FIF.SETTING, '设置', FIF.SETTING, NavigationItemPosition.BOTTOM)
  52. self.stackedWidget.currentChanged.connect(self.initData)
  53. def initData(self):
  54. widget = self.stackedWidget.currentWidget()
  55. if (widget and hasattr(widget, 'initData')):
  56. widget.initData()
  57. def initWindow(self):
  58. Demeter.model('video_cate').init()
  59. root = QFileInfo(__file__).absolutePath()
  60. self.setWindowIcon(QIcon(Demeter.path + 'gui/resource/images/logo.png'))
  61. self.setWindowTitle('灵镜')
  62. self.setMicaEffectEnabled(cfg.get(cfg.micaEnabled))
  63. # create splash screen
  64. self.splashScreen = SplashScreen(self.windowIcon(), self)
  65. self.splashScreen.setIconSize(QSize(106, 106))
  66. self.splashScreen.raise_()
  67. desktop = QApplication.screens()[0].size()
  68. w, h = desktop.width(), desktop.height()
  69. self.resize(w-576, h-114)
  70. self.setMinimumWidth(760)
  71. self.move(w//2 - self.width()//2, h//2 - self.height()//2)
  72. self.show()
  73. QApplication.processEvents()
  74. def onSupport(self):
  75. language = cfg.get(cfg.language).value
  76. if language.name() == "zh_CN":
  77. QDesktopServices.openUrl(QUrl(ZH_SUPPORT_URL))
  78. else:
  79. QDesktopServices.openUrl(QUrl(EN_SUPPORT_URL))
  80. def resizeEvent(self, e):
  81. super().resizeEvent(e)
  82. if hasattr(self, 'splashScreen'):
  83. self.splashScreen.resize(self.size())
  84. def switchToSample(self, routeKey, index):
  85. """ switch to sample """
  86. interfaces = self.findChildren(GalleryInterface)
  87. for w in interfaces:
  88. if w.objectName() == routeKey:
  89. self.stackedWidget.setCurrentWidget(w, False)
  90. w.scrollToCard(index)