Merge branch 'MichaelFitzurka-feature/247-empty-tags' into develop

This commit is contained in:
Timmy Welch 2022-04-04 14:16:29 -07:00
commit 2db80399a6
4 changed files with 73 additions and 16 deletions

View File

@ -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:

View File

@ -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)
@ -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)
@ -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)

View File

@ -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,11 @@ 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 +248,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)
@ -267,6 +299,8 @@ class PageListEditor(QtWidgets.QWidget):
text += " (" + self.pageTypeNames[page_dict["Type"]] + ")"
else:
text += " (Error: " + page_dict["Type"] + ")"
if "Bookmark" in page_dict:
text += " " + "\U0001F516"
return text
def get_page_list(self):
@ -294,16 +328,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 +350,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)

View File

@ -100,6 +100,24 @@
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Bookmark:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leBookmark">
<property name="acceptDrops">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="pageContainer" native="true">
<property name="sizePolicy">