def download_status_changed(self, ident, isPaused): """暂停或重启一个任务。""" work = self.allDownloadWorks[ident][0] if isPaused: if work.downloadStatus != Configures.DownloadCompleted: work.pause() else: args = [ work.title, work.album, work.songLink, work.musicPath, work.musicId, work.length, work.lock ] newDownloadWork = DownloadThread(*args) newDownloadWork.setName(ident) newDownloadWork.setDaemon(True) self.allDownloadWorks[ident][0] = newDownloadWork newDownloadWork.start() if not self.timer.isActive(): self.timer.start(self.timeSpan)
def add_a_download_work(self, songLink, musicPath, title, album, musicId, size, lock): """开始一个下载任务。""" if musicPath in self.allDownloadWorks: print('下载任务已存在%s' % musicPath) return downloadWork = DownloadThread(title, album, songLink, musicPath, musicId, size, lock) downloadWork.setDaemon(True) downloadWork.setName(musicPath) downloadListItem = DownloadListItem(musicPath, title, self.timeSpan) downloadListItem.downloadStatusChanged.connect( self.download_status_changed) downloadListItem.killWork.connect(self.kill_a_download_work) self.downloadList.add_item(downloadListItem, 86) self.allDownloadWorks[musicPath] = [downloadWork, downloadListItem] downloadWork.start() if not self.timer.isActive(): self.timer.start(self.timeSpan)