class InfoDialog(QtGui.QDialog): def __init__(self, file, parent=None): QtGui.QDialog.__init__(self, parent) self.file = file self.ui = Ui_InfoDialog() self.ui.setupUi(self) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.setWindowTitle(_("Info") + " - " + file.base_filename) self.load_info() def load_info(self): file = self.file info = [] info.append((_('Filename:'), file.filename)) if '~format' in file.orig_metadata: info.append((_('Format:'), file.orig_metadata['~format'])) try: size = os.path.getsize(encode_filename(file.filename)) if size < 1024: size = '%d B' % size elif size < 1024 * 1024: size = '%0.1f kB' % (size / 1024.0) else: size = '%0.1f MB' % (size / 1024.0 / 1024.0) info.append((_('Size:'), size)) except: pass if file.orig_metadata.length: info.append((_('Length:'), format_time(file.orig_metadata.length))) if '~#bitrate' in file.orig_metadata: info.append( (_('Bitrate:'), '%d kbps' % file.orig_metadata['~#bitrate'])) if '~#sample_rate' in file.orig_metadata: info.append((_('Sample rate:'), '%d Hz' % file.orig_metadata['~#sample_rate'])) if '~#bits_per_sample' in file.orig_metadata: info.append((_('Bits per sample:'), str(file.orig_metadata['~#bits_per_sample']))) if '~#channels' in file.orig_metadata: ch = file.orig_metadata['~#channels'] if ch == 1: ch = _('Mono') elif ch == 2: ch = _('Stereo') else: ch = str(ch) info.append((_('Channels:'), ch)) text = '<br/>'.join(map(lambda i: '<b>%s</b><br/>%s' % i, info)) self.ui.info.setText(text) for mime, data, _fname in file.metadata.images: item = QtGui.QListWidgetItem() pixmap = QtGui.QPixmap() pixmap.loadFromData(data) icon = QtGui.QIcon(pixmap) item.setIcon(icon) self.ui.artwork_list.addItem(item)
class InfoDialog(QtGui.QDialog): def __init__(self, file, parent=None): QtGui.QDialog.__init__(self, parent) self.file = file self.ui = Ui_InfoDialog() self.ui.setupUi(self) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.setWindowTitle(_("Info") + " - " + file.base_filename) self.load_info() def load_info(self): file = self.file info = [] info.append((_('Filename:'), file.filename)) if '~format' in file.orig_metadata: info.append((_('Format:'), file.orig_metadata['~format'])) try: size = os.path.getsize(encode_filename(file.filename)) if size < 1024: size = '%d B' % size elif size < 1024 * 1024: size = '%0.1f kB' % (size / 1024.0) else: size = '%0.1f MB' % (size / 1024.0 / 1024.0) info.append((_('Size:'), size)) except: pass if file.orig_metadata.length: info.append((_('Length:'), format_time(file.orig_metadata.length))) if '~#bitrate' in file.orig_metadata: info.append((_('Bitrate:'), '%s kbps' % file.orig_metadata['~#bitrate'])) if '~#sample_rate' in file.orig_metadata: info.append((_('Sample rate:'), '%s Hz' % file.orig_metadata['~#sample_rate'])) if '~#bits_per_sample' in file.orig_metadata: info.append((_('Bits per sample:'), str(file.orig_metadata['~#bits_per_sample']))) if '~#channels' in file.orig_metadata: ch = file.orig_metadata['~#channels'] if ch == 1: ch = _('Mono') elif ch == 2: ch = _('Stereo') else: ch = str(ch) info.append((_('Channels:'), ch)) text = '<br/>'.join(map(lambda i: '<b>%s</b><br/>%s' % i, info)) self.ui.info.setText(text) for image in file.metadata.images: data = image["data"] item = QtGui.QListWidgetItem() pixmap = QtGui.QPixmap() pixmap.loadFromData(data) icon = QtGui.QIcon(pixmap) item.setIcon(icon) self.ui.artwork_list.addItem(item)
class InfoDialog(PicardDialog): def __init__(self, obj, parent=None): PicardDialog.__init__(self, parent) self.obj = obj self.ui = Ui_InfoDialog() self.ui.setupUi(self) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.setWindowTitle(_("Info")) self._display_tabs() def _display_tabs(self): self._display_info_tab() self._display_artwork_tab() def _display_artwork_tab(self): tab = self.ui.artwork_tab images = self.obj.metadata.images if not images: self.tab_hide(tab) return for image in images: try: data = image.data except (OSError, IOError) as e: log.error(traceback.format_exc()) continue size = len(data) item = QtGui.QListWidgetItem() pixmap = QtGui.QPixmap() pixmap.loadFromData(data) icon = QtGui.QIcon(pixmap) item.setIcon(icon) s = "%s (%s)\n%d x %d" % (bytes2human.decimal(size), bytes2human.binary(size), pixmap.width(), pixmap.height()) item.setText(s) self.ui.artwork_list.addItem(item) def tab_hide(self, widget): tab = self.ui.tabWidget index = tab.indexOf(widget) tab.removeTab(index)
class InfoDialog(QtGui.QDialog): def __init__(self, obj, parent=None): QtGui.QDialog.__init__(self, parent) self.obj = obj self.ui = Ui_InfoDialog() self.ui.setupUi(self) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.setWindowTitle(_("Info")) self._display_tabs() def _display_tabs(self): self._display_info_tab() self._display_artwork_tab() def _display_artwork_tab(self): tab = self.ui.artwork_tab images = self.obj.metadata.images if not images: self.tab_hide(tab) return for image in images: data = image["data"] size = len(data) item = QtGui.QListWidgetItem() pixmap = QtGui.QPixmap() pixmap.loadFromData(data) icon = QtGui.QIcon(pixmap) item.setIcon(icon) s = "%s (%s)\n%d x %d" % (bytes2human.decimal(size), bytes2human.binary(size), pixmap.width(), pixmap.height()) item.setText(s) self.ui.artwork_list.addItem(item) def tab_hide(self, widget): tab = self.ui.tabWidget index = tab.indexOf(widget) tab.removeTab(index)
class InfoDialog(QtGui.QDialog): def __init__(self, obj, parent=None): QtGui.QDialog.__init__(self, parent) self.obj = obj self.ui = Ui_InfoDialog() self.ui.setupUi(self) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.setWindowTitle(_("Info")) self._display_tabs() def _display_tabs(self): self._display_info_tab() self._display_artwork_tab() def _display_artwork_tab(self): tab = self.ui.artwork_tab images = self.obj.metadata.images if not images: self.tab_hide(tab) return for image in images: data = image["data"] item = QtGui.QListWidgetItem() pixmap = QtGui.QPixmap() pixmap.loadFromData(data) icon = QtGui.QIcon(pixmap) item.setIcon(icon) self.ui.artwork_list.addItem(item) def tab_hide(self, widget): tab = self.ui.tabWidget index = tab.indexOf(widget) tab.removeTab(index)
class InfoDialog(PicardDialog): autorestore = False def __init__(self, obj, parent=None): super().__init__(parent) self.obj = obj self.images = [] self.existing_images = [] self.ui = Ui_InfoDialog() self.display_existing_artwork = False if (isinstance(obj, File) and isinstance(obj.parent, Track) or isinstance(obj, Track) or (isinstance(obj, Album) and obj.get_num_total_files() > 0)): # Display existing artwork only if selected object is track object # or linked to a track object or it's an album with files if (getattr(obj, 'orig_metadata', None) is not None and obj.orig_metadata.images and obj.orig_metadata.images != obj.metadata.images): self.display_existing_artwork = True self.existing_images = obj.orig_metadata.images if obj.metadata.images: self.images = obj.metadata.images if not self.images and self.existing_images: self.images = self.existing_images self.existing_images = [] self.display_existing_artwork = False self.ui.setupUi(self) self.ui.buttonBox.addButton(StandardButton(StandardButton.CLOSE), QtWidgets.QDialogButtonBox.AcceptRole) self.ui.buttonBox.accepted.connect(self.accept) # Add the ArtworkTable to the ui self.ui.artwork_table = ArtworkTable(self.display_existing_artwork) self.ui.artwork_table.setObjectName("artwork_table") self.ui.vboxlayout1.addWidget(self.ui.artwork_table) self.setTabOrder(self.ui.tabWidget, self.ui.artwork_table) self.setTabOrder(self.ui.artwork_table, self.ui.buttonBox) self.setWindowTitle(_("Info")) self.artwork_table = self.ui.artwork_table self._display_tabs() self.restore_geometry() def _display_tabs(self): self._display_info_tab() self._display_artwork_tab() def _display_artwork(self, images, col): """Draw artwork in corresponding cell if image type matches type in Type column. Arguments: images -- The images to be drawn. col -- Column in which images are to be drawn. Can be _new_cover_col or _existing_cover_col. """ row = 0 row_count = self.artwork_table.rowCount() for image in images: while row != row_count: image_type = self.artwork_table.item( row, self.artwork_table._type_col) if image_type and image_type.data( QtCore.Qt.UserRole) == image.types_as_string(): break row += 1 if row == row_count: continue data = None try: if image.thumbnail: try: data = image.thumbnail.data except CoverArtImageIOError as e: log.warning(e) else: data = image.data except CoverArtImageIOError: log.error(traceback.format_exc()) continue item = QtWidgets.QTableWidgetItem() item.setData(QtCore.Qt.UserRole, image) pixmap = QtGui.QPixmap() if data is not None: pixmap.loadFromData(data) item.setToolTip( _("Double-click to open in external viewer\n" "Temporary file: %s\n" "Source: %s") % (image.tempfile_filename, image.source)) infos = [] if image.comment: infos.append(image.comment) infos.append("%s (%s)" % (bytes2human.decimal( image.datalength), bytes2human.binary(image.datalength))) if image.width and image.height: infos.append("%d x %d" % (image.width, image.height)) infos.append(image.mimetype) img_wgt = ArtworkCoverWidget(pixmap=pixmap, text="\n".join(infos)) self.artwork_table.setCellWidget(row, col, img_wgt) self.artwork_table.setItem(row, col, item) row += 1 def _display_artwork_type(self): """Display image type in Type column. If both existing covers and new covers are to be displayed, take union of both cover types list. """ types = [image.types_as_string() for image in self.images] if self.display_existing_artwork: existing_types = [ image.types_as_string() for image in self.existing_images ] # Merge both types and existing types list in sorted order. types = union_sorted_lists(types, existing_types) pixmap_arrow = QtGui.QPixmap(":/images/arrow.png") else: pixmap_arrow = None for row, artwork_type in enumerate(types): self.artwork_table.insertRow(row) item = QtWidgets.QTableWidgetItem() item.setData(QtCore.Qt.UserRole, artwork_type) type_wgt = ArtworkCoverWidget(pixmap=pixmap_arrow, text=artwork_type) self.artwork_table.setCellWidget(row, self.artwork_table._type_col, type_wgt) self.artwork_table.setItem(row, self.artwork_table._type_col, item) def _display_artwork_tab(self): if not self.images: self.tab_hide(self.ui.artwork_tab) self._display_artwork_type() self._display_artwork(self.images, self.artwork_table._new_cover_col) if self.existing_images: self._display_artwork(self.existing_images, self.artwork_table._existing_cover_col) self.artwork_table.itemDoubleClicked.connect(self.show_item) self.artwork_table.verticalHeader().resizeSections( QtWidgets.QHeaderView.ResizeToContents) def tab_hide(self, widget): tab = self.ui.tabWidget index = tab.indexOf(widget) tab.removeTab(index) def show_item(self, item): data = item.data(QtCore.Qt.UserRole) # Check if this function isn't triggered by cell in Type column if isinstance(data, str): return filename = data.tempfile_filename if filename: url = QtCore.QUrl.fromLocalFile(filename) QtGui.QDesktopServices.openUrl(url)
class InfoDialog(PicardDialog): def __init__(self, obj, parent=None): PicardDialog.__init__(self, parent) self.obj = obj self.ui = Ui_InfoDialog() self.ui.setupUi(self) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.setWindowTitle(_("Info")) self._display_tabs() def _display_tabs(self): self._display_info_tab() self._display_artwork_tab() def _display_artwork_tab(self): tab = self.ui.artwork_tab images = self.obj.metadata.images if not images: self.tab_hide(tab) return self.ui.artwork_list.itemDoubleClicked.connect(self.show_item) for image in images: data = None try: if image.thumbnail: try: data = image.thumbnail.data except CoverArtImageIOError as e: log.warning(unicode(e)) pass else: data = image.data except CoverArtImageIOError: log.error(traceback.format_exc()) continue item = QtGui.QListWidgetItem() item.setData(QtCore.Qt.UserRole, image) if data is not None: pixmap = QtGui.QPixmap() pixmap.loadFromData(data) icon = QtGui.QIcon(pixmap) item.setIcon(icon) item.setToolTip( _("Double-click to open in external viewer\n" "Temporary file: %s\n" "Source: %s") % (image.tempfile_filename, image.source)) infos = [] infos.append(image.types_as_string()) if image.comment: infos.append(image.comment) infos.append(u"%s (%s)" % (bytes2human.decimal(image.datalength), bytes2human.binary(image.datalength))) if image.width and image.height: infos.append(u"%d x %d" % (image.width, image.height)) infos.append(image.mimetype) item.setText(u"\n".join(infos)) self.ui.artwork_list.addItem(item) def tab_hide(self, widget): tab = self.ui.tabWidget index = tab.indexOf(widget) tab.removeTab(index) def show_item(self, item): coverartimage = item.data(QtCore.Qt.UserRole) filename = coverartimage.tempfile_filename if filename: webbrowser2.open("file://" + filename)
class InfoDialog(PicardDialog): defaultsize = QtCore.QSize(665, 436) autorestore = False def __init__(self, obj, parent=None): super().__init__(parent) self.obj = obj self.images = [] self.existing_images = [] self.ui = Ui_InfoDialog() self.display_existing_artwork = False if (isinstance(obj, File) and isinstance(obj.parent, Track) or isinstance(obj, Track) or (isinstance(obj, Album) and obj.get_num_total_files() > 0)): # Display existing artwork only if selected object is track object # or linked to a track object or it's an album with files if (getattr(obj, 'orig_metadata', None) is not None and obj.orig_metadata.images and obj.orig_metadata.images != obj.metadata.images): self.display_existing_artwork = True self.existing_images = obj.orig_metadata.images if obj.metadata.images: self.images = obj.metadata.images if not self.images and self.existing_images: self.images = self.existing_images self.existing_images = [] self.display_existing_artwork = False self.ui.setupUi(self) self.ui.buttonBox.addButton( StandardButton(StandardButton.CLOSE), QtWidgets.QDialogButtonBox.AcceptRole) self.ui.buttonBox.accepted.connect(self.accept) # Add the ArtworkTable to the ui self.ui.artwork_table = ArtworkTable(self.display_existing_artwork) self.ui.artwork_table.setObjectName("artwork_table") self.ui.vboxlayout1.addWidget(self.ui.artwork_table) self.setTabOrder(self.ui.tabWidget, self.ui.artwork_table) self.setTabOrder(self.ui.artwork_table, self.ui.buttonBox) self.setWindowTitle(_("Info")) self.artwork_table = self.ui.artwork_table self._display_tabs() self.restore_geometry() def _display_tabs(self): self._display_info_tab() self._display_artwork_tab() def _display_artwork(self, images, col): """Draw artwork in corresponding cell if image type matches type in Type column. Arguments: images -- The images to be drawn. col -- Column in which images are to be drawn. Can be _new_cover_col or _existing_cover_col. """ row = 0 row_count = self.artwork_table.rowCount() for image in images: while row != row_count: image_type = self.artwork_table.item(row, self.artwork_table._type_col) if image_type and image_type.data(QtCore.Qt.UserRole) == image.types_as_string(): break row += 1 if row == row_count: continue data = None try: if image.thumbnail: try: data = image.thumbnail.data except CoverArtImageIOError as e: log.warning(e) else: data = image.data except CoverArtImageIOError: log.error(traceback.format_exc()) continue item = QtWidgets.QTableWidgetItem() item.setData(QtCore.Qt.UserRole, image) pixmap = QtGui.QPixmap() if data is not None: pixmap.loadFromData(data) item.setToolTip( _("Double-click to open in external viewer\n" "Temporary file: %s\n" "Source: %s") % (image.tempfile_filename, image.source)) infos = [] if image.comment: infos.append(image.comment) infos.append("%s (%s)" % (bytes2human.decimal(image.datalength), bytes2human.binary(image.datalength))) if image.width and image.height: infos.append("%d x %d" % (image.width, image.height)) infos.append(image.mimetype) img_wgt = ArtworkCoverWidget(pixmap=pixmap, text="\n".join(infos)) self.artwork_table.setCellWidget(row, col, img_wgt) self.artwork_table.setItem(row, col, item) row += 1 def _display_artwork_type(self): """Display image type in Type column. If both existing covers and new covers are to be displayed, take union of both cover types list. """ types = [image.types_as_string() for image in self.images] if self.display_existing_artwork: existing_types = [image.types_as_string() for image in self.existing_images] # Merge both types and existing types list in sorted order. types = union_sorted_lists(types, existing_types) pixmap_arrow = QtGui.QPixmap(":/images/arrow.png") else: pixmap_arrow = None for row, artwork_type in enumerate(types): self.artwork_table.insertRow(row) item = QtWidgets.QTableWidgetItem() item.setData(QtCore.Qt.UserRole, artwork_type) type_wgt = ArtworkCoverWidget(pixmap=pixmap_arrow, text=artwork_type) self.artwork_table.setCellWidget(row, self.artwork_table._type_col, type_wgt) self.artwork_table.setItem(row, self.artwork_table._type_col, item) def _display_artwork_tab(self): if not self.images: self.tab_hide(self.ui.artwork_tab) self._display_artwork_type() self._display_artwork(self.images, self.artwork_table._new_cover_col) if self.existing_images: self._display_artwork(self.existing_images, self.artwork_table._existing_cover_col) self.artwork_table.itemDoubleClicked.connect(self.show_item) self.artwork_table.verticalHeader().resizeSections(QtWidgets.QHeaderView.ResizeToContents) def tab_hide(self, widget): tab = self.ui.tabWidget index = tab.indexOf(widget) tab.removeTab(index) def show_item(self, item): data = item.data(QtCore.Qt.UserRole) # Check if this function isn't triggered by cell in Type column if isinstance(data, str): return filename = data.tempfile_filename if filename: webbrowser2.open("file://" + filename)
class InfoDialog(PicardDialog): def __init__(self, obj, parent=None): PicardDialog.__init__(self, parent) self.obj = obj self.ui = Ui_InfoDialog() self.display_existing_artwork = False if isinstance(obj, File) and isinstance(obj.parent, Track) or \ isinstance(obj, Track): #Display existing artwork only if selected object is track object #or linked to a track object self.display_existing_artwork = True self.ui.setupUi(self, self.display_existing_artwork) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.setWindowTitle(_("Info")) self.artwork_table = self.ui.artwork_table self._display_tabs() def _display_tabs(self): self._display_info_tab() self._display_artwork_tab() def _display_artwork(self, images, col): """Draw artwork in corresponding cell if image type matches type in Type column. Arguments: images -- The images to be drawn. col -- Column in which images are to be drawn. Can be _new_cover_col or _existing_cover_col. """ row = 0 row_count = self.artwork_table.rowCount() for image in images: while row != row_count: image_type = self.artwork_table.item(row, self.artwork_table._type_col) if image_type and image_type.data(QtCore.Qt.UserRole) == image.types_as_string(): break row += 1 if row == row_count: continue data = None try: if image.thumbnail: try: data = image.thumbnail.data except CoverArtImageIOError as e: log.warning(unicode(e)) pass else: data = image.data except CoverArtImageIOError: log.error(traceback.format_exc()) continue item = QtGui.QTableWidgetItem() item.setData(QtCore.Qt.UserRole, image) pixmap = QtGui.QPixmap() if data is not None: pixmap.loadFromData(data) item.setToolTip( _("Double-click to open in external viewer\n" "Temporary file: %s\n" "Source: %s") % (image.tempfile_filename, image.source)) infos = [] if image.comment: infos.append(image.comment) infos.append(u"%s (%s)" % (bytes2human.decimal(image.datalength), bytes2human.binary(image.datalength))) if image.width and image.height: infos.append(u"%d x %d" % (image.width, image.height)) infos.append(image.mimetype) img_wgt = self.artwork_table.get_coverart_widget(pixmap, "\n".join(infos)) self.artwork_table.setCellWidget(row, col, img_wgt) self.artwork_table.setItem(row, col, item) row += 1 def _display_artwork_type(self): """Display image type in Type column. If both existing covers and new covers are to be displayed, take union of both cover types list. """ types = [image.types_as_string() for image in self.obj.metadata.images] if self.display_existing_artwork: existing_types = [image.types_as_string() for image in self.obj.orig_metadata.images] #Merge both types and existing types list in sorted order. types = union_sorted_lists(types, existing_types) for row, type in enumerate(types): self.artwork_table.insertRow(row) type_wgt = self.artwork_table.get_type_widget(type) item = QtGui.QTableWidgetItem() item.setData(QtCore.Qt.UserRole, type) self.artwork_table.setCellWidget(row, self.artwork_table._type_col, type_wgt) self.artwork_table.setItem(row, self.artwork_table._type_col, item) def arrange_images(self): def get_image_type(image): return image.types_as_string() self.obj.metadata.images.sort(key=get_image_type) if self.display_existing_artwork: self.obj.orig_metadata.images.sort(key=get_image_type) def _display_artwork_tab(self): if not self.obj.metadata.images: self.tab_hide(self.ui.artwork_tab) self.arrange_images() self._display_artwork_type() self._display_artwork(self.obj.metadata.images, self.artwork_table._new_cover_col) if self.display_existing_artwork: self._display_artwork(self.obj.orig_metadata.images, self.artwork_table._existing_cover_col) self.artwork_table.itemDoubleClicked.connect(self.show_item) def tab_hide(self, widget): tab = self.ui.tabWidget index = tab.indexOf(widget) tab.removeTab(index) def show_item(self, item): data = item.data(QtCore.Qt.UserRole) #Check if this function isn't triggered by cell in Type column if isinstance(data, unicode): return filename = data.tempfile_filename if filename: webbrowser2.open("file://" + filename)