Display covers in tabular form in Info dialogs

This commit is contained in:
Rahul Raturi
2016-04-01 20:26:38 +05:30
parent f741d4d02d
commit 7451602f84
2 changed files with 110 additions and 32 deletions

View File

@@ -35,25 +35,32 @@ class InfoDialog(PicardDialog):
PicardDialog.__init__(self, parent)
self.obj = obj
self.ui = Ui_InfoDialog()
self.ui.setupUi(self)
self.display_existing_artwork = False
if isinstance(self, FileInfoDialog):
if obj.metadata.images != obj.orig_metadata.images:
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_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)
def _display_artwork(self, images, col):
row = 0
row_count = self.artwork_table.rowCount()
for image in images:
while row != row_count:
image_type = self.artwork_table.item(row, 0)
if image_type and image_type.text() == image.types_as_string():
break
row+=1
if row == row_count:
continue
data = None
try:
if image.thumbnail:
@@ -67,19 +74,16 @@ class InfoDialog(PicardDialog):
except CoverArtImageIOError:
log.error(traceback.format_exc())
continue
item = QtGui.QListWidgetItem()
item = QtGui.QTableWidgetItem()
item.setData(QtCore.Qt.UserRole, image)
pixmap = QtGui.QPixmap()
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)" %
@@ -88,8 +92,56 @@ class InfoDialog(PicardDialog):
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)
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):
types = []
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 lists
temp = []
i=0
j=0
while i!=len(types) and j!=len(existing_types):
if types[i] > existing_types[j]:
temp.append(existing_types[j])
j+=1
elif types[i] < existing_types[j]:
temp.append(types[i])
i+=1
else:
temp.append(types[i])
i+=1
j+=1
if i==len(types):
temp.extend(existing_types[j:])
else:
temp.extend(types[i:])
types = temp
for row, type in enumerate(types):
self.artwork_table.insertRow(row)
item = QtGui.QTableWidgetItem()
item.setText(type)
item.setTextAlignment(QtCore.Qt.AlignCenter)
self.artwork_table.setItem(row, 0, item)
def arrange_images(self):
self.obj.metadata.images.sort(key=lambda img: img.types_as_string())
if self.display_existing_artwork:
self.obj.orig_metadata.images.sort(key=lambda img: img.types_as_string())
def _display_artwork_tab(self):
self.arrange_images()
self._display_artwork_type()
self._display_artwork(self.obj.metadata.images, 1)
if self.display_existing_artwork:
self._display_artwork(self.obj.orig_metadata.images, 2)
self.artwork_table.itemDoubleClicked.connect(self.show_item)
def tab_hide(self, widget):
tab = self.ui.tabWidget
@@ -97,6 +149,8 @@ class InfoDialog(PicardDialog):
tab.removeTab(index)
def show_item(self, item):
if not item.data:
return
coverartimage = item.data(QtCore.Qt.UserRole)
filename = coverartimage.tempfile_filename
if filename:

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Automatically generated - don't edit.
# Use `python setup.py build_ui` to update it.
@@ -10,10 +9,43 @@ try:
except AttributeError:
_fromUtf8 = lambda s: s
class ArtworkTable(QtGui.QTableWidget):
def __init__(self, display_existing_art):
QtGui.QTableWidget.__init__(self, 0, 2)
h_header = self.horizontalHeader()
v_header = self.verticalHeader()
h_header.setDefaultSectionSize(200)
v_header.setDefaultSectionSize(230)
if display_existing_art:
self.insertColumn(2)
self.setHorizontalHeaderLabels([_("Type"), _("New Cover"),
_("Existing Cover")])
else:
self.setHorizontalHeaderLabels([_("Type"), _("Cover")])
def get_coverart_widget(self, pixmap, text):
coverart_widget = QtGui.QWidget()
image_label = QtGui.QLabel()
text_label = QtGui.QLabel()
layout = QtGui.QVBoxLayout()
image_label.setPixmap(pixmap.scaled(170,170,QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
image_label.setAlignment(QtCore.Qt.AlignCenter)
text_label.setText(text)
text_label.setAlignment(QtCore.Qt.AlignCenter)
text_label.setWordWrap(True)
layout.addWidget(image_label)
layout.addWidget(text_label)
coverart_widget.setLayout(layout)
return coverart_widget
class Ui_InfoDialog(object):
def setupUi(self, InfoDialog):
def setupUi(self, InfoDialog, display_existing_art):
InfoDialog.setObjectName(_fromUtf8("InfoDialog"))
InfoDialog.resize(535, 436)
if display_existing_art:
InfoDialog.resize(665, 436)
else:
InfoDialog.resize(535, 436)
self.verticalLayout = QtGui.QVBoxLayout(InfoDialog)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.tabWidget = QtGui.QTabWidget(InfoDialog)
@@ -45,17 +77,9 @@ class Ui_InfoDialog(object):
self.artwork_tab.setObjectName(_fromUtf8("artwork_tab"))
self.vboxlayout1 = QtGui.QVBoxLayout(self.artwork_tab)
self.vboxlayout1.setObjectName(_fromUtf8("vboxlayout1"))
self.artwork_list = QtGui.QListWidget(self.artwork_tab)
self.artwork_list.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.artwork_list.setIconSize(QtCore.QSize(170, 170))
self.artwork_list.setMovement(QtGui.QListView.Static)
self.artwork_list.setFlow(QtGui.QListView.LeftToRight)
self.artwork_list.setProperty("isWrapping", False)
self.artwork_list.setResizeMode(QtGui.QListView.Fixed)
self.artwork_list.setSpacing(10)
self.artwork_list.setViewMode(QtGui.QListView.IconMode)
self.artwork_list.setObjectName(_fromUtf8("artwork_list"))
self.vboxlayout1.addWidget(self.artwork_list)
self.artwork_table = ArtworkTable(display_existing_art)
self.artwork_table.setObjectName(_fromUtf8("artwork_table"))
self.vboxlayout1.addWidget(self.artwork_table)
self.tabWidget.addTab(self.artwork_tab, _fromUtf8(""))
self.verticalLayout.addWidget(self.tabWidget)
self.buttonBox = QtGui.QDialogButtonBox(InfoDialog)
@@ -66,8 +90,8 @@ class Ui_InfoDialog(object):
self.retranslateUi(InfoDialog)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(InfoDialog)
InfoDialog.setTabOrder(self.tabWidget, self.artwork_list)
InfoDialog.setTabOrder(self.artwork_list, self.buttonBox)
InfoDialog.setTabOrder(self.tabWidget, self.artwork_table)
InfoDialog.setTabOrder(self.artwork_table, self.buttonBox)
def retranslateUi(self, InfoDialog):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.info_tab), _("&Info"))