def __init__(self): super(MainWindowController, self).__init__() self.ui = MainWindow.Ui_MainWindow() self.ui.setupUi(self) self.setup_view() self.left_side_view_group = MainWindowViewGroup( self.ui.partitionsListWidgetLeft, self.ui.catalogTreeWidgetLeft, self.ui.connectionInfoLabelLeft, 'L', None) self.right_side_view_group = MainWindowViewGroup( self.ui.partitionsListWidgetRight, self.ui.catalogTreeWidgetRight, self.ui.connectionInfoLabelRight, 'R', None) self.setup_host_startup()
def initView(self): self.mainWindow = MainWindow() self.lrcWindowManager = LrcWindowManager(self.mainWindow)
class DeepinPlayer(QObject): _instance = None def __init__(self): super(DeepinPlayer, self).__init__() self.initApplication() self.initView() self.initControllers() self.initConnect() self.initQMLContext() self.loadDB() self.timer = QTimer() self.timer.timeout.connect(self.clearCache) self.timer.start(2000) @classmethod def instance(cls): if cls._instance is None: cls._instance = cls() return cls._instance @classmethod def getMainWindow(cls): instance = cls.instance() if instance: return instance.mainWindow def initApplication(self): self.qApp = QCoreApplication.instance() self.qApp.setApplicationName(config.applicationName) self.qApp.setApplicationVersion(config.applicationVersion) self.qApp.setOrganizationName(config.organizationName) self.qApp.setWindowIcon(QIcon(config.windowIcon)) def loadDB(self): QTimer.singleShot(100, musicManageWorker.restoreDB) signalManager.downloadSuggestPlaylist.emit() def initView(self): self.mainWindow = MainWindow() self.lrcWindowManager = LrcWindowManager(self.mainWindow) def initControllers(self): self.playerBinThread = QThread() gPlayer.moveToThread(self.playerBinThread) self.playerBinThread.start() self.dbThread = QThread() dbWorker.moveToThread(self.dbThread) self.dbThread.start() def initQMLContext(self): self.mainWindow.setContexts(contexts) self.mainWindow.setSource(QUrl.fromLocalFile(os.path.join( get_parent_dir(__file__, 2), 'views', 'Main.qml'))) self.qmlDialog = QmlDialog(self.mainWindow.engine()) self.mainWindow.setContext('QmlDialog', self.qmlDialog) def initConnect(self): self.playlistWorkerConnect() self.coverWorkerConnect() self.musicManageWorkerConnect() self.onlineMusicManageWorkerConnect() self.menuWorkerConnect() self.dbWorkerConnect() self.downloadSongWorkerConnect() signalManager.registerQmlObj.connect(self.mainWindow.setContext) signalManager.exited.connect(self.qApp.aboutToQuit) self.qApp.aboutToQuit.connect(self.close) def playlistWorkerConnect(self): playlistWorker.currentPlaylistChanged.connect(mediaPlayer.setPlaylistByName) def coverWorkerConnect(self): coverWorker.updateArtistCover.connect(musicManageWorker.updateArtistCover) coverWorker.updateAlbumCover.connect(musicManageWorker.updateAlbumCover) coverWorker.updateOnlineSongCover.connect( onlineMusicManageWorker.updateSongCover) coverWorker.updateAlbumCover.connect( onlineMusicManageWorker.updateSongCover) def musicManageWorkerConnect(self): musicManageWorker.saveSongToDB.connect(dbWorker.addSong) musicManageWorker.saveSongsToDB.connect(dbWorker.addSongs) musicManageWorker.restoreSongsToDB.connect(dbWorker.restoreSongs) musicManageWorker.addSongToPlaylist.connect( playlistWorker.addLocalMediaToTemporary) musicManageWorker.addSongsToPlaylist.connect( playlistWorker.addLocalMediasToTemporary) musicManageWorker.playSongByUrl.connect(mediaPlayer.playLocalMedia) musicManageWorker.downloadArtistCover.connect( coverWorker.downloadArtistCover) musicManageWorker.downloadAlbumCover.connect(coverWorker.downloadAlbumCover) musicManageWorker.loadDBSuccessed.connect(playlistWorker.loadPlaylists) musicManageWorker.loadDBSuccessed.connect(self.loadConfig) def onlineMusicManageWorkerConnect(self): onlineMusicManageWorker.downloadOnlineSongCover.connect( coverWorker.downloadOnlineSongCover) onlineMusicManageWorker.downloadOnlineAlbumCover.connect( coverWorker.downloadOnlineAlbumCover) onlineMusicManageWorker.downloadAlbumCover.connect( coverWorker.downloadAlbumCover) pass def menuWorkerConnect(self): # setting menu menuWorker.addSongFile.connect(musicManageWorker.addSongFile) menuWorker.addSongFolder.connect(musicManageWorker.searchOneFolderMusic) # artist menu menuWorker.playArtist.connect(musicManageWorker.playArtist) menuWorker.removeFromDatabaseByArtistName.connect( musicManageWorker.removeFromDatabaseByArtistName) menuWorker.removeFromDriverByArtistName.connect( musicManageWorker.removeFromDriverByArtistName) # album menu menuWorker.playAlbum.connect(musicManageWorker.playAlbum) menuWorker.removeFromDatabaseByAlbumName.connect( musicManageWorker.removeFromDatabaseByAlbumName) menuWorker.removeFromDriverByAlbumName.connect( musicManageWorker.removeFromDriverByAlbumName) # song menu menuWorker.orderByKey.connect(musicManageWorker.orderByKey) menuWorker.openSongFolder.connect(musicManageWorker.openSongFolder) menuWorker.removeFromDatabaseByUrl.connect( musicManageWorker.removeFromDatabaseByUrl) menuWorker.removeFromDriveByUrl.connect( musicManageWorker.removeFromDriveByUrl) # folder menu menuWorker.playFolder.connect(musicManageWorker.playFolder) menuWorker.removeFromDatabaseByFolderName.connect( musicManageWorker.removeFromDatabaseByFolderName) menuWorker.removeFromDriverByFolderName.connect( musicManageWorker.removeFromDriverByFolderName) #playlist menu menuWorker.removeFromPlaylist.connect(playlistWorker.removeFromPlaylist) #playlist navigation menu menuWorker.deletePlaylist.connect(playlistWorker.deletePlaylist) #download menu menuWorker.removeFromDownloadList.connect(downloadSongWorker.delSongObj) #public menu: menuWorker.addSongToPlaylist.connect(playlistWorker.addSongToPlaylist) menuWorker.addSongsToPlaylist.connect(playlistWorker.addSongsToPlaylist) def dbWorkerConnect(self): dbWorker.restoreSongsSuccessed.connect(musicManageWorker.loadDB) def downloadSongWorkerConnect(self): downloadSongWorker.addDownloadSongToDataBase.connect( musicManageWorker.addLocalSongToDataBase) def loadConfig(self): mediaPlayer.setPlaylistByName(configWorker.lastPlaylistName) mediaPlayer.setCurrentIndex(configWorker.lastPlayedIndex) mediaPlayer.volume = configWorker.volume mediaPlayer.playbackMode = configWorker.playbackMode def showMainWindow(self): self.mainWindow.show() self.mainWindow.setRoundMask() self.qApp.setActivationWindow(self.mainWindow) def show(self): self.showMainWindow() def clearCache(self): if isWebengineUsed: self.mainWindow.engine().clearComponentCache() self.mainWindow.engine().collectGarbage() self.mainWindow.engine().trimComponentCache() else: self.mainWindow.engine().collectGarbage() self.mainWindow.engine().trimComponentCache() def close(self): QThreadPool.globalInstance().clear() mediaPlayer.stop() configWorker.save() playlistWorker.savePlaylists()
from gi.repository import Gtk from views import MainWindow if __name__ == '__main__': window = MainWindow() window.dbs.fill_databases() window.show_all() Gtk.main()
class DeepinPlayer(QObject): _instance = None def __init__(self): super(DeepinPlayer, self).__init__() self.initApplication() self.initView() self.initControllers() self.initConnect() self.initQMLContext() self.loadDB() self.timer = QTimer() self.timer.timeout.connect(self.clearCache) self.timer.start(2000) @classmethod def instance(cls): if cls._instance is None: cls._instance = cls() return cls._instance @classmethod def getMainWindow(cls): instance = cls.instance() if instance: return instance.mainWindow def initApplication(self): self.qApp = QCoreApplication.instance() self.qApp.setApplicationName(config.applicationName) self.qApp.setApplicationVersion(config.applicationVersion) self.qApp.setOrganizationName(config.organizationName) self.qApp.setWindowIcon(QIcon(config.windowIcon)) def loadDB(self): QTimer.singleShot(100, musicManageWorker.restoreDB) signalManager.downloadSuggestPlaylist.emit() def initView(self): self.mainWindow = MainWindow() self.lrcWindowManager = LrcWindowManager(self.mainWindow) def initControllers(self): self.playerBinThread = QThread() gPlayer.moveToThread(self.playerBinThread) self.playerBinThread.start() self.dbThread = QThread() dbWorker.moveToThread(self.dbThread) self.dbThread.start() def initQMLContext(self): self.mainWindow.setContexts(contexts) self.mainWindow.setSource( QUrl.fromLocalFile( os.path.join(get_parent_dir(__file__, 2), 'views', 'Main.qml'))) self.qmlDialog = QmlDialog(self.mainWindow.engine()) self.mainWindow.setContext('QmlDialog', self.qmlDialog) def initConnect(self): self.playlistWorkerConnect() self.coverWorkerConnect() self.musicManageWorkerConnect() self.onlineMusicManageWorkerConnect() self.menuWorkerConnect() self.dbWorkerConnect() self.downloadSongWorkerConnect() signalManager.registerQmlObj.connect(self.mainWindow.setContext) signalManager.exited.connect(self.qApp.aboutToQuit) self.qApp.aboutToQuit.connect(self.close) def playlistWorkerConnect(self): playlistWorker.currentPlaylistChanged.connect( mediaPlayer.setPlaylistByName) def coverWorkerConnect(self): coverWorker.updateArtistCover.connect( musicManageWorker.updateArtistCover) coverWorker.updateAlbumCover.connect( musicManageWorker.updateAlbumCover) coverWorker.updateOnlineSongCover.connect( onlineMusicManageWorker.updateSongCover) coverWorker.updateAlbumCover.connect( onlineMusicManageWorker.updateSongCover) def musicManageWorkerConnect(self): musicManageWorker.saveSongToDB.connect(dbWorker.addSong) musicManageWorker.saveSongsToDB.connect(dbWorker.addSongs) musicManageWorker.restoreSongsToDB.connect(dbWorker.restoreSongs) musicManageWorker.addSongToPlaylist.connect( playlistWorker.addLocalMediaToTemporary) musicManageWorker.addSongsToPlaylist.connect( playlistWorker.addLocalMediasToTemporary) musicManageWorker.playSongByUrl.connect(mediaPlayer.playLocalMedia) musicManageWorker.downloadArtistCover.connect( coverWorker.downloadArtistCover) musicManageWorker.downloadAlbumCover.connect( coverWorker.downloadAlbumCover) musicManageWorker.loadDBSuccessed.connect(playlistWorker.loadPlaylists) musicManageWorker.loadDBSuccessed.connect(self.loadConfig) def onlineMusicManageWorkerConnect(self): onlineMusicManageWorker.downloadOnlineSongCover.connect( coverWorker.downloadOnlineSongCover) onlineMusicManageWorker.downloadOnlineAlbumCover.connect( coverWorker.downloadOnlineAlbumCover) onlineMusicManageWorker.downloadAlbumCover.connect( coverWorker.downloadAlbumCover) pass def menuWorkerConnect(self): # setting menu menuWorker.addSongFile.connect(musicManageWorker.addSongFile) menuWorker.addSongFolder.connect( musicManageWorker.searchOneFolderMusic) # artist menu menuWorker.playArtist.connect(musicManageWorker.playArtist) menuWorker.removeFromDatabaseByArtistName.connect( musicManageWorker.removeFromDatabaseByArtistName) menuWorker.removeFromDriverByArtistName.connect( musicManageWorker.removeFromDriverByArtistName) # album menu menuWorker.playAlbum.connect(musicManageWorker.playAlbum) menuWorker.removeFromDatabaseByAlbumName.connect( musicManageWorker.removeFromDatabaseByAlbumName) menuWorker.removeFromDriverByAlbumName.connect( musicManageWorker.removeFromDriverByAlbumName) # song menu menuWorker.orderByKey.connect(musicManageWorker.orderByKey) menuWorker.openSongFolder.connect(musicManageWorker.openSongFolder) menuWorker.removeFromDatabaseByUrl.connect( musicManageWorker.removeFromDatabaseByUrl) menuWorker.removeFromDriveByUrl.connect( musicManageWorker.removeFromDriveByUrl) # folder menu menuWorker.playFolder.connect(musicManageWorker.playFolder) menuWorker.removeFromDatabaseByFolderName.connect( musicManageWorker.removeFromDatabaseByFolderName) menuWorker.removeFromDriverByFolderName.connect( musicManageWorker.removeFromDriverByFolderName) #playlist menu menuWorker.removeFromPlaylist.connect( playlistWorker.removeFromPlaylist) #playlist navigation menu menuWorker.deletePlaylist.connect(playlistWorker.deletePlaylist) #download menu menuWorker.removeFromDownloadList.connect( downloadSongWorker.delSongObj) #public menu: menuWorker.addSongToPlaylist.connect(playlistWorker.addSongToPlaylist) menuWorker.addSongsToPlaylist.connect( playlistWorker.addSongsToPlaylist) def dbWorkerConnect(self): dbWorker.restoreSongsSuccessed.connect(musicManageWorker.loadDB) def downloadSongWorkerConnect(self): downloadSongWorker.addDownloadSongToDataBase.connect( musicManageWorker.addLocalSongToDataBase) def loadConfig(self): mediaPlayer.setPlaylistByName(configWorker.lastPlaylistName) mediaPlayer.setCurrentIndex(configWorker.lastPlayedIndex) mediaPlayer.volume = configWorker.volume mediaPlayer.playbackMode = configWorker.playbackMode def showMainWindow(self): self.mainWindow.show() self.mainWindow.setRoundMask() self.qApp.setActivationWindow(self.mainWindow) def show(self): self.showMainWindow() def clearCache(self): if isWebengineUsed: self.mainWindow.engine().clearComponentCache() self.mainWindow.engine().collectGarbage() self.mainWindow.engine().trimComponentCache() else: self.mainWindow.engine().collectGarbage() self.mainWindow.engine().trimComponentCache() def close(self): QThreadPool.globalInstance().clear() mediaPlayer.stop() configWorker.save() playlistWorker.savePlaylists()
def initView(self): self.mainWindow = MainWindow()
class DeepinPlayer(QObject): _instance = None def __init__(self): super(DeepinPlayer, self).__init__() self.initApplication() self.initView() self.initControllers() self.initConnect() self.initQMLContext() self.loadConfig() self.loadDB() self.timer = QTimer() self.timer.timeout.connect(self.clearCache) self.timer.start(2000) @classmethod def instance(cls): if cls._instance is None: cls._instance = cls() return cls._instance @property def qApp(self): return QCoreApplication.instance() def initApplication(self): self.qApp.setApplicationName(config.applicationName) self.qApp.setApplicationVersion(config.applicationVersion) self.qApp.setOrganizationName(config.organizationName) def loadDB(self): QTimer.singleShot(500, self.musicManageWorker.restoreDB) def initView(self): self.mainWindow = MainWindow() def initControllers(self): self.utilWorker = UtilWorker() self.dbWorker = DBWorker() self.configWorker = ConfigWorker() self.i18nWorker = I18nWorker() self.coverWorker = CoverWorker() self.downloadSongWorker = DownloadSongWorker() self.windowManageWorker = WindowManageWorker() self.web360ApiWorker = Web360ApiWorker() self.musicManageWorker = MusicManageWorker() self.onlineMusicManageWorker = OnlineMusicManageWorker() self.menuWorker = MenuWorker() self.mediaPlayer = MediaPlayer() self.playlistWorker = PlaylistWorker() self.web360Thread = QThread(self) self.web360ApiWorker.moveToThread(self.web360Thread) self.web360Thread.start() self.playerBinThread = QThread() gPlayer.moveToThread(self.playerBinThread) self.playerBinThread.start() self.dbThread = QThread() self.dbWorker.moveToThread(self.dbThread) self.dbThread.start() def initQMLContext(self): self.mainWindow.setContexts(contexts) # playlists = self.playlistWorker._playlists # for name, playlist in playlists.items(): # self.playlistWorker.registerObj.emit(name, playlist._medias) self.mainWindow.setSource(QUrl('views/Main.qml')) def initConnect(self): self.web360ApiWorkerConnect() self.mediaPlayerConnect() self.playlistWorkerConnect() self.coverWorkerConnect() self.musicManageWorkerConnect() self.onlineMusicManageWorkerConnect() self.menuWorkerConnect() self.dbWorkerConnect() self.qApp.aboutToQuit.connect(self.close) def web360ApiWorkerConnect(self): self.web360ApiWorker.playMediaContent.connect( self.mediaPlayer.playOnlineMedia) self.web360ApiWorker.swicthMediaContent.connect( self.mediaPlayer.swicthOnlineMedia) self.web360ApiWorker.addMediaContent.connect( self.onlineMusicManageWorker.addSong) self.web360ApiWorker.addMediaContents.connect( self.onlineMusicManageWorker.addSongs) self.web360ApiWorker.addMediaContent.connect( self.playlistWorker.addOnlineMediaToTemporary) self.web360ApiWorker.addMediaContents.connect( self.playlistWorker.addOnlineMediasToTemporary) self.web360ApiWorker.addMediaContentToFavorite.connect( self.onlineMusicManageWorker.addSong) self.web360ApiWorker.addMediaContentToFavorite.connect( self.playlistWorker.addOnlineMediaToFavorite) self.web360ApiWorker.removeMediaContentFromFavorite.connect( self.playlistWorker.removeFavoriteMediaContent) self.web360ApiWorker.downloadSongConetent.connect( self.downloadSongWorker.downloadSong) def mediaPlayerConnect(self): self.mediaPlayer.requestMusic.connect( self.web360ApiWorker.switchMediaByUrl) def playlistWorkerConnect(self): self.playlistWorker.currentPlaylistChanged.connect( self.mediaPlayer.setPlaylistByName) def coverWorkerConnect(self): self.coverWorker.updateArtistCover.connect( self.musicManageWorker.updateArtistCover) self.coverWorker.updateAlbumCover.connect( self.musicManageWorker.updateAlbumCover) self.coverWorker.allTaskFinished.connect( self.musicManageWorker.stopUpdate) self.coverWorker.updateOnlineSongCover.connect( self.onlineMusicManageWorker.updateSongCover) self.coverWorker.updateAlbumCover.connect( self.onlineMusicManageWorker.updateSongCover) self.coverWorker.updateArtistCover.connect( self.mediaPlayer.updateArtistCover) self.coverWorker.updateAlbumCover.connect( self.mediaPlayer.updateAlbumCover) self.coverWorker.updateOnlineSongCover.connect( self.mediaPlayer.updateOnlineSongCover) def musicManageWorkerConnect(self): self.musicManageWorker.saveSongToDB.connect(self.dbWorker.addSong) self.musicManageWorker.saveSongsToDB.connect(self.dbWorker.addSongs) self.musicManageWorker.restoreSongsToDB.connect( self.dbWorker.restoreSongs) self.musicManageWorker.addSongToPlaylist.connect( self.playlistWorker.addLocalMediaToTemporary) self.musicManageWorker.addSongsToPlaylist.connect( self.playlistWorker.addLocalMediasToTemporary) self.musicManageWorker.playSongByUrl.connect( self.mediaPlayer.playLocalMedia) self.musicManageWorker.downloadArtistCover.connect( self.coverWorker.downloadArtistCover) self.musicManageWorker.downloadAlbumCover.connect( self.coverWorker.downloadAlbumCover) self.musicManageWorker.loadDBSuccessed.connect( self.playlistWorker.loadPlaylists) def onlineMusicManageWorkerConnect(self): self.onlineMusicManageWorker.downloadOnlineSongCover.connect( self.coverWorker.downloadOnlineSongCover) self.onlineMusicManageWorker.downloadOnlineAlbumCover.connect( self.coverWorker.downloadOnlineAlbumCover) self.onlineMusicManageWorker.downloadAlbumCover.connect( self.coverWorker.downloadAlbumCover) def menuWorkerConnect(self): self.menuWorker.addSongFile.connect(self.musicManageWorker.addSongFile) self.menuWorker.addSongFolder.connect( self.musicManageWorker.searchOneFolderMusic) def dbWorkerConnect(self): self.dbWorker.restoreSongsSuccessed.connect( self.musicManageWorker.loadDB) def loadConfig(self): self.mediaPlayer.setPlaylistByName(self.configWorker.lastPlaylistName) self.mediaPlayer.setCurrentIndex(self.configWorker.lastPlayedIndex) self.mediaPlayer.volume = self.configWorker.volume self.mediaPlayer.playbackMode = self.configWorker.playbackMode def showMainWindow(self): self.mainWindow.show() self.qApp.setActivationWindow(self.mainWindow) def show(self): self.showMainWindow() def clearCache(self): if isWebengineUsed: self.mainWindow.engine().clearComponentCache() self.mainWindow.engine().collectGarbage() self.mainWindow.engine().trimComponentCache() else: self.mainWindow.engine().collectGarbage() self.mainWindow.engine().trimComponentCache() def close(self): QThreadPool.globalInstance().clear() self.mediaPlayer.stop() self.configWorker.save() self.playlistWorker.savePlaylists()
import sys from PySide import QtGui from views import MainWindow if __name__ == '__main__': app = QtGui.QApplication(sys.argv) window = MainWindow() try: sys.exit(app.exec_()) except (RuntimeError, InterruptedError, Exception, IOError): print("some errors occured") pass
cfg = configparser.ConfigParser() cfg.read('effort.ini') ssh_file = cfg['FILES']['Stylesheet'] with open(ssh_file, 'r') as fh: app.setStyleSheet(fh.read()) db = _setup_db(cfg['FILES']['Database']) if not db: sys.exit('Unable to open database.') # noinspection PyCallByClass,PyTypeChecker def _setup_db(dbname): from PyQt5.QtSql import QSqlDatabase db = QSqlDatabase.addDatabase('QSQLITE') db.setDatabaseName(dbname) return db if db.open() else None if __name__ == '__main__': _setup() from views import MainWindow main_window = MainWindow() main_window.show() sys.exit(app.exec_())
import sys import platform from PyQt5.QtWidgets import QApplication from views import MainWindow def detect_os_platform(): return platform.system() os = detect_os_platform() app = QApplication(sys.argv) main_window = MainWindow(platform=os) main_window.show() sys.exit(app.exec_())