2015-02-21 18:30:32 -08:00
|
|
|
"""A PyQT4 dialog to select specific issue from list"""
|
2012-11-06 12:56:30 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Copyright 2012-2014 Anthony Beville
|
2012-11-06 12:56:30 -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-06 12:56:30 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-06 12:56:30 -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-06 12:56:30 -08:00
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets, uic
|
2020-07-06 16:11:15 -07:00
|
|
|
|
|
|
|
from comictaggerlib.ui.qtutils import reduceWidgetFontSize
|
2018-09-19 13:05:39 -07:00
|
|
|
|
|
|
|
from .comicvinetalker import ComicVineTalker, ComicVineTalkerException
|
|
|
|
from .coverimagewidget import CoverImageWidget
|
2020-07-06 16:11:15 -07:00
|
|
|
from .issuestring import IssueString
|
|
|
|
from .settings import ComicTaggerSettings
|
2012-11-02 13:54:17 -07:00
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
|
|
|
|
class IssueNumberTableWidgetItem(QtWidgets.QTableWidgetItem):
|
2015-02-12 14:57:46 -08:00
|
|
|
def __lt__(self, other):
|
2018-09-19 13:05:39 -07:00
|
|
|
selfStr = self.data(QtCore.Qt.DisplayRole)
|
|
|
|
otherStr = other.data(QtCore.Qt.DisplayRole)
|
2020-07-06 16:11:15 -07:00
|
|
|
return IssueString(selfStr).asFloat() < IssueString(otherStr).asFloat()
|
2013-03-27 10:57:05 -07:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
class IssueSelectionWindow(QtWidgets.QDialog):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
volume_id = 0
|
|
|
|
|
|
|
|
def __init__(self, parent, settings, series_id, issue_number):
|
|
|
|
super(IssueSelectionWindow, self).__init__(parent)
|
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
uic.loadUi(ComicTaggerSettings.getUIFile("issueselectionwindow.ui"), self)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
self.coverWidget = CoverImageWidget(self.coverImageContainer, CoverImageWidget.AltCoverMode)
|
2018-09-19 13:05:39 -07:00
|
|
|
gridlayout = QtWidgets.QGridLayout(self.coverImageContainer)
|
2015-02-13 15:08:07 -08:00
|
|
|
gridlayout.addWidget(self.coverWidget)
|
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:19:38 -08:00
|
|
|
reduceWidgetFontSize(self.twList)
|
|
|
|
reduceWidgetFontSize(self.teDescription, 1)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
self.series_id = series_id
|
2015-02-12 14:57:46 -08:00
|
|
|
self.settings = settings
|
|
|
|
self.url_fetch_thread = None
|
|
|
|
|
|
|
|
if issue_number is None or issue_number == "":
|
|
|
|
self.issue_number = 1
|
|
|
|
else:
|
|
|
|
self.issue_number = issue_number
|
|
|
|
|
|
|
|
self.initial_id = None
|
|
|
|
self.performQuery()
|
|
|
|
|
|
|
|
self.twList.resizeColumnsToContents()
|
|
|
|
self.twList.currentItemChanged.connect(self.currentItemChanged)
|
|
|
|
self.twList.cellDoubleClicked.connect(self.cellDoubleClicked)
|
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
# now that the list has been sorted, find the initial record, and
|
|
|
|
# select it
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.initial_id is None:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.twList.selectRow(0)
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
|
|
|
for r in range(0, self.twList.rowCount()):
|
2018-09-19 13:05:39 -07:00
|
|
|
issue_id = self.twList.item(r, 0).data(QtCore.Qt.UserRole)
|
2020-07-06 16:11:15 -07:00
|
|
|
if issue_id == self.initial_id:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.twList.selectRow(r)
|
2015-02-12 14:57:46 -08:00
|
|
|
break
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def performQuery(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
try:
|
|
|
|
comicVine = ComicVineTalker()
|
2015-02-13 15:08:07 -08:00
|
|
|
volume_data = comicVine.fetchVolumeData(self.series_id)
|
|
|
|
self.issue_list = comicVine.fetchIssuesByVolume(self.series_id)
|
2015-02-12 14:57:46 -08:00
|
|
|
except ComicVineTalkerException as e:
|
2018-09-19 13:05:39 -07:00
|
|
|
QtWidgets.QApplication.restoreOverrideCursor()
|
2015-02-12 14:57:46 -08:00
|
|
|
if e.code == ComicVineTalkerException.RateLimit:
|
2020-07-06 16:11:15 -07:00
|
|
|
QtWidgets.QMessageBox.critical(self, self.tr("Comic Vine Error"), ComicVineTalker.getRateLimitMessage())
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2020-07-06 16:11:15 -07:00
|
|
|
QtWidgets.QMessageBox.critical(self, self.tr("Network Issue"), self.tr("Could not connect to Comic Vine to list issues!"))
|
2015-02-12 14:57:46 -08:00
|
|
|
return
|
|
|
|
|
|
|
|
while self.twList.rowCount() > 0:
|
|
|
|
self.twList.removeRow(0)
|
|
|
|
|
|
|
|
self.twList.setSortingEnabled(False)
|
|
|
|
|
|
|
|
row = 0
|
|
|
|
for record in self.issue_list:
|
|
|
|
self.twList.insertRow(row)
|
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
item_text = record["issue_number"]
|
2015-02-12 14:57:46 -08:00
|
|
|
item = IssueNumberTableWidgetItem(item_text)
|
2015-02-13 15:08:07 -08:00
|
|
|
item.setData(QtCore.Qt.ToolTipRole, item_text)
|
2020-07-06 16:11:15 -07:00
|
|
|
item.setData(QtCore.Qt.UserRole, record["id"])
|
2015-02-12 14:57:46 -08:00
|
|
|
item.setData(QtCore.Qt.DisplayRole, 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, 0, item)
|
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
item_text = record["cover_date"]
|
2015-02-12 14:57:46 -08:00
|
|
|
if item_text is None:
|
|
|
|
item_text = ""
|
2015-02-15 02:44:00 -08:00
|
|
|
# remove the day of "YYYY-MM-DD"
|
2015-02-12 14:57:46 -08:00
|
|
|
parts = item_text.split("-")
|
|
|
|
if len(parts) > 1:
|
|
|
|
item_text = parts[0] + "-" + parts[1]
|
|
|
|
|
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, 1, item)
|
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
item_text = record["name"]
|
2015-02-12 14:57:46 -08:00
|
|
|
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, 2, item)
|
|
|
|
|
2020-07-06 16:11:15 -07:00
|
|
|
if IssueString(record["issue_number"]).asString().lower() == IssueString(self.issue_number).asString().lower():
|
|
|
|
self.initial_id = record["id"]
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
row += 1
|
|
|
|
|
|
|
|
self.twList.setSortingEnabled(True)
|
2015-02-15 02:44:00 -08:00
|
|
|
self.twList.sortItems(0, QtCore.Qt.AscendingOrder)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
QtWidgets.QApplication.restoreOverrideCursor()
|
2015-02-12 14:57:46 -08:00
|
|
|
|
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
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
self.issue_id = self.twList.item(curr.row(), 0).data(QtCore.Qt.UserRole)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
# list selection was changed, update the the issue cover
|
|
|
|
for record in self.issue_list:
|
2020-07-06 16:11:15 -07:00
|
|
|
if record["id"] == self.issue_id:
|
|
|
|
self.issue_number = record["issue_number"]
|
2015-02-13 15:08:07 -08:00
|
|
|
self.coverWidget.setIssueID(int(self.issue_id))
|
2020-07-06 16:11:15 -07:00
|
|
|
if record["description"] is None:
|
2015-02-15 02:44:00 -08:00
|
|
|
self.teDescription.setText("")
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2020-07-06 16:11:15 -07:00
|
|
|
self.teDescription.setText(record["description"])
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
break
|