Cover image culling
This commit is contained in:
		
							
								
								
									
										63
									
								
								__main__.py
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								__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) |         blank_pixmap = QtGui.QPixmap() | ||||||
|         top_item = self.lib_ref.view_model.item(model_index.row()) |         blank_pixmap.load(':/images/blank.png') | ||||||
|  |  | ||||||
|  |         all_indexes = set() | ||||||
|  |         for i in range(self.lib_ref.proxy_model.rowCount()): | ||||||
|  |             all_indexes.add(self.lib_ref.proxy_model.index(i, 0)) | ||||||
|  |  | ||||||
|  |         y_range = range(-20, self.listView.viewport().height(), 10) | ||||||
|  |         x_range = range(0, self.listView.viewport().width(), 80) | ||||||
|  |  | ||||||
|  |         visible_indexes = set() | ||||||
|  |         for i in y_range: | ||||||
|  |             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) | ||||||
|  |  | ||||||
|         if top_item: |  | ||||||
|                 img_pixmap = QtGui.QPixmap() |                 img_pixmap = QtGui.QPixmap() | ||||||
|             img_pixmap.load(':/images/blank.png') |                 if cover: | ||||||
|             top_item.setIcon(QtGui.QIcon(img_pixmap)) |                     img_pixmap.loadFromData(cover) | ||||||
|                 else: |                 else: | ||||||
|             print('Invalid index') |                     img_pixmap.load(':/images/NotFound.png') | ||||||
|  |                 img_pixmap = img_pixmap.scaled(420, 600, QtCore.Qt.IgnoreAspectRatio) | ||||||
|     def cull_covers(self): |                 this_item.setIcon(QtGui.QIcon(img_pixmap)) | ||||||
|         # TODO |  | ||||||
|         # Use this to reduce memory utilization |  | ||||||
|  |  | ||||||
|         img_pixmap = QtGui.QPixmap() |  | ||||||
|         img_pixmap.load(':/images/blank.png') |  | ||||||
|  |  | ||||||
|         for i in range(self.lib_ref.view_model.rowCount()): |  | ||||||
|             item = self.lib_ref.view_model.item(i) |  | ||||||
|             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