def __init__(self, parent, metadata): super(PageBrowserWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('pagebrowser.ui' ), self) self.pageWidget = CoverImageWidget( self.pageContainer, CoverImageWidget.ArchiveMode ) gridlayout = QtGui.QGridLayout( self.pageContainer ) gridlayout.addWidget( self.pageWidget ) gridlayout.setContentsMargins(0,0,0,0) self.pageWidget.showControls = False self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.comic_archive = None self.page_count = 0 self.current_page_num = 0 self.metadata = metadata self.buttonBox.button(QtGui.QDialogButtonBox.Close).setDefault(True) if platform.system() == "Darwin": self.btnPrev.setText("<<") self.btnNext.setText(">>") else: self.btnPrev.setIcon(QtGui.QIcon( ComicTaggerSettings.getGraphic('left.png' ))) self.btnNext.setIcon(QtGui.QIcon( ComicTaggerSettings.getGraphic('right.png'))) self.btnNext.clicked.connect( self.nextPage ) self.btnPrev.clicked.connect( self.prevPage ) self.show() self.btnNext.setEnabled( False ) self.btnPrev.setEnabled( False )
def __init__(self, parent): super(AutoTagProgressWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('autotagprogresswindow.ui'), self) self.archiveCoverWidget = CoverImageWidget(self.archiveCoverContainer, CoverImageWidget.DataMode, False) gridlayout = QtGui.QGridLayout(self.archiveCoverContainer) gridlayout.addWidget(self.archiveCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.testCoverWidget = CoverImageWidget(self.testCoverContainer, CoverImageWidget.DataMode, False) gridlayout = QtGui.QGridLayout(self.testCoverContainer) gridlayout.addWidget(self.testCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.isdone = False self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) utils.reduceWidgetFontSize(self.textEdit)
def __init__(self, parent, matches, comic_archive): super(MatchSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('matchselectionwindow.ui' ), self) self.altCoverWidget = CoverImageWidget( self.altCoverContainer, CoverImageWidget.AltCoverMode ) gridlayout = QtGui.QGridLayout( self.altCoverContainer ) gridlayout.addWidget( self.altCoverWidget ) gridlayout.setContentsMargins(0,0,0,0) self.archiveCoverWidget = CoverImageWidget( self.archiveCoverContainer, CoverImageWidget.ArchiveMode ) gridlayout = QtGui.QGridLayout( self.archiveCoverContainer ) gridlayout.addWidget( self.archiveCoverWidget ) gridlayout.setContentsMargins(0,0,0,0) utils.reduceWidgetFontSize( self.twList ) utils.reduceWidgetFontSize( self.teDescription, 1 ) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.matches = matches self.comic_archive = comic_archive self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.updateData()
def __init__(self, parent, matches, comic_archive): super(MatchSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('matchselectionwindow.ui'), self) self.altCoverWidget = CoverImageWidget(self.altCoverContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.altCoverContainer) gridlayout.addWidget(self.altCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.archiveCoverWidget = CoverImageWidget( self.archiveCoverContainer, CoverImageWidget.ArchiveMode) gridlayout = QtGui.QGridLayout(self.archiveCoverContainer) gridlayout.addWidget(self.archiveCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) utils.reduceWidgetFontSize(self.twList) utils.reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.matches = matches self.comic_archive = comic_archive self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.updateData()
def __init__(self, parent, series_name, issue_number, year, issue_count, cover_index_list, comic_archive, settings, autoselect=False): super(VolumeSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('volumeselectionwindow.ui'), self) self.imageWidget = CoverImageWidget(self.imageContainer, CoverImageWidget.URLMode) gridlayout = QtGui.QGridLayout(self.imageContainer) gridlayout.addWidget(self.imageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.teDetails, 1) reduceWidgetFontSize(self.twList) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.settings = settings self.series_name = series_name self.issue_number = issue_number self.year = year self.issue_count = issue_count self.volume_id = 0 self.comic_archive = comic_archive self.immediate_autoselect = autoselect self.cover_index_list = cover_index_list self.cv_search_results = None self.twList.resizeColumnsToContents() self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.btnRequery.clicked.connect(self.requery) self.btnIssues.clicked.connect(self.showIssues) self.btnAutoSelect.clicked.connect(self.autoSelect) self.updateButtons() self.performQuery() self.twList.selectRow(0)
def __init__(self, parent ): super(PageListEditor, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('pagelisteditor.ui' ), self) self.pageWidget = CoverImageWidget( self.pageContainer, CoverImageWidget.ArchiveMode ) gridlayout = QGridLayout( self.pageContainer ) gridlayout.addWidget( self.pageWidget ) gridlayout.setContentsMargins(0,0,0,0) self.pageWidget.showControls = False self.resetPage() # Add the entries to the manga combobox self.comboBox.addItem( "", "" ) self.comboBox.addItem( self.pageTypeNames[ PageType.FrontCover], PageType.FrontCover ) self.comboBox.addItem( self.pageTypeNames[ PageType.InnerCover], PageType.InnerCover ) self.comboBox.addItem( self.pageTypeNames[ PageType.Advertisment], PageType.Advertisment ) self.comboBox.addItem( self.pageTypeNames[ PageType.Roundup], PageType.Roundup ) self.comboBox.addItem( self.pageTypeNames[ PageType.Story], PageType.Story ) self.comboBox.addItem( self.pageTypeNames[ PageType.Editorial], PageType.Editorial ) self.comboBox.addItem( self.pageTypeNames[ PageType.Letters], PageType.Letters ) self.comboBox.addItem( self.pageTypeNames[ PageType.Preview], PageType.Preview ) self.comboBox.addItem( self.pageTypeNames[ PageType.BackCover], PageType.BackCover ) self.comboBox.addItem( self.pageTypeNames[ PageType.Other], PageType.Other ) self.comboBox.addItem( self.pageTypeNames[ PageType.Deleted], PageType.Deleted ) self.listWidget.itemSelectionChanged.connect( self.changePage ) itemMoveEvents(self.listWidget).connect(self.itemMoveEvent) self.comboBox.activated.connect( self.changePageType ) self.btnUp.clicked.connect( self.moveCurrentUp ) self.btnDown.clicked.connect( self.moveCurrentDown ) self.pre_move_row = -1 self.first_front_page = None
def __init__(self, parent): super(PageListEditor, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('pagelisteditor.ui'), self) self.pageWidget = CoverImageWidget(self.pageContainer, CoverImageWidget.ArchiveMode) gridlayout = QGridLayout(self.pageContainer) gridlayout.addWidget(self.pageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.pageWidget.showControls = False self.resetPage() # Add the entries to the manga combobox self.comboBox.addItem("", "") self.comboBox.addItem(self.pageTypeNames[PageType.FrontCover], PageType.FrontCover) self.comboBox.addItem(self.pageTypeNames[PageType.InnerCover], PageType.InnerCover) self.comboBox.addItem(self.pageTypeNames[PageType.Advertisement], PageType.Advertisement) self.comboBox.addItem(self.pageTypeNames[PageType.Roundup], PageType.Roundup) self.comboBox.addItem(self.pageTypeNames[PageType.Story], PageType.Story) self.comboBox.addItem(self.pageTypeNames[PageType.Editorial], PageType.Editorial) self.comboBox.addItem(self.pageTypeNames[PageType.Letters], PageType.Letters) self.comboBox.addItem(self.pageTypeNames[PageType.Preview], PageType.Preview) self.comboBox.addItem(self.pageTypeNames[PageType.BackCover], PageType.BackCover) self.comboBox.addItem(self.pageTypeNames[PageType.Other], PageType.Other) self.comboBox.addItem(self.pageTypeNames[PageType.Deleted], PageType.Deleted) self.listWidget.itemSelectionChanged.connect(self.changePage) itemMoveEvents(self.listWidget).connect(self.itemMoveEvent) self.comboBox.activated.connect(self.changePageType) self.btnUp.clicked.connect(self.moveCurrentUp) self.btnDown.clicked.connect(self.moveCurrentDown) self.pre_move_row = -1 self.first_front_page = None
def __init__(self, parent, settings, series_id, issue_number): super(IssueSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('issueselectionwindow.ui'), self) self.coverWidget = CoverImageWidget(self.coverImageContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.coverImageContainer) gridlayout.addWidget(self.coverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.twList) reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.series_id = series_id 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) # 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
def __init__(self, parent, match_set_list, style, fetch_func): super(AutoTagMatchWindow, self).__init__(parent) uic.loadUi( ComicTaggerSettings.getUIFile('matchselectionwindow.ui'), self) self.altCoverWidget = CoverImageWidget( self.altCoverContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.altCoverContainer) gridlayout.addWidget(self.altCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.archiveCoverWidget = CoverImageWidget( self.archiveCoverContainer, CoverImageWidget.ArchiveMode) gridlayout = QtGui.QGridLayout(self.archiveCoverContainer) gridlayout.addWidget(self.archiveCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.twList) reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.skipButton = QtGui.QPushButton(self.tr("Skip to Next")) self.buttonBox.addButton( self.skipButton, QtGui.QDialogButtonBox.ActionRole) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText( "Accept and Write Tags") self.match_set_list = match_set_list self.style = style self.fetch_func = fetch_func self.current_match_set_idx = 0 self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.skipButton.clicked.connect(self.skipToNext) self.updateData()
def __init__(self, parent, match_set_list, style, fetch_func): super(AutoTagMatchWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('matchselectionwindow.ui'), self) self.altCoverWidget = CoverImageWidget(self.altCoverContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.altCoverContainer) gridlayout.addWidget(self.altCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.archiveCoverWidget = CoverImageWidget( self.archiveCoverContainer, CoverImageWidget.ArchiveMode) gridlayout = QtGui.QGridLayout(self.archiveCoverContainer) gridlayout.addWidget(self.archiveCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.twList) reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.skipButton = QtGui.QPushButton(self.tr("Skip to Next")) self.buttonBox.addButton(self.skipButton, QtGui.QDialogButtonBox.ActionRole) self.buttonBox.button( QtGui.QDialogButtonBox.Ok).setText("Accept and Write Tags") self.match_set_list = match_set_list self.style = style self.fetch_func = fetch_func self.current_match_set_idx = 0 self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.skipButton.clicked.connect(self.skipToNext) self.updateData()
def __init__(self, parent, settings, series_id, issue_number): super(IssueSelectionWindow, self).__init__(parent) uic.loadUi( ComicTaggerSettings.getUIFile('issueselectionwindow.ui'), self) self.coverWidget = CoverImageWidget( self.coverImageContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.coverImageContainer) gridlayout.addWidget(self.coverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.twList) reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.series_id = series_id 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) # 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
def __init__(self, parent, series_name, issue_number, year, issue_count, cover_index_list, comic_archive, settings, autoselect=False): super(VolumeSelectionWindow, self).__init__(parent) uic.loadUi( ComicTaggerSettings.getUIFile('volumeselectionwindow.ui'), self) self.imageWidget = CoverImageWidget( self.imageContainer, CoverImageWidget.URLMode) gridlayout = QtGui.QGridLayout(self.imageContainer) gridlayout.addWidget(self.imageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.teDetails, 1) reduceWidgetFontSize(self.twList) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.settings = settings self.series_name = series_name self.issue_number = issue_number self.year = year self.issue_count = issue_count self.volume_id = 0 self.comic_archive = comic_archive self.immediate_autoselect = autoselect self.cover_index_list = cover_index_list self.cv_search_results = None self.twList.resizeColumnsToContents() self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.btnRequery.clicked.connect(self.requery) self.btnIssues.clicked.connect(self.showIssues) self.btnAutoSelect.clicked.connect(self.autoSelect) self.updateButtons() self.performQuery() self.twList.selectRow(0)
class VolumeSelectionWindow(QtGui.QDialog): def __init__(self, parent, series_name, issue_number, year, issue_count, cover_index_list, comic_archive, settings, autoselect=False): super(VolumeSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('volumeselectionwindow.ui'), self) self.imageWidget = CoverImageWidget(self.imageContainer, CoverImageWidget.URLMode) gridlayout = QtGui.QGridLayout(self.imageContainer) gridlayout.addWidget(self.imageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.teDetails, 1) reduceWidgetFontSize(self.twList) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.settings = settings self.series_name = series_name self.issue_number = issue_number self.year = year self.issue_count = issue_count self.volume_id = 0 self.comic_archive = comic_archive self.immediate_autoselect = autoselect self.cover_index_list = cover_index_list self.cv_search_results = None self.twList.resizeColumnsToContents() self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.btnRequery.clicked.connect(self.requery) self.btnIssues.clicked.connect(self.showIssues) self.btnAutoSelect.clicked.connect(self.autoSelect) self.updateButtons() self.performQuery() self.twList.selectRow(0) def updateButtons(self): if self.cv_search_results is not None and len( self.cv_search_results) > 0: enabled = True else: enabled = False self.btnRequery.setEnabled(enabled) self.btnIssues.setEnabled(enabled) self.btnAutoSelect.setEnabled(enabled) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(enabled) def requery(self, ): self.performQuery(refresh=True) self.twList.selectRow(0) def autoSelect(self): if self.comic_archive is None: QtGui.QMessageBox.information(self, "Auto-Select", "You need to load a comic first!") return if self.issue_number is None or self.issue_number == "": QtGui.QMessageBox.information( self, "Auto-Select", "Can't auto-select without an issue number (yet!)") return self.iddialog = IDProgressWindow(self) self.iddialog.setModal(True) self.iddialog.rejected.connect(self.identifyCancel) self.iddialog.show() self.ii = IssueIdentifier(self.comic_archive, self.settings) md = GenericMetadata() md.series = self.series_name md.issue = self.issue_number md.year = self.year md.issueCount = self.issue_count self.ii.setAdditionalMetadata(md) self.ii.onlyUseAdditionalMetaData = True self.ii.cover_page_index = int(self.cover_index_list[0]) self.id_thread = IdentifyThread(self.ii) self.id_thread.identifyComplete.connect(self.identifyComplete) self.id_thread.identifyLogMsg.connect(self.logIDOutput) self.id_thread.identifyProgress.connect(self.identifyProgress) self.id_thread.start() self.iddialog.exec_() def logIDOutput(self, text): print unicode(text), self.iddialog.textEdit.ensureCursorVisible() self.iddialog.textEdit.insertPlainText(text) def identifyProgress(self, cur, total): self.iddialog.progressBar.setMaximum(total) self.iddialog.progressBar.setValue(cur) def identifyCancel(self): self.ii.cancel = True def identifyComplete(self): matches = self.ii.match_list result = self.ii.search_result match_index = 0 found_match = None choices = False if result == self.ii.ResultNoMatches: QtGui.QMessageBox.information(self, "Auto-Select Result", " No matches found :-(") elif result == self.ii.ResultFoundMatchButBadCoverScore: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found a match, but cover doesn't seem the same. Verify before commiting!" ) found_match = matches[0] elif result == self.ii.ResultFoundMatchButNotFirstPage: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found a match, but not with the first page of the archive.") found_match = matches[0] elif result == self.ii.ResultMultipleMatchesWithBadImageScores: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found some possibilities, but no confidence. Proceed manually." ) choices = True elif result == self.ii.ResultOneGoodMatch: found_match = matches[0] elif result == self.ii.ResultMultipleGoodMatches: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found multiple likely matches. Please select.") choices = True if choices: selector = MatchSelectionWindow(self, matches, self.comic_archive) selector.setModal(True) selector.exec_() if selector.result(): # we should now have a list index found_match = selector.currentMatch() if found_match is not None: self.iddialog.accept() self.volume_id = found_match['volume_id'] self.issue_number = found_match['issue_number'] self.selectByID() self.showIssues() def showIssues(self): selector = IssueSelectionWindow(self, self.settings, self.volume_id, self.issue_number) title = "" for record in self.cv_search_results: if record['id'] == self.volume_id: title = record['name'] title += " (" + unicode(record['start_year']) + ")" title += " - " break selector.setWindowTitle(title + "Select Issue") selector.setModal(True) selector.exec_() if selector.result(): # we should now have a volume ID self.issue_number = selector.issue_number self.accept() return def selectByID(self): for r in range(0, self.twList.rowCount()): volume_id, b = self.twList.item(r, 0).data( QtCore.Qt.UserRole).toInt() if (volume_id == self.volume_id): self.twList.selectRow(r) break def performQuery(self, refresh=False): self.progdialog = QtGui.QProgressDialog("Searching Online", "Cancel", 0, 100, self) self.progdialog.setWindowTitle("Online Search") self.progdialog.canceled.connect(self.searchCanceled) self.progdialog.setModal(True) self.search_thread = SearchThread(self.series_name, refresh) self.search_thread.searchComplete.connect(self.searchComplete) self.search_thread.progressUpdate.connect(self.searchProgressUpdate) self.search_thread.start() # QtCore.QCoreApplication.processEvents() self.progdialog.exec_() def searchCanceled(self): print("query cancelled") self.search_thread.searchComplete.disconnect(self.searchComplete) self.search_thread.progressUpdate.disconnect(self.searchProgressUpdate) self.progdialog.canceled.disconnect(self.searchCanceled) self.progdialog.reject() QtCore.QTimer.singleShot(200, self.closeMe) def closeMe(self): print("closeme") self.reject() def searchProgressUpdate(self, current, total): self.progdialog.setMaximum(total) self.progdialog.setValue(current) def searchComplete(self): self.progdialog.accept() if self.search_thread.cv_error: if self.search_thread.error_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 Comic Vine to search for series!" )) return self.cv_search_results = self.search_thread.cv_search_results self.updateButtons() self.twList.setSortingEnabled(False) while self.twList.rowCount() > 0: self.twList.removeRow(0) row = 0 for record in self.cv_search_results: self.twList.insertRow(row) item_text = record['name'] item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setData(QtCore.Qt.UserRole, record['id']) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 0, item) item_text = str(record['start_year']) item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 1, item) item_text = record['count_of_issues'] item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setData(QtCore.Qt.DisplayRole, record['count_of_issues']) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 2, item) if record['publisher'] is not None: item_text = record['publisher']['name'] item.setData(QtCore.Qt.ToolTipRole, item_text) item = QtGui.QTableWidgetItem(item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 3, item) row += 1 self.twList.resizeColumnsToContents() self.twList.setSortingEnabled(True) self.twList.sortItems(2, QtCore.Qt.DescendingOrder) self.twList.selectRow(0) self.twList.resizeColumnsToContents() if len(self.cv_search_results) == 0: QtCore.QCoreApplication.processEvents() QtGui.QMessageBox.information(self, "Search Result", "No matches found!") if self.immediate_autoselect and len(self.cv_search_results) > 0: # defer the immediate autoselect so this dialog has time to pop up QtCore.QCoreApplication.processEvents() QtCore.QTimer.singleShot(10, self.doImmediateAutoselect) def doImmediateAutoselect(self): self.immediate_autoselect = False self.autoSelect() def cellDoubleClicked(self, r, c): self.showIssues() def currentItemChanged(self, curr, prev): if curr is None: return if prev is not None and prev.row() == curr.row(): return self.volume_id, b = self.twList.item(curr.row(), 0).data( QtCore.Qt.UserRole).toInt() # list selection was changed, update the info on the volume for record in self.cv_search_results: if record['id'] == self.volume_id: if record['description'] is None: self.teDetails.setText("") else: self.teDetails.setText(record['description']) self.imageWidget.setURL(record['image']['super_url']) break
class MatchSelectionWindow(QtGui.QDialog): volume_id = 0 def __init__(self, parent, matches, comic_archive): super(MatchSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('matchselectionwindow.ui'), self) self.altCoverWidget = CoverImageWidget(self.altCoverContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.altCoverContainer) gridlayout.addWidget(self.altCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.archiveCoverWidget = CoverImageWidget( self.archiveCoverContainer, CoverImageWidget.ArchiveMode) gridlayout = QtGui.QGridLayout(self.archiveCoverContainer) gridlayout.addWidget(self.archiveCoverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) utils.reduceWidgetFontSize(self.twList) utils.reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.matches = matches self.comic_archive = comic_archive self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.updateData() def updateData(self): self.setCoverImage() self.populateTable() self.twList.resizeColumnsToContents() self.twList.selectRow(0) path = self.comic_archive.path self.setWindowTitle(u"Select correct match: {0}".format( os.path.split(path)[1])) def populateTable(self): 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'] item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setData(QtCore.Qt.UserRole, (match, )) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 0, item) if match['publisher'] is not None: item_text = u"{0}".format(match['publisher']) else: item_text = u"Unknown" item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 1, item) month_str = u"" year_str = u"????" if match['month'] is not None: month_str = u"-{0:02d}".format(int(match['month'])) if match['year'] is not None: year_str = u"{0}".format(match['year']) item_text = year_str + month_str 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) item_text = match['issue_title'] 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, 3, item) row += 1 self.twList.resizeColumnsToContents() self.twList.setSortingEnabled(True) self.twList.sortItems(2, QtCore.Qt.AscendingOrder) self.twList.selectRow(0) self.twList.resizeColumnsToContents() self.twList.horizontalHeader().setStretchLastSection(True) 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.altCoverWidget.setIssueID(self.currentMatch()['issue_id']) if self.currentMatch()['description'] is None: self.teDescription.setText("") else: self.teDescription.setText(self.currentMatch()['description']) def setCoverImage(self): self.archiveCoverWidget.setArchive(self.comic_archive) def currentMatch(self): row = self.twList.currentRow() match = self.twList.item(row, 0).data(QtCore.Qt.UserRole).toPyObject()[0] return match
class VolumeSelectionWindow(QtGui.QDialog): def __init__(self, parent, series_name, issue_number, year, issue_count, cover_index_list, comic_archive, settings, autoselect=False): super(VolumeSelectionWindow, self).__init__(parent) uic.loadUi( ComicTaggerSettings.getUIFile('volumeselectionwindow.ui'), self) self.imageWidget = CoverImageWidget( self.imageContainer, CoverImageWidget.URLMode) gridlayout = QtGui.QGridLayout(self.imageContainer) gridlayout.addWidget(self.imageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.teDetails, 1) reduceWidgetFontSize(self.twList) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.settings = settings self.series_name = series_name self.issue_number = issue_number self.year = year self.issue_count = issue_count self.volume_id = 0 self.comic_archive = comic_archive self.immediate_autoselect = autoselect self.cover_index_list = cover_index_list self.cv_search_results = None self.twList.resizeColumnsToContents() self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.btnRequery.clicked.connect(self.requery) self.btnIssues.clicked.connect(self.showIssues) self.btnAutoSelect.clicked.connect(self.autoSelect) self.updateButtons() self.performQuery() self.twList.selectRow(0) def updateButtons(self): if self.cv_search_results is not None and len( self.cv_search_results) > 0: enabled = True else: enabled = False self.btnRequery.setEnabled(enabled) self.btnIssues.setEnabled(enabled) self.btnAutoSelect.setEnabled(enabled) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(enabled) def requery(self,): self.performQuery(refresh=True) self.twList.selectRow(0) def autoSelect(self): if self.comic_archive is None: QtGui.QMessageBox.information( self, "Auto-Select", "You need to load a comic first!") return if self.issue_number is None or self.issue_number == "": QtGui.QMessageBox.information( self, "Auto-Select", "Can't auto-select without an issue number (yet!)") return self.iddialog = IDProgressWindow(self) self.iddialog.setModal(True) self.iddialog.rejected.connect(self.identifyCancel) self.iddialog.show() self.ii = IssueIdentifier(self.comic_archive, self.settings) md = GenericMetadata() md.series = self.series_name md.issue = self.issue_number md.year = self.year md.issueCount = self.issue_count self.ii.setAdditionalMetadata(md) self.ii.onlyUseAdditionalMetaData = True self.ii.cover_page_index = int(self.cover_index_list[0]) self.id_thread = IdentifyThread(self.ii) self.id_thread.identifyComplete.connect(self.identifyComplete) self.id_thread.identifyLogMsg.connect(self.logIDOutput) self.id_thread.identifyProgress.connect(self.identifyProgress) self.id_thread.start() self.iddialog.exec_() def logIDOutput(self, text): print unicode(text), self.iddialog.textEdit.ensureCursorVisible() self.iddialog.textEdit.insertPlainText(text) def identifyProgress(self, cur, total): self.iddialog.progressBar.setMaximum(total) self.iddialog.progressBar.setValue(cur) def identifyCancel(self): self.ii.cancel = True def identifyComplete(self): matches = self.ii.match_list result = self.ii.search_result match_index = 0 found_match = None choices = False if result == self.ii.ResultNoMatches: QtGui.QMessageBox.information( self, "Auto-Select Result", " No matches found :-(") elif result == self.ii.ResultFoundMatchButBadCoverScore: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found a match, but cover doesn't seem the same. Verify before commiting!") found_match = matches[0] elif result == self.ii.ResultFoundMatchButNotFirstPage: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found a match, but not with the first page of the archive.") found_match = matches[0] elif result == self.ii.ResultMultipleMatchesWithBadImageScores: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found some possibilities, but no confidence. Proceed manually.") choices = True elif result == self.ii.ResultOneGoodMatch: found_match = matches[0] elif result == self.ii.ResultMultipleGoodMatches: QtGui.QMessageBox.information( self, "Auto-Select Result", " Found multiple likely matches. Please select.") choices = True if choices: selector = MatchSelectionWindow(self, matches, self.comic_archive) selector.setModal(True) selector.exec_() if selector.result(): # we should now have a list index found_match = selector.currentMatch() if found_match is not None: self.iddialog.accept() self.volume_id = found_match['volume_id'] self.issue_number = found_match['issue_number'] self.selectByID() self.showIssues() def showIssues(self): selector = IssueSelectionWindow( self, self.settings, self.volume_id, self.issue_number) title = "" for record in self.cv_search_results: if record['id'] == self.volume_id: title = record['name'] title += " (" + unicode(record['start_year']) + ")" title += " - " break selector.setWindowTitle(title + "Select Issue") selector.setModal(True) selector.exec_() if selector.result(): # we should now have a volume ID self.issue_number = selector.issue_number self.accept() return def selectByID(self): for r in range(0, self.twList.rowCount()): volume_id, b = self.twList.item( r, 0).data(QtCore.Qt.UserRole).toInt() if (volume_id == self.volume_id): self.twList.selectRow(r) break def performQuery(self, refresh=False): self.progdialog = QtGui.QProgressDialog( "Searching Online", "Cancel", 0, 100, self) self.progdialog.setWindowTitle("Online Search") self.progdialog.canceled.connect(self.searchCanceled) self.progdialog.setModal(True) self.search_thread = SearchThread(self.series_name, refresh) self.search_thread.searchComplete.connect(self.searchComplete) self.search_thread.progressUpdate.connect(self.searchProgressUpdate) self.search_thread.start() # QtCore.QCoreApplication.processEvents() self.progdialog.exec_() def searchCanceled(self): print("query cancelled") self.search_thread.searchComplete.disconnect(self.searchComplete) self.search_thread.progressUpdate.disconnect(self.searchProgressUpdate) self.progdialog.canceled.disconnect(self.searchCanceled) self.progdialog.reject() QtCore.QTimer.singleShot(200, self.closeMe) def closeMe(self): print("closeme") self.reject() def searchProgressUpdate(self, current, total): self.progdialog.setMaximum(total) self.progdialog.setValue(current) def searchComplete(self): self.progdialog.accept() if self.search_thread.cv_error: if self.search_thread.error_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 Comic Vine to search for series!")) return self.cv_search_results = self.search_thread.cv_search_results self.updateButtons() self.twList.setSortingEnabled(False) while self.twList.rowCount() > 0: self.twList.removeRow(0) row = 0 for record in self.cv_search_results: self.twList.insertRow(row) item_text = record['name'] item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setData(QtCore.Qt.UserRole, record['id']) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 0, item) item_text = str(record['start_year']) item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 1, item) item_text = record['count_of_issues'] item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setData(QtCore.Qt.DisplayRole, record['count_of_issues']) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 2, item) if record['publisher'] is not None: item_text = record['publisher']['name'] item.setData(QtCore.Qt.ToolTipRole, item_text) item = QtGui.QTableWidgetItem(item_text) item.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 3, item) row += 1 self.twList.resizeColumnsToContents() self.twList.setSortingEnabled(True) self.twList.sortItems(2, QtCore.Qt.DescendingOrder) self.twList.selectRow(0) self.twList.resizeColumnsToContents() if len(self.cv_search_results) == 0: QtCore.QCoreApplication.processEvents() QtGui.QMessageBox.information( self, "Search Result", "No matches found!") if self.immediate_autoselect and len(self.cv_search_results) > 0: # defer the immediate autoselect so this dialog has time to pop up QtCore.QCoreApplication.processEvents() QtCore.QTimer.singleShot(10, self.doImmediateAutoselect) def doImmediateAutoselect(self): self.immediate_autoselect = False self.autoSelect() def cellDoubleClicked(self, r, c): self.showIssues() def currentItemChanged(self, curr, prev): if curr is None: return if prev is not None and prev.row() == curr.row(): return self.volume_id, b = self.twList.item( curr.row(), 0).data(QtCore.Qt.UserRole).toInt() # list selection was changed, update the info on the volume for record in self.cv_search_results: if record['id'] == self.volume_id: if record['description'] is None: self.teDetails.setText("") else: self.teDetails.setText(record['description']) self.imageWidget.setURL(record['image']['super_url']) break
class IssueSelectionWindow(QtGui.QDialog): volume_id = 0 def __init__(self, parent, settings, series_id, issue_number): super(IssueSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('issueselectionwindow.ui'), self) self.coverWidget = CoverImageWidget(self.coverImageContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.coverImageContainer) gridlayout.addWidget(self.coverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) utils.reduceWidgetFontSize(self.twList) utils.reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.series_id = series_id 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) #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 def performQuery(self): QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) try: comicVine = ComicVineTalker() volume_data = comicVine.fetchVolumeData(self.series_id) self.issue_list = comicVine.fetchIssuesByVolume(self.series_id) 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!")) 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) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setData(QtCore.Qt.UserRole, record['id']) item.setData(QtCore.Qt.DisplayRole, item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 0, item) item_text = record['cover_date'] if item_text is None: item_text = "" #remove the day of "YYYY-MM-DD" parts = item_text.split("-") if len(parts) > 1: item_text = parts[0] + "-" + parts[1] item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 1, item) 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) if IssueString( record['issue_number']).asString().lower() == IssueString( self.issue_number).asString().lower(): self.initial_id = record['id'] row += 1 self.twList.setSortingEnabled(True) self.twList.sortItems(0, QtCore.Qt.AscendingOrder) QtGui.QApplication.restoreOverrideCursor() 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: if record['id'] == self.issue_id: self.issue_number = record['issue_number'] self.coverWidget.setIssueID(int(self.issue_id)) if record['description'] is None: self.teDescription.setText("") else: self.teDescription.setText(record['description']) break
class PageListEditor(QWidget): firstFrontCoverChanged = pyqtSignal(int) listOrderChanged = pyqtSignal() modified = pyqtSignal() pageTypeNames = { PageType.FrontCover: "Front Cover", PageType.InnerCover: "Inner Cover", PageType.Advertisement: "Advertisement", PageType.Roundup: "Roundup", PageType.Story: "Story", PageType.Editorial: "Editorial", PageType.Letters: "Letters", PageType.Preview: "Preview", PageType.BackCover: "Back Cover", PageType.Other: "Other", PageType.Deleted: "Deleted", } def __init__(self, parent): super(PageListEditor, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('pagelisteditor.ui'), self) self.pageWidget = CoverImageWidget(self.pageContainer, CoverImageWidget.ArchiveMode) gridlayout = QGridLayout(self.pageContainer) gridlayout.addWidget(self.pageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.pageWidget.showControls = False self.resetPage() # Add the entries to the manga combobox self.comboBox.addItem("", "") self.comboBox.addItem(self.pageTypeNames[PageType.FrontCover], PageType.FrontCover) self.comboBox.addItem(self.pageTypeNames[PageType.InnerCover], PageType.InnerCover) self.comboBox.addItem(self.pageTypeNames[PageType.Advertisement], PageType.Advertisement) self.comboBox.addItem(self.pageTypeNames[PageType.Roundup], PageType.Roundup) self.comboBox.addItem(self.pageTypeNames[PageType.Story], PageType.Story) self.comboBox.addItem(self.pageTypeNames[PageType.Editorial], PageType.Editorial) self.comboBox.addItem(self.pageTypeNames[PageType.Letters], PageType.Letters) self.comboBox.addItem(self.pageTypeNames[PageType.Preview], PageType.Preview) self.comboBox.addItem(self.pageTypeNames[PageType.BackCover], PageType.BackCover) self.comboBox.addItem(self.pageTypeNames[PageType.Other], PageType.Other) self.comboBox.addItem(self.pageTypeNames[PageType.Deleted], PageType.Deleted) self.listWidget.itemSelectionChanged.connect(self.changePage) itemMoveEvents(self.listWidget).connect(self.itemMoveEvent) self.comboBox.activated.connect(self.changePageType) self.btnUp.clicked.connect(self.moveCurrentUp) self.btnDown.clicked.connect(self.moveCurrentDown) self.pre_move_row = -1 self.first_front_page = None def resetPage(self): self.pageWidget.clear() self.comboBox.setDisabled(True) self.comic_archive = None self.pages_list = None def moveCurrentUp(self): row = self.listWidget.currentRow() if row > 0: item = self.listWidget.takeItem(row) self.listWidget.insertItem(row - 1, item) self.listWidget.setCurrentRow(row - 1) self.listOrderChanged.emit() self.emitFrontCoverChange() self.modified.emit() def moveCurrentDown(self): row = self.listWidget.currentRow() if row < self.listWidget.count() - 1: item = self.listWidget.takeItem(row) self.listWidget.insertItem(row + 1, item) self.listWidget.setCurrentRow(row + 1) self.listOrderChanged.emit() self.emitFrontCoverChange() self.modified.emit() def itemMoveEvent(self, s): #print "move event: ", s, self.listWidget.currentRow() if s == "start": self.pre_move_row = self.listWidget.currentRow() if s == "finish": if self.pre_move_row != self.listWidget.currentRow(): self.listOrderChanged.emit() self.emitFrontCoverChange() self.modified.emit() def changePageType(self, i): new_type = self.comboBox.itemData(i).toString() if self.getCurrentPageType() != new_type: self.setCurrentPageType(new_type) self.emitFrontCoverChange() self.modified.emit() def changePage(self): row = self.listWidget.currentRow() pagetype = self.getCurrentPageType() i = self.comboBox.findData(pagetype) self.comboBox.setCurrentIndex(i) #idx = int(str (self.listWidget.item( row ).text())) idx = int( self.listWidget.item(row).data( Qt.UserRole).toPyObject()[0]['Image']) if self.comic_archive is not None: self.pageWidget.setArchive(self.comic_archive, idx) def getFirstFrontCover(self): frontCover = 0 for i in range(self.listWidget.count()): item = self.listWidget.item(i) page_dict = item.data(Qt.UserRole).toPyObject()[0] if 'Type' in page_dict and page_dict['Type'] == PageType.FrontCover: frontCover = int(page_dict['Image']) break return frontCover def getCurrentPageType(self): row = self.listWidget.currentRow() page_dict = self.listWidget.item(row).data(Qt.UserRole).toPyObject()[0] if 'Type' in page_dict: return page_dict['Type'] else: return "" def setCurrentPageType(self, t): row = self.listWidget.currentRow() page_dict = self.listWidget.item(row).data(Qt.UserRole).toPyObject()[0] if t == "": if 'Type' in page_dict: del (page_dict['Type']) else: page_dict['Type'] = str(t) item = self.listWidget.item(row) # wrap the dict in a tuple to keep from being converted to QStrings item.setData(Qt.UserRole, (page_dict, )) item.setText(self.listEntryText(page_dict)) def setData(self, comic_archive, pages_list): self.comic_archive = comic_archive self.pages_list = pages_list if pages_list is not None and len(pages_list) > 0: self.comboBox.setDisabled(False) self.listWidget.itemSelectionChanged.disconnect(self.changePage) self.listWidget.clear() for p in pages_list: item = QListWidgetItem(self.listEntryText(p)) # wrap the dict in a tuple to keep from being converted to QStrings item.setData(Qt.UserRole, (p, )) self.listWidget.addItem(item) self.first_front_page = self.getFirstFrontCover() self.listWidget.itemSelectionChanged.connect(self.changePage) self.listWidget.setCurrentRow(0) def listEntryText(self, page_dict): text = str(int(page_dict['Image']) + 1) if 'Type' in page_dict: text += " (" + self.pageTypeNames[page_dict['Type']] + ")" return text def getPageList(self): page_list = [] for i in range(self.listWidget.count()): item = self.listWidget.item(i) page_list.append(item.data(Qt.UserRole).toPyObject()[0]) return page_list def emitFrontCoverChange(self): if self.first_front_page != self.getFirstFrontCover(): self.first_front_page = self.getFirstFrontCover() self.firstFrontCoverChanged.emit(self.first_front_page) def setMetadataStyle(self, data_style): # depending on the current data style, certain fields are disabled inactive_color = QColor(255, 170, 150) active_palette = self.comboBox.palette() inactive_palette3 = self.comboBox.palette() inactive_palette3.setColor(QPalette.Base, inactive_color) if data_style == MetaDataStyle.CIX: self.btnUp.setEnabled(True) self.btnDown.setEnabled(True) self.comboBox.setEnabled(True) self.listWidget.setEnabled(True) self.listWidget.setPalette(active_palette) elif data_style == MetaDataStyle.CBI: self.btnUp.setEnabled(False) self.btnDown.setEnabled(False) self.comboBox.setEnabled(False) self.listWidget.setEnabled(False) self.listWidget.setPalette(inactive_palette3) elif data_style == MetaDataStyle.CoMet: pass # make sure combo is disabled when no list if self.comic_archive is None: self.comboBox.setEnabled(False)
class PageListEditor(QWidget): firstFrontCoverChanged = pyqtSignal(int) listOrderChanged = pyqtSignal() modified = pyqtSignal() pageTypeNames = { PageType.FrontCover: "Front Cover", PageType.InnerCover: "Inner Cover", PageType.Advertisement: "Advertisement", PageType.Roundup: "Roundup", PageType.Story: "Story", PageType.Editorial: "Editorial", PageType.Letters: "Letters", PageType.Preview: "Preview", PageType.BackCover: "Back Cover", PageType.Other: "Other", PageType.Deleted: "Deleted", } def __init__(self, parent): super(PageListEditor, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('pagelisteditor.ui'), self) self.pageWidget = CoverImageWidget( self.pageContainer, CoverImageWidget.ArchiveMode) gridlayout = QGridLayout(self.pageContainer) gridlayout.addWidget(self.pageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.pageWidget.showControls = False self.resetPage() # Add the entries to the manga combobox self.comboBox.addItem("", "") self.comboBox.addItem( self.pageTypeNames[PageType.FrontCover], PageType.FrontCover) self.comboBox.addItem( self.pageTypeNames[PageType.InnerCover], PageType.InnerCover) self.comboBox.addItem( self.pageTypeNames[PageType.Advertisement], PageType.Advertisement) self.comboBox.addItem( self.pageTypeNames[PageType.Roundup], PageType.Roundup) self.comboBox.addItem( self.pageTypeNames[PageType.Story], PageType.Story) self.comboBox.addItem( self.pageTypeNames[PageType.Editorial], PageType.Editorial) self.comboBox.addItem( self.pageTypeNames[PageType.Letters], PageType.Letters) self.comboBox.addItem( self.pageTypeNames[PageType.Preview], PageType.Preview) self.comboBox.addItem( self.pageTypeNames[PageType.BackCover], PageType.BackCover) self.comboBox.addItem( self.pageTypeNames[PageType.Other], PageType.Other) self.comboBox.addItem( self.pageTypeNames[PageType.Deleted], PageType.Deleted) self.listWidget.itemSelectionChanged.connect(self.changePage) itemMoveEvents(self.listWidget).connect(self.itemMoveEvent) self.comboBox.activated.connect(self.changePageType) self.btnUp.clicked.connect(self.moveCurrentUp) self.btnDown.clicked.connect(self.moveCurrentDown) self.pre_move_row = -1 self.first_front_page = None def resetPage(self): self.pageWidget.clear() self.comboBox.setDisabled(True) self.comic_archive = None self.pages_list = None def moveCurrentUp(self): row = self.listWidget.currentRow() if row > 0: item = self.listWidget.takeItem(row) self.listWidget.insertItem(row - 1, item) self.listWidget.setCurrentRow(row - 1) self.listOrderChanged.emit() self.emitFrontCoverChange() self.modified.emit() def moveCurrentDown(self): row = self.listWidget.currentRow() if row < self.listWidget.count() - 1: item = self.listWidget.takeItem(row) self.listWidget.insertItem(row + 1, item) self.listWidget.setCurrentRow(row + 1) self.listOrderChanged.emit() self.emitFrontCoverChange() self.modified.emit() def itemMoveEvent(self, s): # print "move event: ", s, self.listWidget.currentRow() if s == "start": self.pre_move_row = self.listWidget.currentRow() if s == "finish": if self.pre_move_row != self.listWidget.currentRow(): self.listOrderChanged.emit() self.emitFrontCoverChange() self.modified.emit() def changePageType(self, i): new_type = self.comboBox.itemData(i).toString() if self.getCurrentPageType() != new_type: self.setCurrentPageType(new_type) self.emitFrontCoverChange() self.modified.emit() def changePage(self): row = self.listWidget.currentRow() pagetype = self.getCurrentPageType() i = self.comboBox.findData(pagetype) self.comboBox.setCurrentIndex(i) #idx = int(str (self.listWidget.item(row).text())) idx = int(self.listWidget.item(row).data( Qt.UserRole).toPyObject()[0]['Image']) if self.comic_archive is not None: self.pageWidget.setArchive(self.comic_archive, idx) def getFirstFrontCover(self): frontCover = 0 for i in range(self.listWidget.count()): item = self.listWidget.item(i) page_dict = item.data(Qt.UserRole).toPyObject()[0] if 'Type' in page_dict and page_dict[ 'Type'] == PageType.FrontCover: frontCover = int(page_dict['Image']) break return frontCover def getCurrentPageType(self): row = self.listWidget.currentRow() page_dict = self.listWidget.item(row).data(Qt.UserRole).toPyObject()[0] if 'Type' in page_dict: return page_dict['Type'] else: return "" def setCurrentPageType(self, t): row = self.listWidget.currentRow() page_dict = self.listWidget.item(row).data(Qt.UserRole).toPyObject()[0] if t == "": if 'Type' in page_dict: del(page_dict['Type']) else: page_dict['Type'] = str(t) item = self.listWidget.item(row) # wrap the dict in a tuple to keep from being converted to QStrings item.setData(Qt.UserRole, (page_dict,)) item.setText(self.listEntryText(page_dict)) def setData(self, comic_archive, pages_list): self.comic_archive = comic_archive self.pages_list = pages_list if pages_list is not None and len(pages_list) > 0: self.comboBox.setDisabled(False) self.listWidget.itemSelectionChanged.disconnect(self.changePage) self.listWidget.clear() for p in pages_list: item = QListWidgetItem(self.listEntryText(p)) # wrap the dict in a tuple to keep from being converted to QStrings item.setData(Qt.UserRole, (p,)) self.listWidget.addItem(item) self.first_front_page = self.getFirstFrontCover() self.listWidget.itemSelectionChanged.connect(self.changePage) self.listWidget.setCurrentRow(0) def listEntryText(self, page_dict): text = str(int(page_dict['Image']) + 1) if 'Type' in page_dict: text += " (" + self.pageTypeNames[page_dict['Type']] + ")" return text def getPageList(self): page_list = [] for i in range(self.listWidget.count()): item = self.listWidget.item(i) page_list.append(item.data(Qt.UserRole).toPyObject()[0]) return page_list def emitFrontCoverChange(self): if self.first_front_page != self.getFirstFrontCover(): self.first_front_page = self.getFirstFrontCover() self.firstFrontCoverChanged.emit(self.first_front_page) def setMetadataStyle(self, data_style): # depending on the current data style, certain fields are disabled inactive_color = QColor(255, 170, 150) active_palette = self.comboBox.palette() inactive_palette3 = self.comboBox.palette() inactive_palette3.setColor(QPalette.Base, inactive_color) if data_style == MetaDataStyle.CIX: self.btnUp.setEnabled(True) self.btnDown.setEnabled(True) self.comboBox.setEnabled(True) self.listWidget.setEnabled(True) self.listWidget.setPalette(active_palette) elif data_style == MetaDataStyle.CBI: self.btnUp.setEnabled(False) self.btnDown.setEnabled(False) self.comboBox.setEnabled(False) self.listWidget.setEnabled(False) self.listWidget.setPalette(inactive_palette3) elif data_style == MetaDataStyle.CoMet: pass # make sure combo is disabled when no list if self.comic_archive is None: self.comboBox.setEnabled(False)
class IssueSelectionWindow(QtGui.QDialog): volume_id = 0 def __init__(self, parent, settings, series_id, issue_number): super(IssueSelectionWindow, self).__init__(parent) uic.loadUi( ComicTaggerSettings.getUIFile('issueselectionwindow.ui'), self) self.coverWidget = CoverImageWidget( self.coverImageContainer, CoverImageWidget.AltCoverMode) gridlayout = QtGui.QGridLayout(self.coverImageContainer) gridlayout.addWidget(self.coverWidget) gridlayout.setContentsMargins(0, 0, 0, 0) reduceWidgetFontSize(self.twList) reduceWidgetFontSize(self.teDescription, 1) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.series_id = series_id 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) # 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 def performQuery(self): QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) try: comicVine = ComicVineTalker() volume_data = comicVine.fetchVolumeData(self.series_id) self.issue_list = comicVine.fetchIssuesByVolume(self.series_id) 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 Comic Vine to list issues!")) 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) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setData(QtCore.Qt.UserRole, record['id']) item.setData(QtCore.Qt.DisplayRole, item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 0, item) item_text = record['cover_date'] if item_text is None: item_text = "" # remove the day of "YYYY-MM-DD" parts = item_text.split("-") if len(parts) > 1: item_text = parts[0] + "-" + parts[1] item = QtGui.QTableWidgetItem(item_text) item.setData(QtCore.Qt.ToolTipRole, item_text) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 1, item) 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) if IssueString( record['issue_number']).asString().lower() == IssueString( self.issue_number).asString().lower(): self.initial_id = record['id'] row += 1 self.twList.setSortingEnabled(True) self.twList.sortItems(0, QtCore.Qt.AscendingOrder) QtGui.QApplication.restoreOverrideCursor() 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: if record['id'] == self.issue_id: self.issue_number = record['issue_number'] self.coverWidget.setIssueID(int(self.issue_id)) if record['description'] is None: self.teDescription.setText("") else: self.teDescription.setText(record['description']) break
class AutoTagMatchWindow(QtGui.QDialog): volume_id = 0 def __init__(self, parent, match_set_list, style, fetch_func): super(AutoTagMatchWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('matchselectionwindow.ui' ), self) self.altCoverWidget = CoverImageWidget( self.altCoverContainer, CoverImageWidget.AltCoverMode ) gridlayout = QtGui.QGridLayout( self.altCoverContainer ) gridlayout.addWidget( self.altCoverWidget ) gridlayout.setContentsMargins(0,0,0,0) self.archiveCoverWidget = CoverImageWidget( self.archiveCoverContainer, CoverImageWidget.ArchiveMode ) gridlayout = QtGui.QGridLayout( self.archiveCoverContainer ) gridlayout.addWidget( self.archiveCoverWidget ) gridlayout.setContentsMargins(0,0,0,0) utils.reduceWidgetFontSize( self.twList ) utils.reduceWidgetFontSize( self.teDescription, 1 ) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.skipButton = QtGui.QPushButton(self.tr("Skip to Next")) self.buttonBox.addButton(self.skipButton, QtGui.QDialogButtonBox.ActionRole) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText("Accept and Write Tags") self.match_set_list = match_set_list self.style = style self.fetch_func = fetch_func self.current_match_set_idx = 0 self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.skipButton.clicked.connect(self.skipToNext) self.updateData() def updateData( self): self.current_match_set = self.match_set_list[ self.current_match_set_idx ] if self.current_match_set_idx + 1 == len( self.match_set_list ): self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setDisabled(True) #self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText("Accept") self.skipButton.setText(self.tr("Skip")) self.setCoverImage() self.populateTable() self.twList.resizeColumnsToContents() self.twList.selectRow( 0 ) path = self.current_match_set.ca.path self.setWindowTitle( u"Select correct match or skip ({0} of {1}): {2}".format( self.current_match_set_idx+1, len( self.match_set_list ), os.path.split(path)[1] )) def populateTable( self ): while self.twList.rowCount() > 0: self.twList.removeRow(0) self.twList.setSortingEnabled(False) row = 0 for match in self.current_match_set.matches: self.twList.insertRow(row) item_text = match['series'] item = QtGui.QTableWidgetItem(item_text) item.setData( QtCore.Qt.ToolTipRole, item_text ) item.setData( QtCore.Qt.UserRole, (match,)) item.setFlags(QtCore.Qt.ItemIsSelectable| QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 0, item) if match['publisher'] is not None: item_text = u"{0}".format(match['publisher']) else: item_text = u"Unknown" item = QtGui.QTableWidgetItem(item_text) item.setData( QtCore.Qt.ToolTipRole, item_text ) item.setFlags(QtCore.Qt.ItemIsSelectable| QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 1, item) month_str = u"" year_str = u"????" if match['month'] is not None: month_str = u"-{0:02d}".format(int(match['month'])) if match['year'] is not None: year_str = u"{0}".format(match['year']) item_text = year_str + month_str 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) item_text = match['issue_title'] 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, 3, item) row += 1 self.twList.resizeColumnsToContents() self.twList.setSortingEnabled(True) self.twList.sortItems( 2 , QtCore.Qt.AscendingOrder ) self.twList.selectRow(0) self.twList.resizeColumnsToContents() self.twList.horizontalHeader().setStretchLastSection(True) 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.altCoverWidget.setIssueID( self.currentMatch()['issue_id'] ) if self.currentMatch()['description'] is None: self.teDescription.setText ( "" ) else: self.teDescription.setText ( self.currentMatch()['description'] ) def setCoverImage( self ): ca = self.current_match_set.ca self.archiveCoverWidget.setArchive(ca) def currentMatch( self ): row = self.twList.currentRow() match = self.twList.item(row, 0).data( QtCore.Qt.UserRole ).toPyObject()[0] return match def accept(self): self.saveMatch() self.current_match_set_idx += 1 if self.current_match_set_idx == len( self.match_set_list ): # no more items QtGui.QDialog.accept(self) else: self.updateData() def skipToNext( self ): self.current_match_set_idx += 1 if self.current_match_set_idx == len( self.match_set_list ): # no more items QtGui.QDialog.reject(self) else: self.updateData() def reject(self): reply = QtGui.QMessageBox.question(self, self.tr("Cancel Matching"), self.tr("Are you sure you wish to cancel the matching process?"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No ) if reply == QtGui.QMessageBox.No: return QtGui.QDialog.reject(self) def saveMatch( self ): match = self.currentMatch() ca = self.current_match_set.ca md = ca.readMetadata( self.style ) if md.isEmpty: md = ca.metadataFromFilename() # now get the particular issue data cv_md = self.fetch_func( match ) if cv_md is None: QtGui.QMessageBox.critical(self, self.tr("Network Issue"), self.tr("Could not connect to ComicVine to get issue details!")) return QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) md.overlay( cv_md ) success = ca.writeMetadata( md, self.style ) ca.loadCache( [ MetaDataStyle.CBI, MetaDataStyle.CIX ] ) QtGui.QApplication.restoreOverrideCursor() if not success: QtGui.QMessageBox.warning(self, self.tr("Write Error"), self.tr("Saving the tags to the archive seemed to fail!"))
class PageBrowserWindow(QtGui.QDialog): def __init__(self, parent, metadata): super(PageBrowserWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('pagebrowser.ui' ), self) self.pageWidget = CoverImageWidget( self.pageContainer, CoverImageWidget.ArchiveMode ) gridlayout = QtGui.QGridLayout( self.pageContainer ) gridlayout.addWidget( self.pageWidget ) gridlayout.setContentsMargins(0,0,0,0) self.pageWidget.showControls = False self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.comic_archive = None self.page_count = 0 self.current_page_num = 0 self.metadata = metadata self.buttonBox.button(QtGui.QDialogButtonBox.Close).setDefault(True) if platform.system() == "Darwin": self.btnPrev.setText("<<") self.btnNext.setText(">>") else: self.btnPrev.setIcon(QtGui.QIcon( ComicTaggerSettings.getGraphic('left.png' ))) self.btnNext.setIcon(QtGui.QIcon( ComicTaggerSettings.getGraphic('right.png'))) self.btnNext.clicked.connect( self.nextPage ) self.btnPrev.clicked.connect( self.prevPage ) self.show() self.btnNext.setEnabled( False ) self.btnPrev.setEnabled( False ) def reset( self ): self.comic_archive = None self.page_count = 0 self.current_page_num = 0 self.metadata = None self.btnNext.setEnabled( False ) self.btnPrev.setEnabled( False ) self.pageWidget.clear() def setComicArchive(self, ca): self.comic_archive = ca self.page_count = ca.getNumberOfPages() self.current_page_num = 0 self.pageWidget.setArchive( self.comic_archive ) self.setPage() if self.page_count > 1: self.btnNext.setEnabled( True ) self.btnPrev.setEnabled( True ) def nextPage(self): if self.current_page_num + 1 < self.page_count: self.current_page_num += 1 else: self.current_page_num = 0 self.setPage() def prevPage(self): if self.current_page_num - 1 >= 0: self.current_page_num -= 1 else: self.current_page_num = self.page_count - 1 self.setPage() def setPage( self ): if self.metadata is not None: archive_page_index = self.metadata.getArchivePageIndex( self.current_page_num ) else: archive_page_index = self.current_page_num self.pageWidget.setPage( archive_page_index ) self.setWindowTitle("Page Browser - Page {0} (of {1}) ".format(self.current_page_num+1, self.page_count ) )
class PageBrowserWindow(QtGui.QDialog): def __init__(self, parent, metadata): super(PageBrowserWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('pagebrowser.ui'), self) self.pageWidget = CoverImageWidget(self.pageContainer, CoverImageWidget.ArchiveMode) gridlayout = QtGui.QGridLayout(self.pageContainer) gridlayout.addWidget(self.pageWidget) gridlayout.setContentsMargins(0, 0, 0, 0) self.pageWidget.showControls = False self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.comic_archive = None self.page_count = 0 self.current_page_num = 0 self.metadata = metadata self.buttonBox.button(QtGui.QDialogButtonBox.Close).setDefault(True) if platform.system() == "Darwin": self.btnPrev.setText("<<") self.btnNext.setText(">>") else: self.btnPrev.setIcon( QtGui.QIcon(ComicTaggerSettings.getGraphic('left.png'))) self.btnNext.setIcon( QtGui.QIcon(ComicTaggerSettings.getGraphic('right.png'))) self.btnNext.clicked.connect(self.nextPage) self.btnPrev.clicked.connect(self.prevPage) self.show() self.btnNext.setEnabled(False) self.btnPrev.setEnabled(False) def reset(self): self.comic_archive = None self.page_count = 0 self.current_page_num = 0 self.metadata = None self.btnNext.setEnabled(False) self.btnPrev.setEnabled(False) self.pageWidget.clear() def setComicArchive(self, ca): self.comic_archive = ca self.page_count = ca.getNumberOfPages() self.current_page_num = 0 self.pageWidget.setArchive(self.comic_archive) self.setPage() if self.page_count > 1: self.btnNext.setEnabled(True) self.btnPrev.setEnabled(True) def nextPage(self): if self.current_page_num + 1 < self.page_count: self.current_page_num += 1 else: self.current_page_num = 0 self.setPage() def prevPage(self): if self.current_page_num - 1 >= 0: self.current_page_num -= 1 else: self.current_page_num = self.page_count - 1 self.setPage() def setPage(self): if self.metadata is not None: archive_page_index = self.metadata.getArchivePageIndex( self.current_page_num) else: archive_page_index = self.current_page_num self.pageWidget.setPage(archive_page_index) self.setWindowTitle("Page Browser - Page {0} (of {1}) ".format( self.current_page_num + 1, self.page_count))
class MatchSelectionWindow(QtGui.QDialog): volume_id = 0 def __init__(self, parent, matches, comic_archive): super(MatchSelectionWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('matchselectionwindow.ui' ), self) self.altCoverWidget = CoverImageWidget( self.altCoverContainer, CoverImageWidget.AltCoverMode ) gridlayout = QtGui.QGridLayout( self.altCoverContainer ) gridlayout.addWidget( self.altCoverWidget ) gridlayout.setContentsMargins(0,0,0,0) self.archiveCoverWidget = CoverImageWidget( self.archiveCoverContainer, CoverImageWidget.ArchiveMode ) gridlayout = QtGui.QGridLayout( self.archiveCoverContainer ) gridlayout.addWidget( self.archiveCoverWidget ) gridlayout.setContentsMargins(0,0,0,0) utils.reduceWidgetFontSize( self.twList ) utils.reduceWidgetFontSize( self.teDescription, 1 ) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMaximizeButtonHint) self.matches = matches self.comic_archive = comic_archive self.twList.currentItemChanged.connect(self.currentItemChanged) self.twList.cellDoubleClicked.connect(self.cellDoubleClicked) self.updateData() def updateData( self): self.setCoverImage() self.populateTable() self.twList.resizeColumnsToContents() self.twList.selectRow( 0 ) path = self.comic_archive.path self.setWindowTitle( u"Select correct match: {0}".format( os.path.split(path)[1] )) def populateTable( self ): 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'] item = QtGui.QTableWidgetItem(item_text) item.setData( QtCore.Qt.ToolTipRole, item_text ) item.setData( QtCore.Qt.UserRole, (match,)) item.setFlags(QtCore.Qt.ItemIsSelectable| QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 0, item) if match['publisher'] is not None: item_text = u"{0}".format(match['publisher']) else: item_text = u"Unknown" item = QtGui.QTableWidgetItem(item_text) item.setData( QtCore.Qt.ToolTipRole, item_text ) item.setFlags(QtCore.Qt.ItemIsSelectable| QtCore.Qt.ItemIsEnabled) self.twList.setItem(row, 1, item) month_str = u"" year_str = u"????" if match['month'] is not None: month_str = u"-{0:02d}".format(int(match['month'])) if match['year'] is not None: year_str = u"{0}".format(match['year']) item_text = year_str + month_str 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) item_text = match['issue_title'] 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, 3, item) row += 1 self.twList.resizeColumnsToContents() self.twList.setSortingEnabled(True) self.twList.sortItems( 2 , QtCore.Qt.AscendingOrder ) self.twList.selectRow(0) self.twList.resizeColumnsToContents() self.twList.horizontalHeader().setStretchLastSection(True) 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.altCoverWidget.setIssueID( self.currentMatch()['issue_id'] ) if self.currentMatch()['description'] is None: self.teDescription.setText ( "" ) else: self.teDescription.setText ( self.currentMatch()['description'] ) def setCoverImage( self ): self.archiveCoverWidget.setArchive( self.comic_archive) def currentMatch( self ): row = self.twList.currentRow() match = self.twList.item(row, 0).data( QtCore.Qt.UserRole ).toPyObject()[0] return match