2015-02-21 18:30:32 -08:00
|
|
|
"""A PyQT4 dialog to select from automated issue matches"""
|
2012-11-17 16:32:01 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Copyright 2012-2014 Anthony Beville
|
2012-11-17 16:32:01 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2012-11-17 16:32:01 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-17 16:32:01 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2012-11-17 16:32:01 -08:00
|
|
|
|
|
|
|
import os
|
2015-02-21 18:30:32 -08:00
|
|
|
#import sys
|
2012-11-17 16:32:01 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets, uic
|
|
|
|
#from PyQt5.QtCore import QUrl, pyqtSignal, QByteArray
|
2012-11-17 16:32:01 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
from .settings import ComicTaggerSettings
|
|
|
|
from .coverimagewidget import CoverImageWidget
|
2015-02-21 18:30:32 -08:00
|
|
|
from comictaggerlib.ui.qtutils import reduceWidgetFontSize
|
|
|
|
#from imagefetcher import ImageFetcher
|
|
|
|
#from comicarchive import MetaDataStyle
|
|
|
|
#from comicvinetalker import ComicVineTalker
|
|
|
|
#import utils
|
2012-11-17 16:32:01 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
class MatchSelectionWindow(QtWidgets.QDialog):
|
2013-02-04 11:54:04 -08:00
|
|
|
|
2015-02-12 14:57:46 -08:00
|
|
|
volume_id = 0
|
|
|
|
|
|
|
|
def __init__(self, parent, matches, comic_archive):
|
|
|
|
super(MatchSelectionWindow, self).__init__(parent)
|
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
uic.loadUi(
|
|
|
|
ComicTaggerSettings.getUIFile('matchselectionwindow.ui'), self)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
self.altCoverWidget = CoverImageWidget(
|
|
|
|
self.altCoverContainer, CoverImageWidget.AltCoverMode)
|
2018-09-19 13:05:39 -07:00
|
|
|
gridlayout = QtWidgets.QGridLayout(self.altCoverContainer)
|
2015-02-13 15:08:07 -08:00
|
|
|
gridlayout.addWidget(self.altCoverWidget)
|
2015-02-15 02:44:00 -08:00
|
|
|
gridlayout.setContentsMargins(0, 0, 0, 0)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
self.archiveCoverWidget = CoverImageWidget(
|
|
|
|
self.archiveCoverContainer, CoverImageWidget.ArchiveMode)
|
2018-09-19 13:05:39 -07:00
|
|
|
gridlayout = QtWidgets.QGridLayout(self.archiveCoverContainer)
|
2015-02-13 15:08:07 -08:00
|
|
|
gridlayout.addWidget(self.archiveCoverWidget)
|
2015-02-15 02:44:00 -08:00
|
|
|
gridlayout.setContentsMargins(0, 0, 0, 0)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-16 07:18:00 -08:00
|
|
|
reduceWidgetFontSize(self.twList)
|
|
|
|
reduceWidgetFontSize(self.teDescription, 1)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.setWindowFlags(self.windowFlags() |
|
2015-02-15 02:44:00 -08:00
|
|
|
QtCore.Qt.WindowSystemMenuHint |
|
|
|
|
QtCore.Qt.WindowMaximizeButtonHint)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.matches = matches
|
|
|
|
self.comic_archive = comic_archive
|
|
|
|
|
|
|
|
self.twList.currentItemChanged.connect(self.currentItemChanged)
|
|
|
|
self.twList.cellDoubleClicked.connect(self.cellDoubleClicked)
|
|
|
|
|
|
|
|
self.updateData()
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def updateData(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.setCoverImage()
|
|
|
|
self.populateTable()
|
|
|
|
self.twList.resizeColumnsToContents()
|
2015-02-13 15:08:07 -08:00
|
|
|
self.twList.selectRow(0)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
path = self.comic_archive.path
|
2018-09-19 13:05:39 -07:00
|
|
|
self.setWindowTitle("Select correct match: {0}".format(
|
2015-02-15 02:44:00 -08:00
|
|
|
os.path.split(path)[1]))
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def populateTable(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
while self.twList.rowCount() > 0:
|
|
|
|
self.twList.removeRow(0)
|
|
|
|
|
|
|
|
self.twList.setSortingEnabled(False)
|
|
|
|
|
|
|
|
row = 0
|
|
|
|
for match in self.matches:
|
|
|
|
self.twList.insertRow(row)
|
|
|
|
|
|
|
|
item_text = match['series']
|
2018-09-19 13:05:39 -07:00
|
|
|
item = QtWidgets.QTableWidgetItem(item_text)
|
2015-02-13 15:08:07 -08:00
|
|
|
item.setData(QtCore.Qt.ToolTipRole, item_text)
|
|
|
|
item.setData(QtCore.Qt.UserRole, (match,))
|
2015-02-15 02:44:00 -08:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2015-02-12 14:57:46 -08:00
|
|
|
self.twList.setItem(row, 0, item)
|
|
|
|
|
|
|
|
if match['publisher'] is not None:
|
2018-09-19 13:05:39 -07:00
|
|
|
item_text = "{0}".format(match['publisher'])
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2018-09-19 13:05:39 -07:00
|
|
|
item_text = "Unknown"
|
|
|
|
item = QtWidgets.QTableWidgetItem(item_text)
|
2015-02-13 15:08:07 -08:00
|
|
|
item.setData(QtCore.Qt.ToolTipRole, item_text)
|
2015-02-15 02:44:00 -08:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2015-02-12 14:57:46 -08:00
|
|
|
self.twList.setItem(row, 1, item)
|
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
month_str = ""
|
|
|
|
year_str = "????"
|
2015-02-12 14:57:46 -08:00
|
|
|
if match['month'] is not None:
|
2018-09-19 13:05:39 -07:00
|
|
|
month_str = "-{0:02d}".format(int(match['month']))
|
2015-02-12 14:57:46 -08:00
|
|
|
if match['year'] is not None:
|
2018-09-19 13:05:39 -07:00
|
|
|
year_str = "{0}".format(match['year'])
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
item_text = year_str + month_str
|
2018-09-19 13:05:39 -07:00
|
|
|
item = QtWidgets.QTableWidgetItem(item_text)
|
2015-02-13 15:08:07 -08:00
|
|
|
item.setData(QtCore.Qt.ToolTipRole, item_text)
|
2015-02-15 02:44:00 -08:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2015-02-12 14:57:46 -08:00
|
|
|
self.twList.setItem(row, 2, item)
|
|
|
|
|
|
|
|
item_text = match['issue_title']
|
|
|
|
if item_text is None:
|
|
|
|
item_text = ""
|
2018-09-19 13:05:39 -07:00
|
|
|
item = QtWidgets.QTableWidgetItem(item_text)
|
2015-02-13 15:08:07 -08:00
|
|
|
item.setData(QtCore.Qt.ToolTipRole, item_text)
|
2015-02-15 02:44:00 -08:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2015-02-12 14:57:46 -08:00
|
|
|
self.twList.setItem(row, 3, item)
|
|
|
|
|
|
|
|
row += 1
|
|
|
|
|
|
|
|
self.twList.resizeColumnsToContents()
|
|
|
|
self.twList.setSortingEnabled(True)
|
2015-02-15 02:44:00 -08:00
|
|
|
self.twList.sortItems(2, QtCore.Qt.AscendingOrder)
|
2015-02-12 14:57:46 -08:00
|
|
|
self.twList.selectRow(0)
|
|
|
|
self.twList.resizeColumnsToContents()
|
|
|
|
self.twList.horizontalHeader().setStretchLastSection(True)
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def cellDoubleClicked(self, r, c):
|
2015-02-12 14:57:46 -08:00
|
|
|
self.accept()
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def currentItemChanged(self, curr, prev):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if curr is None:
|
|
|
|
return
|
|
|
|
if prev is not None and prev.row() == curr.row():
|
2015-02-15 02:44:00 -08:00
|
|
|
return
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
self.altCoverWidget.setIssueID(self.currentMatch()['issue_id'])
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.currentMatch()['description'] is None:
|
2015-02-15 02:44:00 -08:00
|
|
|
self.teDescription.setText("")
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2015-02-15 02:44:00 -08:00
|
|
|
self.teDescription.setText(self.currentMatch()['description'])
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def setCoverImage(self):
|
|
|
|
self.archiveCoverWidget.setArchive(self.comic_archive)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def currentMatch(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
row = self.twList.currentRow()
|
2015-02-15 02:44:00 -08:00
|
|
|
match = self.twList.item(row, 0).data(
|
2018-09-19 13:05:39 -07:00
|
|
|
QtCore.Qt.UserRole)[0]
|
2015-02-12 14:57:46 -08:00
|
|
|
return match
|