diff --git a/picard/ui/infodialog.py b/picard/ui/infodialog.py index df1f9b941..20fa7eb8e 100644 --- a/picard/ui/infodialog.py +++ b/picard/ui/infodialog.py @@ -93,25 +93,56 @@ class ArtworkCoverWidget(QtWidgets.QWidget): class ArtworkTable(QtWidgets.QTableWidget): - def __init__(self, display_existing_art): - super().__init__(0, 2) - self.display_existing_art = display_existing_art + H_SIZE = 200 + V_SIZE = 230 + + NUM_ROWS = 0 + NUM_COLS = 2 + + _columns = {} + _labels = () + + def __init__(self, parent=None): + super().__init__(self.NUM_ROWS, self.NUM_COLS, parent=parent) + h_header = self.horizontalHeader() + h_header.setDefaultSectionSize(self.H_SIZE) + h_header.setStretchLastSection(True) + v_header = self.verticalHeader() - h_header.setDefaultSectionSize(200) - v_header.setDefaultSectionSize(230) - if self.display_existing_art: - self._existing_cover_col = 0 - self._type_col = 1 - self._new_cover_col = 2 - self.insertColumn(2) - self.setHorizontalHeaderLabels([_("Existing Cover"), _("Type"), - _("New Cover")]) - else: - self._type_col = 0 - self._new_cover_col = 1 - self.setHorizontalHeaderLabels([_("Type"), _("Cover")]) - self.setColumnWidth(self._type_col, 140) + v_header.setDefaultSectionSize(self.V_SIZE) + + self.setHorizontalHeaderLabels(self._labels) + + def get_column_index(self, name): + return self._columns[name] + + +class ArtworkTableSimple(ArtworkTable): + TYPE_COLUMN_SIZE = 140 + + _columns = { + 'type': 0, + 'new_cover': 1, + } + + _labels = (_("Type"), _("Cover"),) + + def __init__(self, parent=None): + super().__init__(parent=parent) + self.setColumnWidth(self.get_column_index('type'), self.TYPE_COLUMN_SIZE) + + +class ArtworkTableExisting(ArtworkTable): + NUM_COLS = 3 + + _columns = { + 'existing_cover': 0, + 'type': 1, + 'new_cover': 2, + } + + _labels = (_("Existing Cover"), _("Type"), _("New Cover"),) class InfoDialog(PicardDialog): @@ -122,7 +153,7 @@ class InfoDialog(PicardDialog): self.images = [] self.existing_images = [] self.ui = Ui_InfoDialog() - self.display_existing_artwork = False + artworktable_class = ArtworkTableSimple if (isinstance(obj, File) and isinstance(obj.parent, Track) @@ -133,7 +164,7 @@ class InfoDialog(PicardDialog): 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 + artworktable_class = ArtworkTableExisting self.existing_images = obj.orig_metadata.images if obj.metadata.images: @@ -141,14 +172,14 @@ class InfoDialog(PicardDialog): if not self.images and self.existing_images: self.images = self.existing_images self.existing_images = [] - self.display_existing_artwork = False + artworktable_class = ArtworkTableSimple self.ui.setupUi(self) self.ui.buttonBox.addButton( StandardButton(StandardButton.CLOSE), QtWidgets.QDialogButtonBox.ButtonRole.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 = artworktable_class(parent=self) self.ui.artwork_table.setObjectName('artwork_table') self.ui.artwork_tab.layout().addWidget(self.ui.artwork_table) self.setTabOrder(self.ui.tabWidget, self.ui.artwork_table) @@ -176,19 +207,21 @@ class InfoDialog(PicardDialog): lambda s: '%s' % (color, text_as_html(s)), errors)) self.ui.error.setText(text + '