2012-11-06 12:56:30 -08:00
|
|
|
"""
|
|
|
|
A PyQT4 dialog to select specific issue from list
|
|
|
|
"""
|
|
|
|
|
|
|
|
"""
|
2014-03-23 10:30:23 -07:00
|
|
|
Copyright 2012-2014 Anthony Beville
|
2012-11-06 12:56:30 -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
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
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-02 13:54:17 -07:00
|
|
|
import sys
|
2012-11-12 16:12:43 -08:00
|
|
|
import os
|
2013-03-29 23:25:04 -07:00
|
|
|
import re
|
2012-11-02 13:54:17 -07:00
|
|
|
from PyQt4 import QtCore, QtGui, uic
|
|
|
|
|
2012-11-12 16:12:43 -08:00
|
|
|
from PyQt4.QtCore import QUrl, pyqtSignal, QByteArray
|
2012-11-02 13:54:17 -07:00
|
|
|
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
|
|
|
|
|
2012-11-28 12:15:20 -08:00
|
|
|
from comicvinetalker import ComicVineTalker, ComicVineTalkerException
|
2012-11-12 16:12:43 -08:00
|
|
|
from imagefetcher import ImageFetcher
|
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
|
2013-02-04 20:49:44 -08:00
|
|
|
import utils
|
2012-11-02 13:54:17 -07:00
|
|
|
|
2013-03-27 10:57:05 -07:00
|
|
|
class IssueNumberTableWidgetItem(QtGui.QTableWidgetItem):
|
|
|
|
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())
|
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
class IssueSelectionWindow(QtGui.QDialog):
|
|
|
|
|
|
|
|
volume_id = 0
|
|
|
|
|
2012-11-12 16:12:43 -08:00
|
|
|
def __init__(self, parent, settings, series_id, issue_number):
|
2012-11-02 13:54:17 -07:00
|
|
|
super(IssueSelectionWindow, self).__init__(parent)
|
|
|
|
|
2013-02-06 14:03:53 -08:00
|
|
|
uic.loadUi(ComicTaggerSettings.getUIFile('issueselectionwindow.ui' ), self)
|
2013-02-03 21:13:23 -08:00
|
|
|
|
|
|
|
self.coverWidget = CoverImageWidget( self.coverImageContainer, CoverImageWidget.AltCoverMode )
|
|
|
|
gridlayout = QtGui.QGridLayout( self.coverImageContainer )
|
|
|
|
gridlayout.addWidget( self.coverWidget )
|
|
|
|
gridlayout.setContentsMargins(0,0,0,0)
|
2013-02-04 19:51:50 -08:00
|
|
|
|
2013-02-04 20:49:44 -08:00
|
|
|
utils.reduceWidgetFontSize( self.twList )
|
2013-04-12 10:52:23 -07:00
|
|
|
utils.reduceWidgetFontSize( self.teDescription, 1 )
|
2013-02-04 20:49:44 -08:00
|
|
|
|
2013-02-04 19:51:50 -08:00
|
|
|
self.setWindowFlags(self.windowFlags() |
|
|
|
|
QtCore.Qt.WindowSystemMenuHint |
|
|
|
|
QtCore.Qt.WindowMaximizeButtonHint)
|
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
self.series_id = series_id
|
2012-11-12 16:12:43 -08:00
|
|
|
self.settings = settings
|
|
|
|
self.url_fetch_thread = None
|
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
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)
|
|
|
|
|
|
|
|
#now that the list has been sorted, find the initial record, and select it
|
|
|
|
if self.initial_id is None:
|
|
|
|
self.twList.selectRow( 0 )
|
|
|
|
else:
|
|
|
|
for r in range(0, self.twList.rowCount()):
|
|
|
|
issue_id, b = self.twList.item( r, 0 ).data( QtCore.Qt.UserRole ).toInt()
|
|
|
|
if (issue_id == self.initial_id):
|
|
|
|
self.twList.selectRow( r )
|
|
|
|
break
|
2012-11-12 16:12:43 -08:00
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
def performQuery( self ):
|
2012-11-16 14:45:35 -08:00
|
|
|
|
2012-11-12 16:12:43 -08:00
|
|
|
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
|
|
|
|
|
2012-11-28 12:15:20 -08:00
|
|
|
try:
|
2014-06-12 23:26:44 -07:00
|
|
|
comicVine = ComicVineTalker()
|
2012-11-28 12:15:20 -08:00
|
|
|
volume_data = comicVine.fetchVolumeData( self.series_id )
|
2013-03-29 23:25:04 -07:00
|
|
|
self.issue_list = comicVine.fetchIssuesByVolume( self.series_id )
|
2014-06-12 23:26:44 -07:00
|
|
|
except ComicVineTalkerException as e:
|
|
|
|
QtGui.QApplication.restoreOverrideCursor()
|
|
|
|
if e.code == ComicVineTalkerException.RateLimit:
|
|
|
|
QtGui.QMessageBox.critical(self, self.tr("Comic Vine Error"), ComicVineTalker.getRateLimitMessage())
|
|
|
|
else:
|
|
|
|
QtGui.QMessageBox.critical(self, self.tr("Network Issue"), self.tr("Could not connect to ComicVine to list issues!"))
|
2012-11-28 12:15:20 -08:00
|
|
|
return
|
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
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']
|
2013-03-27 10:57:05 -07:00
|
|
|
item = IssueNumberTableWidgetItem(item_text)
|
2013-01-29 18:17:40 -08:00
|
|
|
item.setData( QtCore.Qt.ToolTipRole, item_text )
|
2012-11-02 13:54:17 -07:00
|
|
|
item.setData( QtCore.Qt.UserRole ,record['id'])
|
2013-03-27 10:57:05 -07:00
|
|
|
item.setData(QtCore.Qt.DisplayRole, item_text)
|
2012-11-02 13:54:17 -07:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsSelectable| QtCore.Qt.ItemIsEnabled)
|
|
|
|
self.twList.setItem(row, 0, item)
|
|
|
|
|
2013-04-10 18:57:19 -07:00
|
|
|
item_text = record['cover_date']
|
2013-04-02 07:11:00 -07:00
|
|
|
if item_text is None:
|
|
|
|
item_text = ""
|
2013-04-10 18:57:19 -07:00
|
|
|
#remove the day of "YYYY-MM-DD"
|
|
|
|
parts = item_text.split("-")
|
|
|
|
if len(parts) > 1:
|
|
|
|
item_text = parts[0] + "-" + parts[1]
|
2013-04-02 07:11:00 -07:00
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
item = QtGui.QTableWidgetItem(item_text)
|
2013-01-29 18:17:40 -08:00
|
|
|
item.setData( QtCore.Qt.ToolTipRole, item_text )
|
2012-11-02 13:54:17 -07:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsSelectable| QtCore.Qt.ItemIsEnabled)
|
|
|
|
self.twList.setItem(row, 1, item)
|
2013-04-10 18:57:19 -07:00
|
|
|
|
|
|
|
item_text = record['name']
|
|
|
|
if item_text is None:
|
|
|
|
item_text = ""
|
|
|
|
item = QtGui.QTableWidgetItem(item_text)
|
|
|
|
item.setData( QtCore.Qt.ToolTipRole, item_text )
|
|
|
|
item.setFlags(QtCore.Qt.ItemIsSelectable| QtCore.Qt.ItemIsEnabled)
|
|
|
|
self.twList.setItem(row, 2, item)
|
2012-11-02 13:54:17 -07:00
|
|
|
|
2013-03-27 12:21:20 -07:00
|
|
|
if IssueString(record['issue_number']).asString().lower() == IssueString(self.issue_number).asString().lower():
|
2012-11-02 13:54:17 -07:00
|
|
|
self.initial_id = record['id']
|
|
|
|
|
|
|
|
row += 1
|
|
|
|
|
|
|
|
self.twList.setSortingEnabled(True)
|
|
|
|
self.twList.sortItems( 0 , QtCore.Qt.AscendingOrder )
|
|
|
|
|
2012-11-12 16:12:43 -08:00
|
|
|
QtGui.QApplication.restoreOverrideCursor()
|
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
def cellDoubleClicked( self, r, c ):
|
|
|
|
self.accept()
|
|
|
|
|
|
|
|
def currentItemChanged( self, curr, prev ):
|
|
|
|
|
|
|
|
if curr is None:
|
|
|
|
return
|
|
|
|
if prev is not None and prev.row() == curr.row():
|
|
|
|
return
|
|
|
|
|
|
|
|
self.issue_id, b = self.twList.item( curr.row(), 0 ).data( QtCore.Qt.UserRole ).toInt()
|
|
|
|
|
|
|
|
# list selection was changed, update the the issue cover
|
|
|
|
for record in self.issue_list:
|
2013-02-03 21:13:23 -08:00
|
|
|
if record['id'] == self.issue_id:
|
2012-11-02 13:54:17 -07:00
|
|
|
self.issue_number = record['issue_number']
|
2013-02-03 21:13:23 -08:00
|
|
|
self.coverWidget.setIssueID( int(self.issue_id) )
|
2013-04-11 18:56:24 -07:00
|
|
|
if record['description'] is None:
|
|
|
|
self.teDescription.setText ( "" )
|
|
|
|
else:
|
|
|
|
self.teDescription.setText ( record['description'] )
|
|
|
|
|
2012-11-02 13:54:17 -07:00
|
|
|
break
|
2012-11-12 16:12:43 -08:00
|
|
|
|