From 593f568ea7a7a7a6705ddc2b08b2861ab6a259b7 Mon Sep 17 00:00:00 2001 From: MichaelFitzurka Date: Sun, 3 Apr 2022 15:39:03 -0400 Subject: [PATCH 1/4] method renamed to match new changes. --- comicapi/comicarchive.py | 26 +++++++++++++------------- comicapi/comicinfoxml.py | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index 02d84ab..7aeec0c 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -65,13 +65,13 @@ class SevenZipArchiver: self.path = path # @todo: Implement Comment? - def getArchiveComment(self): + def get_comment(self): return "" - def setArchiveComment(self, comment): + def set_comment(self, comment): return False - def readArchiveFile(self, archive_file): + def read_file(self, archive_file): data = "" try: with py7zr.SevenZipFile(self.path, "r") as zf: @@ -85,22 +85,22 @@ class SevenZipArchiver: return data - def removeArchiveFile(self, archive_file): + def remove_file(self, archive_file): try: - self.rebuildSevenZipFile([archive_file]) + self.rebuild_zip_file([archive_file]) except: return False else: return True - def writeArchiveFile(self, archive_file, data): + def write_file(self, archive_file, data): # At the moment, no other option but to rebuild the whole # zip archive w/o the indicated file. Very sucky, but maybe # another solution can be found try: - files = self.getArchiveFilenameList() + files = self.get_filename_list() if archive_file in files: - self.rebuildSevenZipFile([archive_file]) + self.rebuild_zip_file([archive_file]) # now just add the archive file as a new one with py7zr.SevenZipFile(self.path, "a") as zf: @@ -109,7 +109,7 @@ class SevenZipArchiver: except: return False - def getArchiveFilenameList(self): + def get_filename_list(self): try: with py7zr.SevenZipFile(self.path, "r") as zf: namelist = zf.getnames() @@ -119,7 +119,7 @@ class SevenZipArchiver: logger.warning("Unable to get 7zip file list [%s]: %s", e, self.path) return [] - def rebuildSevenZipFile(self, exclude_list): + def rebuild_zip_file(self, exclude_list): """Zip helper func This recompresses the zip archive, without the files in the exclude_list @@ -142,12 +142,12 @@ class SevenZipArchiver: os.remove(self.path) os.rename(tmp_name, self.path) - def copyFromArchive(self, otherArchive): + def copy_from_archive(self, otherArchive): """Replace the current zip with one copied from another archive""" try: with py7zr.SevenZipFile(self.path, "w") as zout: - for fname in otherArchive.getArchiveFilenameList(): - data = otherArchive.readArchiveFile(fname) + for fname in otherArchive.get_filename_list(): + data = otherArchive.read_file(fname) if data is not None: zout.writestr(data, fname) except Exception as e: diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index 10675fc..1533e41 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -152,7 +152,7 @@ class ComicInfoXml: assign("LanguageISO", md.language) assign("Format", md.format) assign("AgeRating", md.maturity_rating) - assign("BlackAndWhite", "Yes" if md.blackAndWhite else None) + assign("BlackAndWhite", "Yes" if md.black_and_white else None) assign("Manga", md.manga) assign("Characters", md.characters) assign("Teams", md.teams) From 1b28623fe3c66bac4c5c2061f8b140b88a37ba2b Mon Sep 17 00:00:00 2001 From: MichaelFitzurka Date: Sun, 3 Apr 2022 15:44:20 -0400 Subject: [PATCH 2/4] Bookmark functionality. Fixes #212. --- comicapi/comicinfoxml.py | 2 +- comictaggerlib/pagelisteditor.py | 50 ++++++++++++++++++++++++++--- comictaggerlib/ui/pagelisteditor.ui | 18 +++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index 1533e41..0858d66 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -168,7 +168,7 @@ class ComicInfoXml: for page_dict in md.pages: page_node = ET.SubElement(pages_node, "Page") - page_node.attrib = page_dict + page_node.attrib = dict(sorted(page_dict.items())) utils.indent(root) diff --git a/comictaggerlib/pagelisteditor.py b/comictaggerlib/pagelisteditor.py index 87f04e0..11f9242 100644 --- a/comictaggerlib/pagelisteditor.py +++ b/comictaggerlib/pagelisteditor.py @@ -97,6 +97,7 @@ class PageListEditor(QtWidgets.QWidget): self.listWidget.itemSelectionChanged.connect(self.change_page) item_move_events(self.listWidget).connect(self.item_move_event) self.comboBox.activated.connect(self.change_page_type) + self.leBookmark.editingFinished.connect(self.save_bookmark) self.btnUp.clicked.connect(self.move_current_up) self.btnDown.clicked.connect(self.move_current_down) self.pre_move_row = -1 @@ -108,6 +109,7 @@ class PageListEditor(QtWidgets.QWidget): def reset_page(self): self.pageWidget.clear() self.comboBox.setDisabled(True) + self.leBookmark.setDisabled(True) self.comic_archive = None self.pages_list = [] @@ -203,6 +205,12 @@ class PageListEditor(QtWidgets.QWidget): i = self.comboBox.findData(pagetype) self.comboBox.setCurrentIndex(i) + if 'Bookmark' in self.listWidget.item(row).data(QtCore.Qt.UserRole)[0]: + self.leBookmark.setText(self.listWidget.item(row) + .data(QtCore.Qt.UserRole)[0]['Bookmark']) + else: + self.leBookmark.setText('') + idx = int(self.listWidget.item(row).data(QtCore.Qt.ItemDataRole.UserRole)[0]["Image"]) if self.comic_archive is not None: @@ -241,11 +249,36 @@ class PageListEditor(QtWidgets.QWidget): item.setData(QtCore.Qt.ItemDataRole.UserRole, (page_dict,)) item.setText(self.list_entry_text(page_dict)) + def save_bookmark(self): + row = self.listWidget.currentRow() + page_dict = self.listWidget.item(row).data(QtCore.Qt.UserRole)[0] + + current_bookmark = '' + if 'Bookmark' in page_dict: + current_bookmark = page_dict['Bookmark'] + + if self.leBookmark.text().strip(): + new_bookmark = str(self.leBookmark.text().strip()) + if current_bookmark != new_bookmark: + page_dict['Bookmark'] = new_bookmark + self.modified.emit() + elif current_bookmark != '': + del(page_dict['Bookmark']) + self.modified.emit() + + item = self.listWidget.item(row) + # wrap the dict in a tuple to keep from being converted to QStrings + item.setData(QtCore.Qt.UserRole, (page_dict,)) + item.setText(self.list_entry_text(page_dict)) + + self.listWidget.setFocus() + def set_data(self, comic_archive: ComicArchive, pages_list: 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.leBookmark.setDisabled(False) self.listWidget.itemSelectionChanged.disconnect(self.change_page) @@ -261,12 +294,14 @@ class PageListEditor(QtWidgets.QWidget): self.listWidget.setCurrentRow(0) def list_entry_text(self, page_dict): - text = str(int(page_dict["Image"]) + 1) - if "Type" in page_dict: - if page_dict["Type"] in self.pageTypeNames.keys(): - text += " (" + self.pageTypeNames[page_dict["Type"]] + ")" + text = str(int(page_dict['Image']) + 1) + if 'Type' in page_dict: + if page_dict['Type'] in self.pageTypeNames.keys(): + text += ' (' + self.pageTypeNames[page_dict['Type']] + ')' else: - text += " (Error: " + page_dict["Type"] + ")" + text += ' (Error: ' + page_dict['Type'] + ')' + if 'Bookmark' in page_dict: + text += ' ' + u'\U0001F516' return text def get_page_list(self): @@ -294,16 +329,20 @@ class PageListEditor(QtWidgets.QWidget): self.btnUp.setEnabled(True) self.btnDown.setEnabled(True) self.comboBox.setEnabled(True) + self.leBookmark.setEnabled(True) self.listWidget.setEnabled(True) + self.leBookmark.setPalette(active_palette) self.listWidget.setPalette(active_palette) elif data_style == MetaDataStyle.CBI: self.btnUp.setEnabled(False) self.btnDown.setEnabled(False) self.comboBox.setEnabled(False) + self.leBookmark.setEnabled(False) self.listWidget.setEnabled(False) + self.leBookmark.setPalette(inactive_palette3) self.listWidget.setPalette(inactive_palette3) elif data_style == MetaDataStyle.COMET: @@ -312,3 +351,4 @@ class PageListEditor(QtWidgets.QWidget): # make sure combo is disabled when no list if self.comic_archive is None: self.comboBox.setEnabled(False) + self.leBookmark.setEnabled(False) diff --git a/comictaggerlib/ui/pagelisteditor.ui b/comictaggerlib/ui/pagelisteditor.ui index 0a95a94..68909b0 100644 --- a/comictaggerlib/ui/pagelisteditor.ui +++ b/comictaggerlib/ui/pagelisteditor.ui @@ -100,6 +100,24 @@ + + + + + + Bookmark: + + + + + + + false + + + + + From ada88d719f23957a4f244076cdc22edefbbb3714 Mon Sep 17 00:00:00 2001 From: MichaelFitzurka Date: Sun, 3 Apr 2022 16:50:27 -0400 Subject: [PATCH 3/4] Empty metadata should not assign an empty tag. --- comicapi/comicinfoxml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index 0858d66..0079f2b 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -67,7 +67,7 @@ class ComicInfoXml: # helper func def assign(cix_entry, md_entry): - if md_entry is not None: + if md_entry is not None and md_entry: et_entry = root.find(cix_entry) if et_entry is not None: et_entry.text = str(md_entry) From 4936c31c18c08207a2592fd7de75f0553da8c0d8 Mon Sep 17 00:00:00 2001 From: MichaelFitzurka Date: Mon, 4 Apr 2022 16:36:46 -0400 Subject: [PATCH 4/4] black changed some single quotes to double quotes. --- comictaggerlib/pagelisteditor.py | 33 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/comictaggerlib/pagelisteditor.py b/comictaggerlib/pagelisteditor.py index 11f9242..45d8c44 100644 --- a/comictaggerlib/pagelisteditor.py +++ b/comictaggerlib/pagelisteditor.py @@ -205,11 +205,10 @@ class PageListEditor(QtWidgets.QWidget): i = self.comboBox.findData(pagetype) self.comboBox.setCurrentIndex(i) - if 'Bookmark' in self.listWidget.item(row).data(QtCore.Qt.UserRole)[0]: - self.leBookmark.setText(self.listWidget.item(row) - .data(QtCore.Qt.UserRole)[0]['Bookmark']) + if "Bookmark" in self.listWidget.item(row).data(QtCore.Qt.UserRole)[0]: + self.leBookmark.setText(self.listWidget.item(row).data(QtCore.Qt.UserRole)[0]["Bookmark"]) else: - self.leBookmark.setText('') + self.leBookmark.setText("") idx = int(self.listWidget.item(row).data(QtCore.Qt.ItemDataRole.UserRole)[0]["Image"]) @@ -253,17 +252,17 @@ class PageListEditor(QtWidgets.QWidget): row = self.listWidget.currentRow() page_dict = self.listWidget.item(row).data(QtCore.Qt.UserRole)[0] - current_bookmark = '' - if 'Bookmark' in page_dict: - current_bookmark = page_dict['Bookmark'] + current_bookmark = "" + if "Bookmark" in page_dict: + current_bookmark = page_dict["Bookmark"] if self.leBookmark.text().strip(): new_bookmark = str(self.leBookmark.text().strip()) if current_bookmark != new_bookmark: - page_dict['Bookmark'] = new_bookmark + page_dict["Bookmark"] = new_bookmark self.modified.emit() - elif current_bookmark != '': - del(page_dict['Bookmark']) + elif current_bookmark != "": + del page_dict["Bookmark"] self.modified.emit() item = self.listWidget.item(row) @@ -294,14 +293,14 @@ class PageListEditor(QtWidgets.QWidget): self.listWidget.setCurrentRow(0) def list_entry_text(self, page_dict): - text = str(int(page_dict['Image']) + 1) - if 'Type' in page_dict: - if page_dict['Type'] in self.pageTypeNames.keys(): - text += ' (' + self.pageTypeNames[page_dict['Type']] + ')' + text = str(int(page_dict["Image"]) + 1) + if "Type" in page_dict: + if page_dict["Type"] in self.pageTypeNames.keys(): + text += " (" + self.pageTypeNames[page_dict["Type"]] + ")" else: - text += ' (Error: ' + page_dict['Type'] + ')' - if 'Bookmark' in page_dict: - text += ' ' + u'\U0001F516' + text += " (Error: " + page_dict["Type"] + ")" + if "Bookmark" in page_dict: + text += " " + "\U0001F516" return text def get_page_list(self):