def load_new_amz_files(self, amz_files): parser = AmzParser() for f in amz_files: parser.parse(f) objects = parser.get_parsed_objects() self.tree_model = TreeModel(objects) self.treeView.setModel(self.tree_model) self.setup_treeview()
class MainWindow(QMainWindow, _ui.Ui_MainWindow): updateInfo = pyqtSignal() resetInfo = pyqtSignal() def __init__(self, amz_files, parent=None): QMainWindow.__init__(self, parent) self.setupUi(self) loadFileIcon = QIcon.fromTheme('document-new', QIcon(QPixmap(load_icon_path))) downloadIcon = QIcon.fromTheme('go-down', QIcon(QPixmap(download_icon_path))) settingsIcon = QIcon.fromTheme('preferences-other', QIcon(QPixmap(settings_icon_path))) showIcon = QIcon.fromTheme('emblem-downloads', QIcon(QPixmap(show_icon_path))) exitIcon = QIcon.fromTheme('window-close', QIcon(QPixmap(exit_icon_path))) self.pythonPixmap = QPixmap(python_icon_path) self.pymazon_text = self.nowDownloadingLabel.text() self.actionLoadFiles.setIcon(loadFileIcon) self.actionDownload.setIcon(downloadIcon) self.actionSettings.setIcon(settingsIcon) self.actionShowDownloads.setIcon(showIcon) self.actionQuit.setIcon(exitIcon) self.albumArtLabel.setPixmap(self.pythonPixmap) self.settingsDialog = SettingsDialog(self) self.tree_model = None self.pbardelegate = ProgressBarDelegate() self.treeView.setItemDelegateForColumn(1, self.pbardelegate) self.downloader = None self.current_album = None self.old_albums = [] self.updateInfo.connect(self.update_album_info) self.resetInfo.connect(self.reset_displaybar_info) if amz_files: self.load_new_amz_files(amz_files) @pyqtSlot() def on_actionLoadFiles_triggered(self): self.new_amz() @pyqtSlot() def on_actionSettings_triggered(self): self.settingsDialog.launch() @pyqtSlot() def on_actionDownload_triggered(self): self.download_tracks() @pyqtSlot() def on_actionShowDownloads_triggered(self): webbrowser.open(settings.save_dir) @pyqtSlot() def on_actionQuit_triggered(self): self.close() @pyqtSlot() def on_actionAbout_triggered(self): webbrowser.open('http://code.google.com/p/pymazon') def closeEvent(self, evt): if self.downloader: self.downloader.kill() evt.accept() def new_amz(self): caption = 'Choose AMZ File' filefilter = "Amazon MP3 Download (*.amz)" files = [ str(f) for f in QFileDialog.getOpenFileNames( self, caption, '', filefilter) ] if files: self.load_new_amz_files(files) def load_new_amz_files(self, amz_files): parser = AmzParser() for f in amz_files: parser.parse(f) objects = parser.get_parsed_objects() self.tree_model = TreeModel(objects) self.treeView.setModel(self.tree_model) self.setup_treeview() def setup_treeview(self): self.treeView.expandAll() self.treeView.resizeColumnToContents(0) width = self.treeView.columnWidth(0) self.treeView.setColumnWidth(1, 100) self.treeView.setColumnWidth(0, width + 50) def download_tracks(self): if not self.tree_model: return save_dir = settings.save_dir if not os.access(save_dir, os.W_OK): msg = 'No write access to save directory. ' msg += 'Choose a new directory with write privileges.' QMessageBox.information(self, 'No Access!', msg) return self.downloader = Downloader(self.tree_model, self.update_cb, self.finished_cb) self.actionDownload.setEnabled(False) self.actionSettings.setEnabled(False) self.actionLoadFiles.setEnabled(False) self.downloader.start() def update_cb(self, node): if isinstance(node.elem.obj, Album): if not node.elem.obj is self.current_album: if node.elem.obj not in self.old_albums: self.old_albums.append(node.elem.obj) self.current_album = node.elem.obj self.updateInfo.emit() else: pass self.tree_model.update_node(node) def finished_cb(self): self.downloader = None self.resetInfo.emit() self.actionDownload.setEnabled(True) self.actionSettings.setEnabled(True) self.actionLoadFiles.setEnabled(True) def reset_displaybar_info(self): self.current_album = None self.old_albums = [] self.nowDownloadingLabel.setText(self.pymazon_text) self.albumArtLabel.setPixmap(self.pythonPixmap) def update_album_info(self): self.update_album_art() self.update_downloading_text() def update_album_art(self): img = self.current_album.image if img != "": pm = QPixmap() pm.loadFromData(img, None, Qt.AutoColor) self.albumArtLabel.setPixmap(pm) def update_downloading_text(self): name = self.current_album.artist title = self.current_album.title txt = 'Now dowloading <b>%s</b> by <b>%s</b>' % (title, name) self.nowDownloadingLabel.setText(txt)
class MainWindow(QMainWindow, _ui.Ui_MainWindow): updateInfo = pyqtSignal() resetInfo = pyqtSignal() def __init__(self, amz_files, parent=None): QMainWindow.__init__(self, parent) self.setupUi(self) loadFileIcon = QIcon.fromTheme('document-new', QIcon(QPixmap(load_icon_path))) downloadIcon = QIcon.fromTheme('go-down', QIcon(QPixmap(download_icon_path))) settingsIcon = QIcon.fromTheme('preferences-other', QIcon(QPixmap(settings_icon_path))) showIcon = QIcon.fromTheme('emblem-downloads', QIcon(QPixmap(show_icon_path))) exitIcon = QIcon.fromTheme('window-close', QIcon(QPixmap(exit_icon_path))) self.pythonPixmap = QPixmap(python_icon_path) self.pymazon_text = self.nowDownloadingLabel.text() self.actionLoadFiles.setIcon(loadFileIcon) self.actionDownload.setIcon(downloadIcon) self.actionSettings.setIcon(settingsIcon) self.actionShowDownloads.setIcon(showIcon) self.actionQuit.setIcon(exitIcon) self.albumArtLabel.setPixmap(self.pythonPixmap) self.settingsDialog = SettingsDialog(self) self.tree_model = None self.pbardelegate = ProgressBarDelegate() self.treeView.setItemDelegateForColumn(1, self.pbardelegate) self.downloader = None self.current_album = None self.old_albums = [] self.updateInfo.connect(self.update_album_info) self.resetInfo.connect(self.reset_displaybar_info) if amz_files: self.load_new_amz_files(amz_files) @pyqtSlot() def on_actionLoadFiles_triggered(self): self.new_amz() @pyqtSlot() def on_actionSettings_triggered(self): self.settingsDialog.launch() @pyqtSlot() def on_actionDownload_triggered(self): self.download_tracks() @pyqtSlot() def on_actionShowDownloads_triggered(self): webbrowser.open(settings.save_dir) @pyqtSlot() def on_actionQuit_triggered(self): self.close() @pyqtSlot() def on_actionAbout_triggered(self): webbrowser.open('http://code.google.com/p/pymazon') def closeEvent(self, evt): if self.downloader: self.downloader.kill() evt.accept() def new_amz(self): caption = 'Choose AMZ File' filefilter = "Amazon MP3 Download (*.amz)" files = [str(f) for f in QFileDialog.getOpenFileNames(self, caption, '', filefilter)] if files: self.load_new_amz_files(files) def load_new_amz_files(self, amz_files): parser = AmzParser() for f in amz_files: parser.parse(f) objects = parser.get_parsed_objects() self.tree_model = TreeModel(objects) self.treeView.setModel(self.tree_model) self.setup_treeview() def setup_treeview(self): self.treeView.expandAll() self.treeView.resizeColumnToContents(0) width = self.treeView.columnWidth(0) self.treeView.setColumnWidth(1, 100) self.treeView.setColumnWidth(0, width + 50) def download_tracks(self): if not self.tree_model: return save_dir = settings.save_dir if not os.access(save_dir, os.W_OK): msg = 'No write access to save directory. ' msg += 'Choose a new directory with write privileges.' QMessageBox.information(self, 'No Access!', msg) return self.downloader = Downloader(self.tree_model, self.update_cb, self.finished_cb) self.actionDownload.setEnabled(False) self.actionSettings.setEnabled(False) self.actionLoadFiles.setEnabled(False) self.downloader.start() def update_cb(self, node): if isinstance(node.elem.obj, Album): if not node.elem.obj is self.current_album: if node.elem.obj not in self.old_albums: self.old_albums.append(node.elem.obj) self.current_album = node.elem.obj self.updateInfo.emit() else: pass self.tree_model.update_node(node) def finished_cb(self): self.downloader = None self.resetInfo.emit() self.actionDownload.setEnabled(True) self.actionSettings.setEnabled(True) self.actionLoadFiles.setEnabled(True) def reset_displaybar_info(self): self.current_album = None self.old_albums = [] self.nowDownloadingLabel.setText(self.pymazon_text) self.albumArtLabel.setPixmap(self.pythonPixmap) def update_album_info(self): self.update_album_art() self.update_downloading_text() def update_album_art(self): img = self.current_album.image pm = QPixmap() pm.loadFromData(img, None, Qt.AutoColor) self.albumArtLabel.setPixmap(pm) def update_downloading_text(self): name = self.current_album.artist title = self.current_album.title txt = 'Now dowloading <b>%s</b> by <b>%s</b>' % (title, name) self.nowDownloadingLabel.setText(txt)