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
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
#import sys
|
|
|
|
#import os
|
|
|
|
#import re
|
2012-11-02 13:54:17 -07:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
from PyQt4 import QtCore, QtGui, uic
|
2015-02-21 18:30:32 -08:00
|
|
|
#from PyQt4.QtCore import QUrl, pyqtSignal, QByteArray
|
|
|
|
#from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
|
2012-11-02 13:54:17 -07:00
|
|
|
|
2012-11-28 12:15:20 -08:00
|
|
|
from comicvinetalker import ComicVineTalker, ComicVineTalkerException
|
2012-11-13 13:25:15 -08:00
|
|
|
from settings import ComicTaggerSettings
|
2012-12-03 18:27:31 -08:00
|
|
|
from issuestring import IssueString
|
2013-02-03 21:13:23 -08:00
|
|
|
from coverimagewidget import CoverImageWidget
|
2015-02-21 18:30:32 -08:00
|
|
|
from comictaggerlib.ui.qtutils import reduceWidgetFontSize
|
|
|
|
#from imagefetcher import ImageFetcher
|
|
|
|
#import utils
|
2012-11-02 13:54:17 -07:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2013-03-27 10:57:05 -07:00
|
|
|
class IssueNumberTableWidgetItem(QtGui.QTableWidgetItem):
|
2015-02-15 02:44:00 -08:00
|
|
|
|
2015-02-12 14:57:46 -08:00
|
|
|
def __lt__(self, other):
|
|
|
|
selfStr = self.data(QtCore.Qt.DisplayRole).toString()
|
|
|
|
otherStr = other.data(QtCore.Qt.DisplayRole).toString()
|
|
|
|
return (IssueString(selfStr).asFloat() <
|
|
|
|
IssueString(otherStr).asFloat())
|
2013-03-27 10:57:05 -07:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
class IssueSelectionWindow(QtGui.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)
|
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
uic.loadUi(
|
|
|
|
ComicTaggerSettings.getUIFile('issueselectionwindow.ui'), self)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
self.coverWidget = CoverImageWidget(
|
|
|
|
self.coverImageContainer, CoverImageWidget.AltCoverMode)
|
2015-02-13 15:08:07 -08:00
|
|
|
gridlayout = QtGui.QGridLayout(self.coverImageContainer)
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
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()):
|
2015-02-15 02:44:00 -08:00
|
|
|
issue_id, b = self.twList.item(
|
|
|
|
r, 0).data(QtCore.Qt.UserRole).toInt()
|
2015-02-12 14:57:46 -08: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
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
QtGui.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:
|
|
|
|
QtGui.QApplication.restoreOverrideCursor()
|
|
|
|
if e.code == ComicVineTalkerException.RateLimit:
|
2015-02-15 02:44:00 -08:00
|
|
|
QtGui.QMessageBox.critical(
|
2015-02-15 03:55:04 -08:00
|
|
|
self,
|
|
|
|
self.tr("Comic Vine Error"),
|
|
|
|
ComicVineTalker.getRateLimitMessage())
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2015-02-15 03:55:04 -08:00
|
|
|
QtGui.QMessageBox.critical(
|
|
|
|
self,
|
|
|
|
self.tr("Network Issue"),
|
2015-02-21 18:30:32 -08:00
|
|
|
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)
|
|
|
|
|
|
|
|
item_text = record['issue_number']
|
|
|
|
item = IssueNumberTableWidgetItem(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.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)
|
|
|
|
|
|
|
|
item_text = record['cover_date']
|
|
|
|
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]
|
|
|
|
|
|
|
|
item = QtGui.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)
|
|
|
|
|
|
|
|
item_text = record['name']
|
|
|
|
if item_text is None:
|
|
|
|
item_text = ""
|
|
|
|
item = QtGui.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)
|
|
|
|
|
2015-02-15 03:55:04 -08:00
|
|
|
if IssueString(
|
|
|
|
record['issue_number']).asString().lower() == IssueString(
|
2015-02-15 03:44:09 -08:00
|
|
|
self.issue_number).asString().lower():
|
2015-02-12 14:57:46 -08:00
|
|
|
self.initial_id = record['id']
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
QtGui.QApplication.restoreOverrideCursor()
|
|
|
|
|
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-15 02:44:00 -08:00
|
|
|
self.issue_id, b = self.twList.item(
|
|
|
|
curr.row(), 0).data(QtCore.Qt.UserRole).toInt()
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
# list selection was changed, update the the issue cover
|
|
|
|
for record in self.issue_list:
|
|
|
|
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))
|
2015-02-12 14:57:46 -08: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:
|
2015-02-15 02:44:00 -08:00
|
|
|
self.teDescription.setText(record['description'])
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
break
|