diff --git a/__main__.py b/__main__.py index 6afb402..ec1eda5 100755 --- a/__main__.py +++ b/__main__.py @@ -216,7 +216,13 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.ks_exit_all.activated.connect(self.closeEvent) self.listView.setFocus() + self.open_books_at_startup() + # Scan the library @ startup + if self.settings['scan_library']: + self.settings_dialog.start_library_scan() + + def open_books_at_startup(self): # Open last... open books. # Then set the value to None for the next run if self.settings['last_open_books']: @@ -246,10 +252,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.move_on() - # Scan the library @ startup - if self.settings['scan_library']: - self.settings_dialog.start_library_scan() - def cull_covers(self, event=None): blank_pixmap = QtGui.QPixmap() blank_pixmap.load(':/images/blank.png') @@ -498,8 +500,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.bookToolBar.show() self.libraryToolBar.hide() - current_metadata = self.tabWidget.widget( - self.tabWidget.currentIndex()).metadata + current_tab = self.tabWidget.widget( + self.tabWidget.currentIndex()) + current_metadata = current_tab.metadata if self.bookToolBar.fontButton.isChecked(): self.bookToolBar.customize_view_on() @@ -515,6 +518,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): if current_position: self.bookToolBar.tocBox.setCurrentIndex( current_position['current_chapter'] - 1) + if not current_metadata['images_only']: + current_tab.set_scroll_value(False) self.bookToolBar.tocBox.blockSignals(False) self.format_contentView() @@ -820,7 +825,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): 'background-color: %s' % background.name()) current_tab.format_view( - None, None, None, background, padding) + None, None, None, background, padding, None) else: profile_index = self.bookToolBar.profileBox.currentIndex() @@ -887,6 +892,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): checked = [i for i in directory_list if i[3] == QtCore.Qt.Checked] filter_list = list(map(generate_name, checked)) filter_list.sort() + filter_list.append('Manually added') filter_actions = [QtWidgets.QAction(i, self.library_filter_menu) for i in filter_list] filter_all = QtWidgets.QAction('All', self.library_filter_menu) @@ -969,6 +975,5 @@ def main(): app.exec_() - if __name__ == '__main__': main() diff --git a/library.py b/library.py index 436a117..3eb4a60 100644 --- a/library.py +++ b/library.py @@ -246,7 +246,7 @@ class Library: return directory_name, directory_tags - return None, None + return 'manually added', None # Both the models will have to be done separately # Item Model diff --git a/widgets.py b/widgets.py index c2c7784..41df0b1 100644 --- a/widgets.py +++ b/widgets.py @@ -424,35 +424,9 @@ class Tab(QtWidgets.QWidget): self.contentView.setHtml(chapter_content) self.contentView.setReadOnly(True) - def set_scroll_value(): - # TODO - # Stays in place upon switching tabs - - previous_widget = self.window().tabWidget.currentWidget() - self.window().tabWidget.setCurrentWidget(self) - - scroll_position = ( - self.metadata['position']['scroll_value'] * - self.contentView.verticalScrollBar().maximum()) - - # Scroll a little ahead - # This avoids confusion with potentially duplicate phrases - # And the found result is at the top of the window - self.contentView.verticalScrollBar().setValue(scroll_position * 1.1) - - last_visible_text = self.metadata['position']['last_visible_text'] - if last_visible_text: - self.contentView.find(last_visible_text) - - text_cursor = self.contentView.textCursor() - text_cursor.clearSelection() - self.contentView.setTextCursor(text_cursor) - - self.window().tabWidget.setCurrentWidget(previous_widget) - temp_hidden_button = QtWidgets.QToolButton(self) temp_hidden_button.setVisible(False) - temp_hidden_button.clicked.connect(set_scroll_value) + temp_hidden_button.clicked.connect(self.set_scroll_value) temp_hidden_button.animateClick(100) # The following are common to both the text browser and @@ -487,6 +461,31 @@ class Tab(QtWidgets.QWidget): self.contentView.setFocus() + def set_scroll_value(self, switch_widgets=True): + if switch_widgets: + previous_widget = self.window().tabWidget.currentWidget() + self.window().tabWidget.setCurrentWidget(self) + + scroll_position = ( + self.metadata['position']['scroll_value'] * + self.contentView.verticalScrollBar().maximum()) + + # Scroll a little ahead + # This avoids confusion with potentially duplicate phrases + # And the found result is at the top of the window + self.contentView.verticalScrollBar().setValue(scroll_position * 1.1) + + last_visible_text = self.metadata['position']['last_visible_text'] + if last_visible_text: + self.contentView.find(last_visible_text) + + text_cursor = self.contentView.textCursor() + text_cursor.clearSelection() + self.contentView.setTextCursor(text_cursor) + + if switch_widgets: + self.window().tabWidget.setCurrentWidget(previous_widget) + def generate_position(self): total_chapters = len(self.metadata['content'].keys()) # TODO @@ -704,15 +703,32 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser): self.ignore_wheel_event_number = 0 self.common_functions = PliantWidgetsCommonFunctions( self, self.main_window) + self.verticalScrollBar().sliderMoved.connect(self.record_scroll_position) self.setMouseTracking(True) def wheelEvent(self, event): - if self.verticalScrollBar().maximum() == 0: - self.common_functions.wheelEvent(event, False) - return + self.record_scroll_position() + self.common_functions.wheelEvent(event, False) - self.parent.metadata['position']['scroll_value'] = ( - self.verticalScrollBar().value() / self.verticalScrollBar().maximum()) + def keyPressEvent(self, event): + if event.key() == 32: + self.record_scroll_position() + + if self.verticalScrollBar().value() == self.verticalScrollBar().maximum(): + self.common_functions.change_chapter(1, True) + else: + QtWidgets.QTextEdit.keyPressEvent(self, event) + + else: + QtWidgets.QTextEdit.keyPressEvent(self, event) + + def record_scroll_position(self): + vertical = self.verticalScrollBar().value() + maximum = self.verticalScrollBar().maximum() + + self.parent.metadata['position']['scroll_value'] = 1 + if maximum != 0: + self.parent.metadata['position']['scroll_value'] = (vertical / maximum) cursor = self.cursorForPosition(QtCore.QPoint(0, 0)) bottom_right = QtCore.QPoint(self.viewport().width() - 1, self.viewport().height()) @@ -720,27 +736,10 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser): cursor.setPosition(bottom_right_cursor, QtGui.QTextCursor.KeepAnchor) visible_text = cursor.selectedText() - if len(visible_text) > 30: - visible_text = visible_text[:31] + if len(visible_text) > 50: + visible_text = visible_text[:51] self.parent.metadata['position']['last_visible_text'] = visible_text - self.common_functions.wheelEvent(event, False) - - def keyPressEvent(self, event): - if event.key() == 32: - vertical = self.verticalScrollBar().value() - maximum = self.verticalScrollBar().maximum() - - self.parent.metadata['position']['scroll_value'] = (vertical / maximum) - - if vertical == maximum: - self.common_functions.change_chapter(1, True) - else: - QtWidgets.QTextEdit.keyPressEvent(self, event) - - else: - QtWidgets.QTextEdit.keyPressEvent(self, event) - # def mouseMoveEvent(self, event): # TODO # This does not work as expected