From 1b28623fe3c66bac4c5c2061f8b140b88a37ba2b Mon Sep 17 00:00:00 2001 From: MichaelFitzurka Date: Sun, 3 Apr 2022 15:44:20 -0400 Subject: [PATCH] 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 + + + + +