Cover image culling
This commit is contained in:
61
__main__.py
61
__main__.py
@@ -219,28 +219,53 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
if self.settings['scan_library']:
|
if self.settings['scan_library']:
|
||||||
self.settings_dialog.start_library_scan()
|
self.settings_dialog.start_library_scan()
|
||||||
|
|
||||||
def test_function(self, event=None):
|
def cull_covers(self, event=None):
|
||||||
top_index = self.listView.indexAt(QtCore.QPoint(20, 20))
|
|
||||||
model_index = self.lib_ref.proxy_model.mapToSource(top_index)
|
|
||||||
top_item = self.lib_ref.view_model.item(model_index.row())
|
|
||||||
|
|
||||||
if top_item:
|
blank_pixmap = QtGui.QPixmap()
|
||||||
img_pixmap = QtGui.QPixmap()
|
blank_pixmap.load(':/images/blank.png')
|
||||||
img_pixmap.load(':/images/blank.png')
|
|
||||||
top_item.setIcon(QtGui.QIcon(img_pixmap))
|
|
||||||
else:
|
|
||||||
print('Invalid index')
|
|
||||||
|
|
||||||
def cull_covers(self):
|
all_indexes = set()
|
||||||
# TODO
|
for i in range(self.lib_ref.proxy_model.rowCount()):
|
||||||
# Use this to reduce memory utilization
|
all_indexes.add(self.lib_ref.proxy_model.index(i, 0))
|
||||||
|
|
||||||
img_pixmap = QtGui.QPixmap()
|
y_range = range(-20, self.listView.viewport().height(), 10)
|
||||||
img_pixmap.load(':/images/blank.png')
|
x_range = range(0, self.listView.viewport().width(), 80)
|
||||||
|
|
||||||
for i in range(self.lib_ref.view_model.rowCount()):
|
visible_indexes = set()
|
||||||
item = self.lib_ref.view_model.item(i)
|
for i in y_range:
|
||||||
item.setIcon(QtGui.QIcon(img_pixmap))
|
for j in x_range:
|
||||||
|
this_index = self.listView.indexAt(QtCore.QPoint(j, i))
|
||||||
|
visible_indexes.add(this_index)
|
||||||
|
|
||||||
|
invisible_indexes = all_indexes - visible_indexes
|
||||||
|
for i in invisible_indexes:
|
||||||
|
model_index = self.lib_ref.proxy_model.mapToSource(i)
|
||||||
|
this_item = self.lib_ref.view_model.item(model_index.row())
|
||||||
|
|
||||||
|
if this_item:
|
||||||
|
this_item.setIcon(QtGui.QIcon(blank_pixmap))
|
||||||
|
|
||||||
|
for i in visible_indexes:
|
||||||
|
model_index = self.lib_ref.proxy_model.mapToSource(i)
|
||||||
|
this_item = self.lib_ref.view_model.item(model_index.row())
|
||||||
|
|
||||||
|
if this_item:
|
||||||
|
book_hash = this_item.data(QtCore.Qt.UserRole + 6)
|
||||||
|
cover = database.DatabaseFunctions(
|
||||||
|
self.database_path).fetch_data(
|
||||||
|
('CoverImage',),
|
||||||
|
'books',
|
||||||
|
{'Hash': book_hash},
|
||||||
|
'EQUALS',
|
||||||
|
True)
|
||||||
|
|
||||||
|
img_pixmap = QtGui.QPixmap()
|
||||||
|
if cover:
|
||||||
|
img_pixmap.loadFromData(cover)
|
||||||
|
else:
|
||||||
|
img_pixmap.load(':/images/NotFound.png')
|
||||||
|
img_pixmap = img_pixmap.scaled(420, 600, QtCore.Qt.IgnoreAspectRatio)
|
||||||
|
this_item.setIcon(QtGui.QIcon(img_pixmap))
|
||||||
|
|
||||||
def resizeEvent(self, event=None):
|
def resizeEvent(self, event=None):
|
||||||
if event:
|
if event:
|
||||||
|
Reference in New Issue
Block a user