Mouse cursor hiding implemented for comics view, Tab focus fixed
This commit is contained in:
		
							
								
								
									
										4
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								TODO
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ TODO | ||||
|     Options: | ||||
|         Automatic library management | ||||
|             ✓ Recursive file addition | ||||
|             Auto deletion | ||||
|             ✓ Auto deletion | ||||
|             Add only one file type if multiple are present | ||||
|         ✓ Remember files | ||||
|         ✓ Check files (hashes) upon restart | ||||
| @@ -17,8 +17,8 @@ TODO | ||||
|         ✓ Shift focus to the tab that has the book open | ||||
|         ✓ Tie file deletion and tab closing to model updates | ||||
|         ✓ Create separate thread for parser - Show progress in main window | ||||
|         ✓ Memory management | ||||
|         ? Create emblem per filetype | ||||
|         Memory management | ||||
|         Table view | ||||
|         Ignore a / the / numbers for sorting purposes | ||||
|         Put the path in the scope of the search | ||||
|   | ||||
							
								
								
									
										41
									
								
								__main__.py
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								__main__.py
									
									
									
									
									
								
							| @@ -43,12 +43,11 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|  | ||||
|         # Empty variables that will be infested soon | ||||
|         self.settings = {} | ||||
|         self.last_open_tab = None | ||||
|         self.last_open_path = None | ||||
|         self.thread = None  # Background Thread | ||||
|         self.current_contentView = None  # For fullscreening purposes | ||||
|         self.display_profiles = None | ||||
|         self.current_profile_index = None | ||||
|         self.comic_profile = {} | ||||
|         self.database_path = None | ||||
|         self.library_filter_menu = None | ||||
|  | ||||
| @@ -176,7 +175,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|         self.reloadLibrary.setObjectName('reloadLibrary') | ||||
|         self.reloadLibrary.setAutoRaise(True) | ||||
|         self.reloadLibrary.clicked.connect(self.settings_dialog.start_library_scan) | ||||
|         # self.reloadLibrary.clicked.connect(self.cull_covers)  # TODO | ||||
|  | ||||
|         self.tabWidget.tabBar().setTabButton( | ||||
|             0, QtWidgets.QTabBar.RightSide, self.reloadLibrary) | ||||
| @@ -233,7 +231,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|         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) | ||||
|         y_range = list(range(0, self.listView.viewport().height(), 100)) | ||||
|         y_range.extend((-20, self.listView.viewport().height() + 20)) | ||||
|         x_range = range(0, self.listView.viewport().width(), 80) | ||||
|  | ||||
|         visible_indexes = set() | ||||
| @@ -279,7 +278,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|                 this_item.setData(True, QtCore.Qt.UserRole + 8) | ||||
|  | ||||
|     def start_culling_timer(self): | ||||
|         self.culling_timer.start(50) | ||||
|         self.culling_timer.start(30) | ||||
|  | ||||
|     def test_function(self): | ||||
|         print('Caesar si viveret, ad remum dareris') | ||||
| @@ -315,6 +314,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|             layout_extra_space_per_image = space_left // num_images | ||||
|             self.listView.setGridSize( | ||||
|                 QtCore.QSize(default_size + layout_extra_space_per_image, 250)) | ||||
|             self.start_culling_timer() | ||||
|         except ZeroDivisionError:  # Initial resize is ignored | ||||
|             return | ||||
|  | ||||
| @@ -325,7 +325,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|         # from the libary in case of a database refresh | ||||
|  | ||||
|         opened_files = QtWidgets.QFileDialog.getOpenFileNames( | ||||
|             self, 'Open file', self.last_open_path, | ||||
|             self, 'Open file', self.settings['last_open_path'], | ||||
|             f'eBooks ({self.available_parsers})') | ||||
|  | ||||
|         if not opened_files[0]: | ||||
| @@ -334,7 +334,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|         self.settings_dialog.okButton.setEnabled(False) | ||||
|         self.reloadLibrary.setEnabled(False) | ||||
|  | ||||
|         self.last_open_path = os.path.dirname(opened_files[0][0]) | ||||
|         self.settings['last_open_path'] = os.path.dirname(opened_files[0][0]) | ||||
|         self.sorterProgress.setVisible(True) | ||||
|         self.statusMessage.setText('Adding books...') | ||||
|         self.thread = BackGroundBookAddition( | ||||
| @@ -424,6 +424,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|         if self.tabWidget.currentIndex() == 0: | ||||
|  | ||||
|             self.resizeEvent() | ||||
|             self.start_culling_timer() | ||||
|             if self.settings['show_toolbars']: | ||||
|                 self.bookToolBar.hide() | ||||
|                 self.libraryToolBar.show() | ||||
| @@ -576,20 +577,26 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): | ||||
|             True, | ||||
|             self.temp_dir.path()).initiate_threads() | ||||
|  | ||||
|         found_a_focusable_tab = False | ||||
|  | ||||
|         for i in contents: | ||||
|             # New tabs are created here | ||||
|             # Initial position adjustment is carried out by the tab itself | ||||
|             file_data = contents[i] | ||||
|             Tab(file_data, self.tabWidget)  # New tabs are created here | ||||
|                                             # Initial position adjustment | ||||
|                                             # is carried out by the tab itself | ||||
|             if file_data['path'] == self.last_open_tab: | ||||
|                 found_a_focusable_tab = True | ||||
|                 self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1) | ||||
|             Tab(file_data, self.tabWidget) | ||||
|  | ||||
|         if not found_a_focusable_tab: | ||||
|             self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1) | ||||
|         if self.settings['last_open_tab'] == 'library': | ||||
|             self.tabWidget.setCurrentIndex(0) | ||||
|             self.listView.setFocus() | ||||
|             self.settings['last_open_tab'] = None | ||||
|             return | ||||
|  | ||||
|         for i in range(1, self.tabWidget.count()): | ||||
|             this_path = self.tabWidget.widget(i).metadata['path'] | ||||
|             if self.settings['last_open_tab'] == this_path: | ||||
|                 self.tabWidget.setCurrentIndex(i) | ||||
|                 self.settings['last_open_tab'] = None | ||||
|                 return | ||||
|  | ||||
|         self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1) | ||||
|         self.format_contentView() | ||||
|  | ||||
|     def get_color(self): | ||||
|   | ||||
| @@ -52,7 +52,7 @@ class Settings: | ||||
|         self.settings.endGroup() | ||||
|  | ||||
|         self.settings.beginGroup('runtimeVariables') | ||||
|         self.parent.last_open_path = self.settings.value( | ||||
|         self.parent.settings['last_open_path'] = self.settings.value( | ||||
|             'lastOpenPath', os.path.expanduser('~')) | ||||
|         self.parent.database_path = self.settings.value( | ||||
|             'databasePath', | ||||
| @@ -67,7 +67,7 @@ class Settings: | ||||
|  | ||||
|         self.settings.beginGroup('lastOpen') | ||||
|         self.parent.settings['last_open_books'] = self.settings.value('lastOpenBooks', []) | ||||
|         self.parent.last_open_tab = self.settings.value('lastOpenTab', 'library') | ||||
|         self.parent.settings['last_open_tab'] = self.settings.value('lastOpenTab', 'library') | ||||
|         self.settings.endGroup() | ||||
|  | ||||
|         self.settings.beginGroup('settingsWindow') | ||||
| @@ -107,7 +107,7 @@ class Settings: | ||||
|         self.settings.endGroup() | ||||
|  | ||||
|         self.settings.beginGroup('runtimeVariables') | ||||
|         self.settings.setValue('lastOpenPath', self.parent.last_open_path) | ||||
|         self.settings.setValue('lastOpenPath', self.parent.settings['last_open_path']) | ||||
|         self.settings.setValue('databasePath', self.parent.database_path) | ||||
|  | ||||
|         current_profile1 = self.parent.bookToolBar.profileBox.itemData( | ||||
|   | ||||
							
								
								
									
										31
									
								
								widgets.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								widgets.py
									
									
									
									
									
								
							| @@ -408,10 +408,10 @@ class Tab(QtWidgets.QWidget): | ||||
|         self.are_we_doing_images_only = self.metadata['images_only'] | ||||
|  | ||||
|         if self.are_we_doing_images_only:  # Boolean | ||||
|             self.contentView = PliantQGraphicsView(self.window()) | ||||
|             self.contentView = PliantQGraphicsView(self.window(), self) | ||||
|             self.contentView.loadImage(chapter_content) | ||||
|         else: | ||||
|             self.contentView = PliantQTextBrowser(self.window()) | ||||
|             self.contentView = PliantQTextBrowser(self.window(), self) | ||||
|             # print(dir(self.contentView.document()))  ## TODO USE this for modifying formatting and searching | ||||
|  | ||||
|             relative_path_root = os.path.join( | ||||
| @@ -449,6 +449,11 @@ class Tab(QtWidgets.QWidget): | ||||
|         title = self.metadata['title'] | ||||
|         self.parent.addTab(self, title) | ||||
|  | ||||
|         # Hide mouse cursor timer | ||||
|         self.mouse_hide_timer = QtCore.QTimer() | ||||
|         self.mouse_hide_timer.setSingleShot(True) | ||||
|         self.mouse_hide_timer.timeout.connect(self.hide_mouse) | ||||
|  | ||||
|         self.contentView.setFocus() | ||||
|  | ||||
|     def generate_position(self): | ||||
| @@ -544,6 +549,9 @@ class Tab(QtWidgets.QWidget): | ||||
|         else: | ||||
|             self.dockWidget.show() | ||||
|  | ||||
|     def hide_mouse(self): | ||||
|         self.contentView.setCursor(QtCore.Qt.BlankCursor) | ||||
|  | ||||
|     def sneaky_change(self): | ||||
|         direction = -1 | ||||
|         if self.sender().objectName() == 'nextChapter': | ||||
| @@ -561,11 +569,13 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView): | ||||
|     def __init__(self, main_window, parent=None): | ||||
|         super(PliantQGraphicsView, self).__init__(parent) | ||||
|         self.main_window = main_window | ||||
|         self.parent = parent | ||||
|         self.image_pixmap = None | ||||
|         self.ignore_wheel_event = False | ||||
|         self.ignore_wheel_event_number = 0 | ||||
|         self.common_functions = PliantWidgetsCommonFunctions( | ||||
|             self, self.main_window) | ||||
|         self.setMouseTracking(True) | ||||
|  | ||||
|     def loadImage(self, image_path): | ||||
|         self.image_pixmap = QtGui.QPixmap() | ||||
| @@ -633,15 +643,21 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView): | ||||
|                 scroll_increment = int((maximum - 0) / 2) | ||||
|                 self.verticalScrollBar().setValue(vertical + scroll_increment) | ||||
|  | ||||
|     def mouseMoveEvent(self, event): | ||||
|         self.setCursor(QtCore.Qt.ArrowCursor) | ||||
|         self.parent.mouse_hide_timer.start(3000) | ||||
|  | ||||
|  | ||||
| class PliantQTextBrowser(QtWidgets.QTextBrowser): | ||||
|     def __init__(self, main_window, parent=None): | ||||
|         super(PliantQTextBrowser, self).__init__(parent) | ||||
|         self.main_window = main_window | ||||
|         self.parent = parent | ||||
|         self.ignore_wheel_event = False | ||||
|         self.ignore_wheel_event_number = 0 | ||||
|         self.common_functions = PliantWidgetsCommonFunctions( | ||||
|             self, self.main_window) | ||||
|         self.setMouseTracking(True) | ||||
|  | ||||
|     def wheelEvent(self, event): | ||||
|         self.common_functions.wheelEvent(event, False) | ||||
| @@ -659,6 +675,13 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser): | ||||
|         else: | ||||
|             QtWidgets.QTextBrowser.keyPressEvent(self, event) | ||||
|  | ||||
|     # def mouseMoveEvent(self, event): | ||||
|         # TODO | ||||
|         # This does not work as expected | ||||
|         # event.accept() | ||||
|         # self.setCursor(QtCore.Qt.ArrowCursor) | ||||
|         # self.parent.mouse_hide_timer.start(3000) | ||||
|  | ||||
|  | ||||
| class PliantWidgetsCommonFunctions(): | ||||
|     def __init__(self, parent_widget, main_window): | ||||
| @@ -686,7 +709,7 @@ class PliantWidgetsCommonFunctions(): | ||||
|         elif vertical_pdelta < 0: | ||||
|             moving_up = False | ||||
|  | ||||
|         if abs(vertical_pdelta) > 100:  # Adjust sensitivity here | ||||
|         if abs(vertical_pdelta) > 80:  # Adjust sensitivity here | ||||
|             # Implies that no scrollbar movement is possible | ||||
|             if self.pw.verticalScrollBar().value() == self.pw.verticalScrollBar().maximum() == 0: | ||||
|                 if moving_up: | ||||
| @@ -721,7 +744,7 @@ class PliantWidgetsCommonFunctions(): | ||||
|  | ||||
|             if not was_button_pressed: | ||||
|                 self.pw.ignore_wheel_event = True | ||||
|  | ||||
|      | ||||
|  | ||||
| class LibraryDelegate(QtWidgets.QStyledItemDelegate): | ||||
|     def __init__(self, temp_dir, parent=None): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user