def __init__(self): super(Window, self).__init__() self.setObjectName('MainWindow') self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowIcon(QIcon('resource/format.ico')) self.setWindowTitle("Music") with open('QSS/window.qss', 'r') as f: self.setStyleSheet(f.read()) self.resize(1022, 670) self.header = Header(self) self.navigation = Navigation(self) self.playWidgets = PlayWidgets(self) self.detailSings = DetailSings(self) self.mainContent = MainContent(self) self.nativeMusic = NativeMusic(self) self.searchArea = SearchArea(self) self.mainContents = QTabWidget() self.mainContents.tabBar().setObjectName("mainTab") self.systemTray = SystemTray('resource/logo.png', self) # 加载tab设置。 self.setContents() # 添加各类网站的歌单。 self.addAllPlaylist() # 设置布局小细线。 self.setLines() # 设置布局。 self.setLayouts() # 注册功能。 self.configFeatures()
def setTray(self): self.systemTray = SystemTray(self, 'icons/dictionary.png') self.systemTray.setToolTip("Dictionary!") self.systemTray.activated.connect( lambda: self.show() and self.activateWindow()) closeAction = QAction('退出', self, triggered=self.close) self.systemTray.addAction(closeAction) self.systemTray.show()
def __init__(self): super(Window, self).__init__() self.setObjectName('MainWindow') self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowIcon(QIcon('resource/format.ico')) self.setWindowTitle("Music") self.resize(1022, 670) self.header = Header(self) self.navigation = Navigation(self) self.playWidgets = PlayWidgets(self) self.detailSings = DetailSings(self) self.mainContent = MainContent(self) self.nativeMusic = NativeMusic(self) self.downloadFrame = DownloadFrame(self) self.searchArea = SearchArea(self) self.recommendFrame = RecommendFrame(self) self.mainContents = QTabWidget() self.mainContents.tabBar().setObjectName("mainTab") self.systemTray = SystemTray('resource/logo.png', self) # 加载tab设置。 self.setContents() # 添加各类网站的歌单。 self.addAllPlaylist() # 设置布局小细线。 self.setLines() # 设置布局。 self.setLayouts() # 注册功能。 self.configFeatures() with open('QSS/window.qss', 'r') as f: self.setStyleSheet(f.read())
class Window(QWidget): """Window 承载整个界面。""" def __init__(self): super(Window, self).__init__() self.setObjectName('MainWindow') self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowIcon(QIcon('resource/format.ico')) self.setWindowTitle("Music") with open('QSS/window.qss', 'r') as f: self.setStyleSheet(f.read()) self.resize(1022, 670) self.header = Header(self) self.navigation = Navigation(self) self.playWidgets = PlayWidgets(self) self.detailSings = DetailSings(self) self.mainContent = MainContent(self) self.nativeMusic = NativeMusic(self) self.searchArea = SearchArea(self) self.mainContents = QTabWidget() self.mainContents.tabBar().setObjectName("mainTab") self.systemTray = SystemTray('resource/logo.png', self) # 加载tab设置。 self.setContents() # 添加各类网站的歌单。 self.addAllPlaylist() # 设置布局小细线。 self.setLines() # 设置布局。 self.setLayouts() # 注册功能。 self.configFeatures() def addAllPlaylist(self): self.indexNetEaseSings = NetEaseSingsArea(self.mainContent) self.indexXiamiSings = XiamiSingsArea(self.mainContent) self.indexQQSings = QQSingsArea(self.mainContent) self.mainContent.addTab(self.indexNetEaseSings, "网易云歌单") self.mainContent.addTab(self.indexXiamiSings, "虾米歌单") self.mainContent.addTab(self.indexQQSings, "QQ歌单") # 布局。 def setContents(self): """设置tab界面。""" # 将需要切换的窗口做成Tab,并隐藏tabBar,这样方便切换,并且可以做前进后退功能。 self.mainContents.addTab(self.mainContent, '') self.mainContents.addTab(self.detailSings, '') self.mainContents.addTab(self.nativeMusic, '') self.mainContents.addTab(self.searchArea, '') self.mainContents.setCurrentIndex(0) def setLines(self): """设置布局小细线。""" self.line1 = QFrame(self) self.line1.setObjectName("line1") self.line1.setFrameShape(QFrame.HLine) self.line1.setFrameShadow(QFrame.Plain) self.line1.setLineWidth(2) def setLayouts(self): self.mainLayout = QVBoxLayout() self.mainLayout.addWidget(self.header) self.mainLayout.addWidget(self.line1) self.contentLayout = QHBoxLayout() self.contentLayout.setStretch(0, 70) self.contentLayout.setStretch(1, 570) self.contentLayout.addWidget(self.navigation) self.contentLayout.addWidget(self.mainContents) self.contentLayout.setSpacing(0) self.contentLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addLayout(self.contentLayout) self.mainLayout.addWidget(self.playWidgets) self.mainLayout.setStretch(0, 43) self.mainLayout.setStretch(1, 0) self.mainLayout.setStretch(2, 576) self.mainLayout.setStretch(3, 50) self.mainLayout.setSpacing(0) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.mainLayout) # 注册所有功能。 def configFeatures(self): self.config = ConfigWindow(self) self.header.config = ConfigHeader(self.header) self.searchArea.config = ConfigSearchArea(self.searchArea) self.navigation.config = ConfigNavigation(self.navigation) self.nativeMusic.config = ConfigNative(self.nativeMusic) self.mainContent.config = ConfigMainContent(self.mainContent) self.detailSings.config = ConfigDetailSings(self.detailSings) self.indexNetEaseSings.config = ConfigNetEase(self.indexNetEaseSings) self.indexXiamiSings.config = ConfigXiami(self.indexXiamiSings) self.indexQQSings.config = ConfigQQ(self.indexQQSings) self.systemTray.config = ConfigSystemTray(self.systemTray) self.indexNetEaseSings.config.initThread() self.indexXiamiSings.config.initThread() self.indexQQSings.config.initThread() def closeEvent(self, event): # 主要是保存cookies. self.header.config.saveCookies() self.playWidgets.saveCookies() # 系统托盘需要先隐藏,否则退出后会残留在任务栏。 self.systemTray.hide()
class Window(QWidget): """Window 承载整个界面。""" def __init__(self): super(Window, self).__init__() self.setObjectName('MainWindow') self.setWindowTitle('Dictionary') self.setWindowIcon(QIcon('icons/dictionary.png')) self.setWindowFlags(Qt.FramelessWindowHint) self.resize(540, 490) self.searchThread = RequestThread(self) self.searchThread.finished.connect(self.searchResult) self.mainLayout = VBoxLayout(self) self.setSearchFrame() self.setShowFrame() self.setTray() def setSearchFrame(self): self.searchFrame = SearchAndControlFrame(self) self.searchFrame.setSearchButtonConnect(self.searchWord) self.mainLayout.addWidget(self.searchFrame) def setShowFrame(self): self.showFrame = ShowFrame(self) self.mainLayout.addWidget(self.showFrame) self.showFrame.addEngine('Shanbay', ShanbaySearch()) self.showFrame.setCurrentRow(0) def searchWord(self): words = self.searchFrame.getText() self.startSearch(words) def startSearch(self, words): self.searchThread.setTarget(self.showFrame.engines[ self.showFrame.getCurrentEngine()].searchWord) self.searchThread.setArgs(words) self.searchThread.start() def searchResult(self): self.showFrame.setText(self.searchThread.result['definition']) def addEngine(self, name, funcName): self.showFrame.addEngine(name, funcName()) def setTray(self): self.systemTray = SystemTray(self, 'icons/dictionary.png') self.systemTray.setToolTip("Dictionary!") self.systemTray.activated.connect( lambda: self.show() and self.activateWindow()) closeAction = QAction('退出', self, triggered=self.close) self.systemTray.addAction(closeAction) self.systemTray.show() def closeEvent(self, event): sys.exit('close')
class Window(QWidget): """Window 承载整个界面。""" def __init__(self): super(Window, self).__init__() self.setObjectName('MainWindow') self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowIcon(QIcon('resource/format.ico')) self.setWindowTitle("Music") self.resize(1022, 670) self.header = Header(self) self.navigation = Navigation(self) self.playWidgets = PlayWidgets(self) self.detailSings = DetailSings(self) self.mainContent = MainContent(self) self.nativeMusic = NativeMusic(self) self.downloadFrame = DownloadFrame(self) self.searchArea = SearchArea(self) self.recommendFrame = RecommendFrame(self) self.mainContents = QTabWidget() self.mainContents.tabBar().setObjectName("mainTab") self.systemTray = SystemTray('resource/logo.png', self) # 加载tab设置。 self.setContents() # 添加各类网站的歌单。 self.addAllPlaylist() # 设置布局小细线。 self.setLines() # 设置布局。 self.setLayouts() # 注册功能。 self.configFeatures() with open('QSS/window.qss', 'r') as f: self.setStyleSheet(f.read()) def addAllPlaylist(self): self.indexNetEaseSings = NetEaseSingsArea(self.mainContent) self.indexXiamiSings = XiamiSingsArea(self.mainContent) self.indexQQSings = QQSingsArea(self.mainContent) self.mainContent.addTab(self.indexNetEaseSings, "网易云歌单") self.mainContent.addTab(self.indexXiamiSings, "虾米歌单") self.mainContent.addTab(self.indexQQSings, "QQ歌单") # 布局。 def setContents(self): """设置tab界面。""" # 将需要切换的窗口做成Tab,并隐藏tabBar,这样方便切换,并且可以做前进后退功能。 self.mainContents.addTab(self.mainContent, '') self.mainContents.addTab(self.detailSings, '') self.mainContents.addTab(self.nativeMusic, '') self.mainContents.addTab(self.downloadFrame, '') self.mainContents.addTab(self.recommendFrame, '') self.mainContents.addTab(self.searchArea, '') self.mainContents.setCurrentIndex(0) def setLines(self): """设置布局小细线。""" self.line1 = QFrame(self) self.line1.setObjectName("line1") self.line1.setFrameShape(QFrame.HLine) self.line1.setFrameShadow(QFrame.Plain) self.line1.setLineWidth(2) def setLayouts(self): self.mainLayout = QVBoxLayout() self.mainLayout.addWidget(self.header) self.mainLayout.addWidget(self.line1) self.contentLayout = QHBoxLayout() self.contentLayout.setStretch(0, 70) self.contentLayout.setStretch(1, 570) self.contentLayout.addWidget(self.navigation) self.contentLayout.addWidget(self.mainContents) self.contentLayout.setSpacing(0) self.contentLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addLayout(self.contentLayout) self.mainLayout.addWidget(self.playWidgets) self.mainLayout.setStretch(0, 43) self.mainLayout.setStretch(1, 0) self.mainLayout.setStretch(2, 576) self.mainLayout.setStretch(3, 50) self.mainLayout.setSpacing(0) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.mainLayout) # 注册所有功能。 def configFeatures(self): self.config = ConfigWindow(self) self.header.config = ConfigHeader(self.header) self.downloadFrame.config = ConfigDownloadFrame(self.downloadFrame) self.searchArea.config = ConfigSearchArea(self.searchArea) self.navigation.config = ConfigNavigation(self.navigation) self.nativeMusic.config = ConfigNative(self.nativeMusic) self.mainContent.config = ConfigMainContent(self.mainContent) self.detailSings.config = ConfigDetailSings(self.detailSings) self.indexNetEaseSings.config = ConfigNetEase(self.indexNetEaseSings) self.indexXiamiSings.config = ConfigXiami(self.indexXiamiSings) self.indexQQSings.config = ConfigQQ(self.indexQQSings) self.systemTray.config = ConfigSystemTray(self.systemTray) self.recommendFrame.config = ConfigRecommendFrame(self.recommendFrame) self.indexNetEaseSings.config.initThread() self.indexXiamiSings.config.initThread() self.indexQQSings.config.initThread() # 当前耦合度过高。 self.downloadFrame.config.getDownloadSignal() self.config.pullRecommendSong() # move to center. screen = QApplication.desktop().availableGeometry() self.playWidgets.desktopLyric.resize(screen.width(), 50) self.playWidgets.desktopLyric.move(0, screen.height() - 100) def closeEvent(self, event): # 主要是保存cookies. self.header.config.saveCookies() self.playWidgets.saveCookies() self.downloadFrame.config.saveCookies() # 关闭并保存数据库 self.db.commitAndClose() # 系统托盘需要先隐藏,否则退出后会残留在任务栏。 self.systemTray.hide() def resizeEvent(self, event): self. playWidgets.currentMusic.move(0, self.height()-64-self.playWidgets.height())