Skip to content

Commit

Permalink
format code width PyYapf
Browse files Browse the repository at this point in the history
  • Loading branch information
dragondjf committed Nov 2, 2015
1 parent 47c046e commit 24520b2
Show file tree
Hide file tree
Showing 90 changed files with 2,025 additions and 1,956 deletions.
44 changes: 16 additions & 28 deletions src/app/deepinplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# -*- coding: utf-8 -*-

import os
from PyQt5.QtCore import (QCoreApplication, QObject,
QUrl, QThread, QTimer,
from PyQt5.QtCore import (QCoreApplication, QObject, QUrl, QThread, QTimer,
QThreadPool, QPoint)
from PyQt5.QtGui import QScreen, QIcon
from views import MainWindow, LrcWindowManager, QmlDialog
Expand Down Expand Up @@ -71,8 +70,8 @@ def initControllers(self):

def initQMLContext(self):
self.mainWindow.setContexts(contexts)
self.mainWindow.setSource(QUrl.fromLocalFile(
os.path.join(get_parent_dir(__file__, 2), 'views', 'Main.qml')))
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)
Expand All @@ -90,16 +89,12 @@ def initConnect(self):
signalManager.exited.connect(self.qApp.aboutToQuit)
self.qApp.aboutToQuit.connect(self.close)


def playlistWorkerConnect(self):
playlistWorker.currentPlaylistChanged.connect(
mediaPlayer.setPlaylistByName)
playlistWorker.currentPlaylistChanged.connect(mediaPlayer.setPlaylistByName)

def coverWorkerConnect(self):
coverWorker.updateArtistCover.connect(
musicManageWorker.updateArtistCover)
coverWorker.updateAlbumCover.connect(
musicManageWorker.updateAlbumCover)
coverWorker.updateArtistCover.connect(musicManageWorker.updateArtistCover)
coverWorker.updateAlbumCover.connect(musicManageWorker.updateAlbumCover)
coverWorker.updateOnlineSongCover.connect(
onlineMusicManageWorker.updateSongCover)
coverWorker.updateAlbumCover.connect(
Expand All @@ -108,24 +103,19 @@ def coverWorkerConnect(self):
def musicManageWorkerConnect(self):
musicManageWorker.saveSongToDB.connect(dbWorker.addSong)
musicManageWorker.saveSongsToDB.connect(dbWorker.addSongs)
musicManageWorker.restoreSongsToDB.connect(
dbWorker.restoreSongs)
musicManageWorker.restoreSongsToDB.connect(dbWorker.restoreSongs)
musicManageWorker.addSongToPlaylist.connect(
playlistWorker.addLocalMediaToTemporary)
musicManageWorker.addSongsToPlaylist.connect(
playlistWorker.addLocalMediasToTemporary)
musicManageWorker.playSongByUrl.connect(
mediaPlayer.playLocalMedia)
musicManageWorker.playSongByUrl.connect(mediaPlayer.playLocalMedia)

musicManageWorker.downloadArtistCover.connect(
coverWorker.downloadArtistCover)
musicManageWorker.downloadAlbumCover.connect(
coverWorker.downloadAlbumCover)
musicManageWorker.downloadAlbumCover.connect(coverWorker.downloadAlbumCover)

musicManageWorker.loadDBSuccessed.connect(
playlistWorker.loadPlaylists)
musicManageWorker.loadDBSuccessed.connect(
self.loadConfig)
musicManageWorker.loadDBSuccessed.connect(playlistWorker.loadPlaylists)
musicManageWorker.loadDBSuccessed.connect(self.loadConfig)

def onlineMusicManageWorkerConnect(self):
onlineMusicManageWorker.downloadOnlineSongCover.connect(
Expand All @@ -139,8 +129,7 @@ def onlineMusicManageWorkerConnect(self):
def menuWorkerConnect(self):
# setting menu
menuWorker.addSongFile.connect(musicManageWorker.addSongFile)
menuWorker.addSongFolder.connect(
musicManageWorker.searchOneFolderMusic)
menuWorker.addSongFolder.connect(musicManageWorker.searchOneFolderMusic)

# artist menu
menuWorker.playArtist.connect(musicManageWorker.playArtist)
Expand All @@ -159,8 +148,7 @@ def menuWorkerConnect(self):
# song menu

menuWorker.orderByKey.connect(musicManageWorker.orderByKey)
menuWorker.openSongFolder.connect(
musicManageWorker.openSongFolder)
menuWorker.openSongFolder.connect(musicManageWorker.openSongFolder)
menuWorker.removeFromDatabaseByUrl.connect(
musicManageWorker.removeFromDatabaseByUrl)
menuWorker.removeFromDriveByUrl.connect(
Expand All @@ -187,11 +175,11 @@ def menuWorkerConnect(self):
menuWorker.addSongsToPlaylist.connect(playlistWorker.addSongsToPlaylist)

def dbWorkerConnect(self):
dbWorker.restoreSongsSuccessed.connect(
musicManageWorker.loadDB)
dbWorker.restoreSongsSuccessed.connect(musicManageWorker.loadDB)

def downloadSongWorkerConnect(self):
downloadSongWorker.addDownloadSongToDataBase.connect(musicManageWorker.addLocalSongToDataBase)
downloadSongWorker.addDownloadSongToDataBase.connect(
musicManageWorker.addLocalSongToDataBase)

def loadConfig(self):
mediaPlayer.setPlaylistByName(configWorker.lastPlaylistName)
Expand Down
31 changes: 11 additions & 20 deletions src/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
from PyQt5.QtCore import QStandardPaths


parentDir = os.path.dirname

Home = os.path.expanduser('~')
Expand All @@ -20,30 +19,22 @@
SongCoverPath = os.path.join(CoverPath, 'song')
OnlineSongCoverPath = os.path.join(CoverPath, 'onlineSong')
OnlineAlbumCoverPath = os.path.join(CoverPath, 'onlineAlbum')
LevevDBPath = os.path.join(ProjectPath, 'leveldb')
MusicDBFile = os.path.join(ProjectPath, 'music.db')
LevevDBPath = os.path.join(ProjectPath, 'leveldb')
MusicDBFile = os.path.join(ProjectPath, 'music.db')

DownloadSongPath = os.path.join(QStandardPaths.writableLocation(QStandardPaths.MusicLocation), 'download')
LRCPath = os.path.join(QStandardPaths.writableLocation(QStandardPaths.MusicLocation), 'lyrics')
DownloadSongPath = os.path.join(
QStandardPaths.writableLocation(QStandardPaths.MusicLocation), 'download')
LRCPath = os.path.join(
QStandardPaths.writableLocation(QStandardPaths.MusicLocation), 'lyrics')
LogCachePath = os.path.join(Home, '.cache', 'deepin-muisc')
LogPath = os.path.join(LogCachePath, 'main.log')

paths = [
ProjectPath,
MusicManagerPath,
PlaylistPath,
CoverPath,
ArtistCoverPath,
AlbumCoverPath,
SongCoverPath,
OnlineSongCoverPath,
OnlineAlbumCoverPath,
LevevDBPath,
DownloadSongPath,
LRCPath,
LogCachePath
ProjectPath, MusicManagerPath, PlaylistPath, CoverPath, ArtistCoverPath,
AlbumCoverPath, SongCoverPath, OnlineSongCoverPath, OnlineAlbumCoverPath,
LevevDBPath, DownloadSongPath, LRCPath, LogCachePath
]

for path in paths:
if not os.path.exists(path):
os.makedirs(path)
if not os.path.exists(path):
os.makedirs(path)
97 changes: 42 additions & 55 deletions src/controllers/configworker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import os
import sys
import json
Expand All @@ -16,60 +15,48 @@ class ConfigWorker(object):

__metaclass__ = ModelMetaclass

__Fields__ = (
('lastPlaylistName', 'QString', 'temporary'),
('lastPlayedIndex', int, 0),
('playbackMode', int, 4),
('volume', int, 50),
# settings

('isAutoPlay', bool, False),
('isDesktopLrcShow', bool, False),
('isContinueLastPlayProgress', bool, False),
('isCoverBackground', bool, False),
('isFade', bool, False),
('isExitedWhenClosed', int, 0), # 0: minimized 1:exited
('addSongToPlaylistPlayMode', int, 0), # 0: play first; 1:play next ; 2:play last:

('isShortcutEnable', bool, True),
('shortcut_preivous', 'QString', 'Left'),
('shortcut_next', 'QString', 'Right'),
('shortcut_volumnIncrease', 'QString', 'Up'),
('shortcut_volumeDecrease', 'QString', 'Down'),
('shortcut_playPause', 'QString', 'Space'),
('shortcut_simpleFullMode', 'QString', 'F11'),
('shortcut_miniFullMode', 'QString', 'F10'),
('shortcut_hideShowWindow', 'QString', 'F5'),
('shortcut_hideShowDesktopLRC', 'QString', 'F6'),

('desktopLRC_fontType', int, 0),
('fontType', list, ['A', 'B']),

('desktopLRC_fontSize', int, 30),
('desktopLRC_fontSize_minValue', int, 10),
('desktopLRC_fontSize_maxValue', int, 100),

('desktopLRC_fontItalic', int, 0),
('fontItalic', list, ['C', 'D']),

('desktopLRC_lineNumber', int, 1),
('lineNumber', list, ['1', '2']),

('desktopLRC_fontAlignment', int, 0),
('fontAlignment', list, ['F', 'G']),

('desktopLRC_background1', int, 0),
('background1', list, ['green', 'red']),

('desktopLRC_background2', int, 0),
('background2', list, ['yellow', 'gray']),

('desktopLRC_backgroundSize', int, 30),
('desktopLRC_backgroundSize_minValue', int, 10),
('desktopLRC_backgroundSize_maxValue', int, 100),

('DownloadSongPath', 'QString', DownloadSongPath)
)
__Fields__ = (('lastPlaylistName', 'QString', 'temporary'),
('lastPlayedIndex', int, 0),
('playbackMode', int, 4),
('volume', int, 50),
# settings
('isAutoPlay', bool, False),
('isDesktopLrcShow', bool, False),
('isContinueLastPlayProgress', bool, False),
('isCoverBackground', bool, False),
('isFade', bool, False),
('isExitedWhenClosed', int, 0), # 0: minimized 1:exited
('addSongToPlaylistPlayMode', int,
0), # 0: play first; 1:play next ; 2:play last:
('isShortcutEnable', bool, True),
('shortcut_preivous', 'QString', 'Left'),
('shortcut_next', 'QString', 'Right'),
('shortcut_volumnIncrease', 'QString', 'Up'),
('shortcut_volumeDecrease', 'QString', 'Down'),
('shortcut_playPause', 'QString', 'Space'),
('shortcut_simpleFullMode', 'QString', 'F11'),
('shortcut_miniFullMode', 'QString', 'F10'),
('shortcut_hideShowWindow', 'QString', 'F5'),
('shortcut_hideShowDesktopLRC', 'QString', 'F6'),
('desktopLRC_fontType', int, 0),
('fontType', list, ['A', 'B']),
('desktopLRC_fontSize', int, 30),
('desktopLRC_fontSize_minValue', int, 10),
('desktopLRC_fontSize_maxValue', int, 100),
('desktopLRC_fontItalic', int, 0),
('fontItalic', list, ['C', 'D']),
('desktopLRC_lineNumber', int, 1),
('lineNumber', list, ['1', '2']),
('desktopLRC_fontAlignment', int, 0),
('fontAlignment', list, ['F', 'G']),
('desktopLRC_background1', int, 0),
('background1', list, ['green', 'red']),
('desktopLRC_background2', int, 0),
('background2', list, ['yellow', 'gray']),
('desktopLRC_backgroundSize', int, 30),
('desktopLRC_backgroundSize_minValue', int, 10),
('desktopLRC_backgroundSize_maxValue', int, 100),
('DownloadSongPath', 'QString', DownloadSongPath))

__contextName__ = "ConfigWorker"

Expand Down
30 changes: 17 additions & 13 deletions src/controllers/coverworker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import os
import sys
import copy
Expand All @@ -18,7 +17,6 @@


class Cover360Runnable(QRunnable):

def __init__(self, worker, artist, title, url):
super(Cover360Runnable, self).__init__()
self.worker = worker
Expand All @@ -32,13 +30,13 @@ def run(self):
r = requests.get(self.url)
with open(localUrl, "wb") as f:
f.write(r.content)
self.worker.download360SongCoverSuccessed.emit(self.artist, self.title, localUrl)
self.worker.download360SongCoverSuccessed.emit(
self.artist, self.title, localUrl)
except Exception, e:
logger.error(e)


class AlbumCover360Runnable(QRunnable):

def __init__(self, worker, artist, title, url, medias):
super(AlbumCover360Runnable, self).__init__()
self.worker = worker
Expand All @@ -54,7 +52,8 @@ def run(self):
artist = media['singerName']
title = media['songName']
localUrl = CoverWorker.onlineSongCoverPath(artist, title)
self.worker.download360SongCoverSuccessed.emit(artist, title, localUrl)
self.worker.download360SongCoverSuccessed.emit(
artist, title, localUrl)
return
r = requests.get(self.url)
for media in self.medias:
Expand All @@ -63,7 +62,8 @@ def run(self):
localUrl = CoverWorker.onlineSongCoverPath(artist, title)
with open(localUrl, "wb") as f:
f.write(r.content)
self.worker.download360SongCoverSuccessed.emit(self.artist, self.title, localUrl)
self.worker.download360SongCoverSuccessed.emit(
self.artist, self.title, localUrl)
except Exception, e:
logger.error(e)

Expand All @@ -72,7 +72,6 @@ class CoverWorker(QObject):

__contextName__ = "CoverWorker"


downloadArtistCoverSuccessed = pyqtSignal('QString', 'QString')
downloadAlbumCoverSuccessed = pyqtSignal('QString', 'QString', 'QString')
download360SongCoverSuccessed = pyqtSignal('QString', 'QString', 'QString')
Expand All @@ -81,10 +80,14 @@ class CoverWorker(QObject):
updateAlbumCover = pyqtSignal('QString', 'QString', 'QString')
updateOnlineSongCover = pyqtSignal('QString', 'QString', 'QString')

defaultArtistCover = os.path.join(get_parent_dir(__file__, 2), 'skin', 'images','bg1.jpg')
defaultAlbumCover = os.path.join(get_parent_dir(__file__, 2), 'skin', 'images','bg1.jpg')
defaultSongCover = os.path.join(get_parent_dir(__file__, 2), 'skin', 'images','bg1.jpg')
defaultFolderCover = os.path.join(get_parent_dir(__file__, 2), 'skin', 'images','folder-music.svg')
defaultArtistCover = os.path.join(
get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
defaultAlbumCover = os.path.join(
get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
defaultSongCover = os.path.join(
get_parent_dir(__file__, 2), 'skin', 'images', 'bg1.jpg')
defaultFolderCover = os.path.join(
get_parent_dir(__file__, 2), 'skin', 'images', 'folder-music.svg')

albumCoverThreadPool = QThreadPool()

Expand Down Expand Up @@ -117,7 +120,7 @@ def downloadCoverByUrl(self, mediaUrl, coverUrl):
pass

def cacheArtistCover(self, artist, url):
self.artistCovers[artist] = url
self.artistCovers[artist] = url
self.updateArtistCover.emit(artist, url)

def cacheAlbumCover(self, artist, album, url):
Expand Down Expand Up @@ -275,6 +278,7 @@ def isArtistCoverExisted(cls, artist):
def albumCoverPath(cls, artist, album):
filepath = os.path.join(AlbumCoverPath, '%s-%s' % (artist, album))
return filepath

@classmethod
def isAlbumCoverExisted(cls, artist, album):
return os.path.exists(cls.albumCoverPath(artist, album))
Expand All @@ -298,4 +302,4 @@ def isOnlineSongCoverExisted(cls, artist, title):
return os.path.exists(cls.onlineSongCoverPath(artist, title))


coverWorker = CoverWorker()
coverWorker = CoverWorker()
Loading

0 comments on commit 24520b2

Please sign in to comment.