Toggle cover culling
This commit is contained in:
		
							
								
								
									
										44
									
								
								__main__.py
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								__main__.py
									
									
									
									
									
								
							| @@ -274,17 +274,43 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|                         '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)) | ||||
|                 this_item.setData(True, QtCore.Qt.UserRole + 8) | ||||
|                 self.cover_loader(this_item, cover) | ||||
|  | ||||
|     def start_culling_timer(self): | ||||
|         self.culling_timer.start(30) | ||||
|         if self.settings['perform_culling']: | ||||
|             self.culling_timer.start(30) | ||||
|  | ||||
|     def load_all_covers(self): | ||||
|         all_covers_db = database.DatabaseFunctions( | ||||
|             self.database_path).fetch_data( | ||||
|                 ('Hash', 'CoverImage',), | ||||
|                 'books', | ||||
|                 {'Hash': ''}, | ||||
|                 'LIKE') | ||||
|  | ||||
|         all_covers = { | ||||
|             i[0]: i[1] for i in all_covers_db} | ||||
|  | ||||
|         for i in range(self.lib_ref.view_model.rowCount()): | ||||
|             this_item = self.lib_ref.view_model.item(i, 0) | ||||
|  | ||||
|             is_cover_already_displayed = this_item.data(QtCore.Qt.UserRole + 8) | ||||
|             if is_cover_already_displayed: | ||||
|                 continue | ||||
|  | ||||
|             book_hash = this_item.data(QtCore.Qt.UserRole + 6) | ||||
|             cover = all_covers[book_hash] | ||||
|             self.cover_loader(this_item, cover) | ||||
|  | ||||
|     def cover_loader(self, item, cover): | ||||
|         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) | ||||
|         item.setIcon(QtGui.QIcon(img_pixmap)) | ||||
|         item.setData(True, QtCore.Qt.UserRole + 8) | ||||
|  | ||||
|     def test_function(self): | ||||
|         print('Caesar si viveret, ad remum dareris') | ||||
|   | ||||
| @@ -137,6 +137,9 @@ class Library: | ||||
|             self.table_rows.append( | ||||
|                 [title, author, None, year, tags, all_metadata, i[8]]) | ||||
|  | ||||
|         if not self.parent.settings['perform_culling']: | ||||
|             self.parent.load_all_covers() | ||||
|  | ||||
|     def create_table_model(self): | ||||
|         table_header = ['Title', 'Author', 'Status', 'Year', 'Tags'] | ||||
|         self.table_model = MostExcellentTableModel( | ||||
|   | ||||
| @@ -80,6 +80,43 @@ | ||||
|           </item> | ||||
|          </layout> | ||||
|         </item> | ||||
|         <item row="1" column="0"> | ||||
|          <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|           <item> | ||||
|            <spacer name="horizontalSpacer"> | ||||
|             <property name="orientation"> | ||||
|              <enum>Qt::Horizontal</enum> | ||||
|             </property> | ||||
|             <property name="sizeHint" stdset="0"> | ||||
|              <size> | ||||
|               <width>40</width> | ||||
|               <height>20</height> | ||||
|              </size> | ||||
|             </property> | ||||
|            </spacer> | ||||
|           </item> | ||||
|           <item> | ||||
|            <widget class="QCheckBox" name="performCulling"> | ||||
|             <property name="text"> | ||||
|              <string>Load covers only when needed</string> | ||||
|             </property> | ||||
|            </widget> | ||||
|           </item> | ||||
|           <item> | ||||
|            <spacer name="horizontalSpacer_2"> | ||||
|             <property name="orientation"> | ||||
|              <enum>Qt::Horizontal</enum> | ||||
|             </property> | ||||
|             <property name="sizeHint" stdset="0"> | ||||
|              <size> | ||||
|               <width>40</width> | ||||
|               <height>20</height> | ||||
|              </size> | ||||
|             </property> | ||||
|            </spacer> | ||||
|           </item> | ||||
|          </layout> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </widget> | ||||
|      </item> | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
|  | ||||
| # Form implementation generated from reading ui file 'raw/settings.ui' | ||||
| # | ||||
| # Created by: PyQt5 UI code generator 5.9.2 | ||||
| # Created by: PyQt5 UI code generator 5.10 | ||||
| # | ||||
| # WARNING! All changes made in this file will be lost! | ||||
|  | ||||
| @@ -51,6 +51,16 @@ class Ui_Dialog(object): | ||||
|         self.horizontalLayout_4.addWidget(self.autoTags) | ||||
|         self.verticalLayout.addLayout(self.horizontalLayout_4) | ||||
|         self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1) | ||||
|         self.horizontalLayout = QtWidgets.QHBoxLayout() | ||||
|         self.horizontalLayout.setObjectName("horizontalLayout") | ||||
|         spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) | ||||
|         self.horizontalLayout.addItem(spacerItem) | ||||
|         self.performCulling = QtWidgets.QCheckBox(self.groupBox) | ||||
|         self.performCulling.setObjectName("performCulling") | ||||
|         self.horizontalLayout.addWidget(self.performCulling) | ||||
|         spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) | ||||
|         self.horizontalLayout.addItem(spacerItem1) | ||||
|         self.gridLayout.addLayout(self.horizontalLayout, 1, 0, 1, 1) | ||||
|         self.verticalLayout_2.addWidget(self.groupBox) | ||||
|         self.gridLayout_3.addLayout(self.verticalLayout_2, 0, 0, 1, 1) | ||||
|         self.horizontalLayout_2 = QtWidgets.QHBoxLayout() | ||||
| @@ -78,6 +88,7 @@ class Ui_Dialog(object): | ||||
|         self.fileRemember.setText(_translate("Dialog", "Remember open files")) | ||||
|         self.coverShadows.setText(_translate("Dialog", "Cover shadows")) | ||||
|         self.autoTags.setText(_translate("Dialog", "Generate tags from files")) | ||||
|         self.performCulling.setText(_translate("Dialog", "Load covers only when needed")) | ||||
|         self.okButton.setText(_translate("Dialog", "OK")) | ||||
|         self.cancelButton.setText(_translate("Dialog", "Cancel")) | ||||
|         self.aboutButton.setText(_translate("Dialog", "About")) | ||||
|   | ||||
| @@ -89,6 +89,8 @@ class Settings: | ||||
|             'scanLibraryAtStart', 'False').capitalize()) | ||||
|         self.parent.settings['remember_files'] = literal_eval(self.settings.value( | ||||
|             'rememberFiles', 'False').capitalize()) | ||||
|         self.parent.settings['perform_culling'] = literal_eval(self.settings.value( | ||||
|             'performCulling', 'True').capitalize()) | ||||
|         self.settings.endGroup() | ||||
|  | ||||
|     def save_settings(self): | ||||
| @@ -147,4 +149,5 @@ class Settings: | ||||
|         self.settings.setValue('coverShadows', current_settings['cover_shadows']) | ||||
|         self.settings.setValue('autoTags', current_settings['auto_tags']) | ||||
|         self.settings.setValue('scanLibraryAtStart', current_settings['scan_library']) | ||||
|         self.settings.setValue('performCulling', current_settings['perform_culling']) | ||||
|         self.settings.endGroup() | ||||
|   | ||||
| @@ -59,11 +59,13 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog): | ||||
|         self.coverShadows.setChecked(self.parent.settings['cover_shadows']) | ||||
|         self.refreshLibrary.setChecked(self.parent.settings['scan_library']) | ||||
|         self.fileRemember.setChecked(self.parent.settings['remember_files']) | ||||
|         self.performCulling.setChecked(self.parent.settings['perform_culling']) | ||||
|  | ||||
|         self.autoTags.clicked.connect(self.manage_checkboxes) | ||||
|         self.coverShadows.clicked.connect(self.manage_checkboxes) | ||||
|         self.refreshLibrary.clicked.connect(self.manage_checkboxes) | ||||
|         self.fileRemember.clicked.connect(self.manage_checkboxes) | ||||
|         self.performCulling.clicked.connect(self.manage_checkboxes) | ||||
|  | ||||
|         # Generate the filesystem treeView | ||||
|         self.generate_tree() | ||||
| @@ -234,10 +236,14 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog): | ||||
|             'coverShadows': 'cover_shadows', | ||||
|             'autoTags': 'auto_tags', | ||||
|             'refreshLibrary': 'scan_library', | ||||
|             'fileRemember': 'remember_files'} | ||||
|             'fileRemember': 'remember_files', | ||||
|             'performCulling': 'perform_culling'} | ||||
|  | ||||
|         self.parent.settings[sender_dict[sender]] = not self.parent.settings[sender_dict[sender]] | ||||
|  | ||||
|         if not self.performCulling.isChecked(): | ||||
|             self.parent.load_all_covers() | ||||
|  | ||||
|     def about_pressed(self): | ||||
|         self.treeView.setVisible(not self.treeView.isVisible()) | ||||
|         self.aboutBox.setVisible(not self.aboutBox.isVisible()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user