Improved epub cover image search, simplified function naming

This commit is contained in:
BasioMeusPuga
2017-11-14 16:07:30 +05:30
parent e3ad37022a
commit 390c33af62
7 changed files with 55 additions and 56 deletions

View File

@@ -144,7 +144,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.listView.verticalScrollBar().setSingleStep(7)
self.listView.doubleClicked.connect(self.list_doubleclick)
self.listView.setItemDelegate(LibraryDelegate(self.temp_dir.path()))
self.reload_listview()
self.lib_ref.generate_model('build')
self.lib_ref.create_proxymodel()
# Keyboard shortcuts
self.exit_all = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self)
@@ -208,13 +209,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
for i in selected_books:
data = i.data(QtCore.Qt.UserRole + 3)
selected_hashes.append(data['hash'])
database.DatabaseFunctions(
self.database_path).delete_from_database(selected_hashes)
self.viewModel = None # TODO
# Delete the item from the model instead
# of reconstructing it
# The same goes for addition
self.reload_listview()
self.lib_ref.generate_model('build')
self.lib_ref.create_proxymodel()
selected_number = len(selected_books)
msg_box = QtWidgets.QMessageBox()
@@ -227,10 +227,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
msg_box.show()
msg_box.exec_()
def reload_listview(self):
if not self.viewModel:
self.lib_ref.generate_model('build')
def tab_switch(self):
if self.tabWidget.currentIndex() == 0:
@@ -282,13 +278,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# We're also updating the underlying model to have real-time
# updates on the read status
# Find index of the model item that corresponds to the tab
# Set a baseline model index in case the item gets deleted
# E.g It's open in a tab and deleted from the library
model_index = None
start_index = self.viewModel.index(0, 0)
# Find index of the model item that corresponds to the tab
matching_item = self.viewModel.match(
start_index,
QtCore.Qt.UserRole + 6,

View File

@@ -127,9 +127,15 @@ class DatabaseFunctions:
# file_hashes is expected as a list that will be iterated upon
# This should enable multiple deletion
for i in file_hashes:
self.database.execute(
f"DELETE FROM books WHERE Hash = '{i}'")
first = file_hashes[0]
sql_command = f"DELETE FROM books WHERE Hash = '{first}'"
if len(file_hashes) > 1:
for i in file_hashes[1:]:
sql_command += f" OR Hash = '{i}'"
self.database.execute(sql_command)
self.database.commit()
self.close_database()

View File

@@ -121,8 +121,6 @@ class Library:
item.setIcon(QtGui.QIcon(img_pixmap))
self.parent_window.viewModel.appendRow(item)
self.create_proxymodel()
def create_proxymodel(self):
self.proxy_model = QtCore.QSortFilterProxyModel()
self.proxy_model.setSourceModel(self.parent_window.viewModel)

View File

@@ -58,38 +58,38 @@ class ParseEPUB:
cover_item = self.book.get_item_with_id(cover)
if cover_item:
return cover_item.get_content()
# In case no cover_item is returned,
# we look for a cover in the guide
for j in self.book.guide:
try:
if (j['title'].lower in ['cover', 'cover-image', 'coverimage'] or
j['type'] == 'coverimagestandard'):
image_path = j['href']
break
except KeyError:
pass
# And if all else fails, we find
# the first image referenced in the book
# Fuck everything
if not image_path:
for j in self.book.items:
if j.media_type == 'application/xhtml+xml':
_regex = re.search(r"src=\"(.*)\"\/", j.content.decode('utf-8'))
if _regex:
image_path = _regex[1]
break
for k in self.book.get_items_of_type(ebooklib.ITEM_IMAGE):
if os.path.basename(k.file_name) == os.path.basename(image_path):
image_content = k.get_content()
break
return image_content
except KeyError:
return None
pass
# In case no cover_item is returned, we look for a cover in the guide
for i in self.book.guide:
try:
if (i['title'].lower in ['cover', 'cover-image', 'coverimage'] or
i['type'] == 'coverimagestandard'):
image_path = i['href']
break
except KeyError:
pass
# If that fails, we find the first image referenced in the book
if not image_path:
for i in self.book.items:
if i.media_type == 'application/xhtml+xml':
_regex = re.search(r"src=\"(.*)\"\/", i.content.decode('utf-8'))
if _regex:
image_path = _regex[1]
break
if image_path:
for i in self.book.get_items_of_type(ebooklib.ITEM_IMAGE):
if os.path.basename(i.file_name) == os.path.basename(image_path):
return i.get_content()
# And if that too fails, we get the first image referenced in the file
for i in self.book.items:
if i.media_type == 'image/jpeg' or i.media_type == 'image/png':
return i.get_content()
def get_isbn(self):
try:

View File

@@ -59,7 +59,7 @@ class GeneratePie():
lPath = "%s %s %s" % (lLineOne, lArc, lLineTwo)
lGradient = GRADIENTS[lIndex]
lSvgPath += "<path d='%s' style='stroke:#c579be; fill:url(#%s);'/>" % (
lSvgPath += "<path d='%s' style='stroke:#097b8c; fill:url(#%s);'/>" % (
lPath, lGradient)
lIndex += 1
@@ -68,19 +68,19 @@ class GeneratePie():
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<radialGradient id="myRadialGradientGreen" r="65%%" cx="0" cy="0" spreadMethod="pad">
<stop offset="0%%" stop-color="#c579be" stop-opacity="1"/>
<stop offset="100%%" stop-color="#c579be" stop-opacity="1" />
<stop offset="0%%" stop-color="#11e0ff" stop-opacity="1"/>
<stop offset="100%%" stop-color="#11e0ff" stop-opacity="1" />
</radialGradient>
</defs>
<defs>
<radialGradient id="myRadialGradientOrange" r="65%%" cx="0" cy="0" spreadMethod="pad">
<stop offset="0%%" stop-color="#6c4268" stop-opacity="1"/>
<stop offset="100%%" stop-color="#6c4268" stop-opacity="1" />
<stop offset="0%%" stop-color="#097b8c" stop-opacity="1"/>
<stop offset="100%%" stop-color="#097b8c" stop-opacity="1" />
</radialGradient>
</defs>
%s
<!-- <circle cx="%d" cy="%d" r="100" style="stroke:#6c4268; fill:none;"/> -->
<!-- <circle cx="%d" cy="%d" r="100" style="stroke:#097b8c; fill:none;"/> -->
</svg>
""" % (lSvgPath, lOffsetX, lOffsetY)

BIN
resources/NotFound.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -360,7 +360,7 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate):
QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
pie_chart.GeneratePie(progress_percent, self.temp_dir).generate()
svg_path = os.path.join(self.temp_dir, 'lector_progress.svg')
read_icon = QtGui.QIcon(svg_path).pixmap(34)
read_icon = QtGui.QIcon(svg_path).pixmap(32)
x_draw = option.rect.bottomRight().x() - 30
y_draw = option.rect.bottomRight().y() - 35