Consolidate docks

Update copyright
Pondered the nature of protein powder
This commit is contained in:
BasioMeusPuga
2019-01-03 03:28:31 +05:30
parent 6ea5635d28
commit d75689ea97
18 changed files with 101 additions and 119 deletions

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

9
TODO
View File

@@ -2,7 +2,8 @@ TODO
General:
✓ Internationalization
✓ Application icon
✓ .desktop file
✓ .desktop file
Flatpak and maybe AppImage support
Options:
✓ Automatic library management
✓ Recursive file addition
@@ -63,7 +64,7 @@ TODO
✓ Track open bookmark windows so they can be closed quickly at exit
Double page / column view
✓ For comics
Caching is current non fuctional
Caching is currently non fuctional
Annotations
✓ Text
Annotation preview in listView
@@ -76,6 +77,7 @@ TODO
✓ Homegrown solution please
✓ cbz, cbr support
✓ Keep font settings enabled but only for background color
✓ Double page view
✓ mobi, azw support
Limit the extra files produced by KindleUnpack
Have them save to memory
@@ -90,6 +92,9 @@ TODO
Colors aren't loaded properly for annotation previews
Cover page shouldn't be scolled midway
Last line in QTextBrowser should never be cut off
Annotation / bookmark docks shouldn't be separate
Cursor position is a little finicky when toggling fullscreen
Hide mousepointer more aggressively
Secondary:
Double page view for books

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -78,7 +78,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.comic_profile = {}
self.database_path = None
self.active_library_filters = []
self.active_bookmark_docks = []
self.active_docks = []
# Initialize application
Settings(self).read_settings() # This should populate all variables that need
@@ -171,9 +171,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.libraryToolBar.tableViewButton.trigger()
# Book toolbar
self.bookToolBar.annotationButton.triggered.connect(self.toggle_dock_widgets)
self.bookToolBar.annotationButton.triggered.connect(self.toggle_side_dock)
self.bookToolBar.addBookmarkButton.triggered.connect(self.add_bookmark)
self.bookToolBar.bookmarkButton.triggered.connect(self.toggle_dock_widgets)
self.bookToolBar.bookmarkButton.triggered.connect(self.toggle_side_dock)
self.bookToolBar.distractionFreeButton.triggered.connect(self.toggle_distraction_free)
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
@@ -617,8 +617,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Hide bookmark and annotation widgets
for i in range(1, self.tabWidget.count()):
self.tabWidget.widget(i).bookmarkDock.setVisible(False)
self.tabWidget.widget(i).annotationDock.setVisible(False)
self.tabWidget.widget(i).sideDock.setVisible(False)
if self.tabWidget.currentIndex() == 0:
@@ -685,9 +684,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tabWidget.widget(tab_index).setParent(None)
gc.collect()
self.bookToolBar.bookmarkButton.setChecked(False)
self.bookToolBar.annotationButton.setChecked(False)
def set_toc_position(self, event=None):
current_tab = self.tabWidget.currentWidget()
@@ -705,13 +701,15 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
def set_fullscreen(self):
self.tabWidget.currentWidget().go_fullscreen()
def toggle_dock_widgets(self):
def toggle_side_dock(self):
# Tab indices are fixed
# 0 = Annotations
# 1 = Bookmarks
sender = self.sender()
if sender == self.bookToolBar.bookmarkButton:
self.tabWidget.currentWidget().toggle_bookmarks()
if sender == self.bookToolBar.annotationButton:
self.tabWidget.currentWidget().toggle_annotations()
self.tabWidget.currentWidget().toggle_side_dock(0)
if sender == self.bookToolBar.bookmarkButton:
self.tabWidget.currentWidget().toggle_side_dock(1)
def library_doubleclick(self, index):
sender = self.sender().objectName()
@@ -986,7 +984,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.settingsDialog.hide()
self.definitionDialog.hide()
self.temp_dir.remove()
for this_dock in self.active_bookmark_docks:
for this_dock in self.active_docks:
try:
this_dock.setVisible(False)
except RuntimeError:

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -350,7 +350,7 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
self.image_pixmap.save(save_file[0])
if action == bookmarksToggleAction:
self.parent.toggle_bookmarks()
self.parent.toggle_side_dock(1)
if action == dfToggleAction:
self.main_window.toggle_distraction_free()
if action == fsToggleAction:
@@ -455,8 +455,8 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
if self.annotation_mode:
self.annotation_mode = False
self.viewport().setCursor(QtCore.Qt.ArrowCursor)
self.parent.annotationDock.show()
self.parent.annotationDock.setWindowOpacity(.95)
self.parent.sideDock.show()
self.parent.sideDock.setWindowOpacity(.95)
self.current_annotation = None
self.parent.annotationListView.clearSelection()
@@ -464,7 +464,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
else:
self.annotation_mode = True
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
self.parent.annotationDock.hide()
self.parent.sideDock.hide()
selected_index = self.parent.annotationListView.currentIndex()
self.current_annotation = self.parent.annotationModel.data(
@@ -616,7 +616,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
'delete', 'text', current_chapter, cursor_at_mouse.position())
if action == bookmarksToggleAction:
self.parent.toggle_bookmarks()
self.parent.toggle_side_dock(1)
if action == fsToggleAction:
self.parent.exit_fullscreen()

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -74,11 +74,9 @@ class BookToolBar(QtWidgets.QToolBar):
self.fontButton.triggered.connect(self.toggle_font_settings)
self.addSeparator()
self.addAction(self.annotationButton)
self.annotationButton.setCheckable(True)
self.addSeparator()
self.addAction(self.addBookmarkButton)
self.addAction(self.bookmarkButton)
self.bookmarkButton.setCheckable(True)
self.addSeparator()
self.addAction(self.distractionFreeButton)
self.addAction(self.fullscreenButton)

View File

@@ -1,5 +1,5 @@
# This file is a part of Lector, a Qt based ebook reader
# Copyright (C) 2017-2018 BasioMeusPuga
# Copyright (C) 2017-2019 BasioMeusPuga
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,7 +17,6 @@
# TODO
# Reading modes
# Double page, Continuous etc
# Especially for comics
import os
import uuid
@@ -121,71 +120,61 @@ class Tab(QtWidgets.QWidget):
self.contentView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.contentView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
# Create the annotations dock
self.annotationDock = PliantDockWidget(self.main_window, 'annotations', self.contentView)
self.annotationDock.setWindowTitle(self._translate('Tab', 'Annotations'))
self.annotationDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
self.annotationDock.hide()
# Create a common dock for annotations and bookmarks
# And add a vertical layout to it for requisite widgets
self.sideDock = PliantDockWidget(self.main_window, False, self.contentView)
self.sideDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
self.sideDock.setTitleBarWidget(QtWidgets.QWidget())
self.sideDockTabWidget = QtWidgets.QTabWidget()
self.sideDock.setWidget(self.sideDockTabWidget)
self.annotationListView = QtWidgets.QListView(self.annotationDock)
# Annotation list view and model
self.annotationListView = QtWidgets.QListView(self.sideDock)
self.annotationListView.setResizeMode(QtWidgets.QListWidget.Adjust)
self.annotationListView.setMaximumWidth(350)
self.annotationListView.doubleClicked.connect(self.contentView.toggle_annotation_mode)
self.annotationListView.setEditTriggers(QtWidgets.QListView.NoEditTriggers)
self.annotationDock.setWidget(self.annotationListView)
self.sideDockTabWidget.addTab(self.annotationListView, 'Annotations')
self.annotationModel = QtGui.QStandardItemModel(self)
self.generate_annotation_model()
# Create the annotation notes dock
self.annotationNoteDock = PliantDockWidget(self.main_window, 'notes', self.contentView)
self.annotationNoteDock.setWindowTitle(self._translate('Tab', 'Note'))
self.annotationNoteDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
self.annotationNoteDock.hide()
self.annotationNoteEdit = QtWidgets.QTextEdit(self.annotationDock)
self.annotationNoteEdit.setMaximumSize(QtCore.QSize(250, 250))
self.annotationNoteEdit.setFocusPolicy(QtCore.Qt.StrongFocus)
self.annotationNoteDock.setWidget(self.annotationNoteEdit)
# Create the dock widget for context specific display
self.bookmarkDock = PliantDockWidget(self.main_window, 'bookmarks', self.contentView)
title_string = self._translate('Tab', 'Bookmarks')
if self.main_window.settings['toc_with_bookmarks']:
title_string = self._translate('Tab', 'TOC + Bookmarks')
self.bookmarkDock.setWindowTitle(title_string)
self.bookmarkDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
self.bookmarkDock.hide()
self.bookmarkTreeView = QtWidgets.QTreeView(self.bookmarkDock)
# Bookmark tree view and model
self.bookmarkTreeView = QtWidgets.QTreeView(self.sideDock)
self.bookmarkTreeView.setHeaderHidden(True)
self.bookmarkTreeView.setMaximumWidth(350)
self.bookmarkTreeView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.bookmarkTreeView.customContextMenuRequested.connect(
self.generate_bookmark_context_menu)
self.bookmarkTreeView.clicked.connect(self.navigate_to_bookmark)
self.bookmarkDock.setWidget(self.bookmarkTreeView)
self.sideDockTabWidget.addTab(self.bookmarkTreeView, 'Bookmarks')
self.bookmarkModel = QtGui.QStandardItemModel(self)
self.bookmarkProxyModel = BookmarkProxyModel(self)
self.generate_bookmark_model()
# Create the annotation notes dock
self.annotationNoteDock = PliantDockWidget(self.main_window, True, self.contentView)
self.annotationNoteDock.setWindowTitle(self._translate('Tab', 'Note'))
self.annotationNoteDock.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
self.annotationNoteDock.hide()
self.annotationNoteEdit = QtWidgets.QTextEdit(self.annotationNoteDock)
self.annotationNoteEdit.setMaximumSize(QtCore.QSize(250, 250))
self.annotationNoteEdit.setFocusPolicy(QtCore.Qt.StrongFocus)
self.annotationNoteDock.setWidget(self.annotationNoteEdit)
self.generate_keyboard_shortcuts()
self.masterLayout.addWidget(self.contentView)
self.masterLayout.addWidget(self.annotationDock)
self.masterLayout.addWidget(self.sideDock)
self.masterLayout.addWidget(self.annotationNoteDock)
self.masterLayout.addWidget(self.bookmarkDock)
# The following has to be after the docks are added to the layout
self.annotationDock.setFloating(True)
self.annotationDock.setWindowOpacity(.95)
self.sideDock.setFloating(True)
self.sideDock.setWindowOpacity(.95)
self.annotationNoteDock.setFloating(True)
self.annotationNoteDock.setWindowOpacity(.95)
self.bookmarkDock.setFloating(True)
self.bookmarkDock.setWindowOpacity(.95)
title = self.metadata['title']
if self.main_window.settings['attenuate_titles'] and len(title) > 30:
@@ -209,6 +198,18 @@ class Tab(QtWidgets.QWidget):
self.contentView.setFocus()
def toggle_side_dock(self, tab_required=1):
if (self.sideDock.isVisible()
and self.sideDockTabWidget.currentIndex() == tab_required):
self.sideDock.hide()
elif not self.sideDock.isVisible():
self.sideDock.show()
if tab_required == 0:
self.sideDockTabWidget.setCurrentIndex(0)
else: # Takes care of the action menu as well
self.sideDockTabWidget.setCurrentIndex(1)
def update_last_accessed_time(self):
self.metadata['last_accessed'] = QtCore.QDateTime().currentDateTime()
@@ -301,13 +302,13 @@ class Tab(QtWidgets.QWidget):
self.ksToggleBookMarks = QtWidgets.QShortcut(
QtGui.QKeySequence('Ctrl+B'), self.contentView)
self.ksToggleBookMarks.activated.connect(self.toggle_bookmarks)
self.ksToggleBookMarks.activated.connect(self.toggle_side_dock)
def go_fullscreen(self):
# To allow toggles to function
# properly after the fullscreening
self.bookmarkDock.hide()
self.annotationDock.hide()
self.sideDock.hide()
self.annotationNoteDock.hide()
if self.contentView.windowState() == QtCore.Qt.WindowFullScreen:
@@ -328,11 +329,16 @@ class Tab(QtWidgets.QWidget):
self.is_fullscreen = True
def exit_fullscreen(self):
for i in (self.bookmarkDock, self.annotationDock, self.annotationNoteDock):
# Intercept escape presses
for i in (self.annotationNoteDock, self.sideDock):
if i.isVisible():
i.setVisible(False)
return
# Prevents cursor position change on escape presses
if self.main_window.isVisible():
return
if not self.are_we_doing_images_only:
self.contentView.record_position()
@@ -424,12 +430,6 @@ class Tab(QtWidgets.QWidget):
if old_position == new_position:
break
def toggle_annotations(self):
if self.annotationDock.isVisible():
self.annotationDock.hide()
else:
self.annotationDock.show()
def generate_annotation_model(self):
saved_annotations = self.main_window.settings['annotations']
@@ -451,12 +451,6 @@ class Tab(QtWidgets.QWidget):
self.annotationListView.setModel(self.annotationModel)
def toggle_bookmarks(self):
if self.bookmarkDock.isVisible():
self.bookmarkDock.hide()
else:
self.bookmarkDock.show()
def add_bookmark(self):
identifier = uuid.uuid4().hex[:10]
description = self._translate('Tab', 'New bookmark')
@@ -472,7 +466,7 @@ class Tab(QtWidgets.QWidget):
'cursor_position': cursor_position,
'description': description}
self.bookmarkDock.setVisible(True)
self.sideDock.setVisible(True)
self.add_bookmark_to_model(
description, chapter, cursor_position, identifier, True)
@@ -484,7 +478,7 @@ class Tab(QtWidgets.QWidget):
new_child = parent_item.child(parent_item.rowCount() - 1, 0)
source_index = self.bookmarkModel.indexFromItem(new_child)
edit_index = self.bookmarkTreeView.model().mapFromSource(source_index)
self.bookmarkDock.activateWindow()
self.sideDock.activateWindow()
self.bookmarkTreeView.setFocus()
self.bookmarkTreeView.setCurrentIndex(edit_index)
self.bookmarkTreeView.edit(edit_index)
@@ -632,10 +626,10 @@ class Tab(QtWidgets.QWidget):
class PliantDockWidget(QtWidgets.QDockWidget):
def __init__(self, main_window, intended_for, contentView, parent=None):
def __init__(self, main_window, notes_only, contentView, parent=None):
super(PliantDockWidget, self).__init__()
self.main_window = main_window
self.intended_for = intended_for
self.notes_only = notes_only
self.contentView = contentView
self.current_annotation = None
@@ -643,43 +637,30 @@ class PliantDockWidget(QtWidgets.QDockWidget):
viewport_height = self.contentView.viewport().size().height()
viewport_topRight = self.contentView.mapToGlobal(
self.contentView.viewport().rect().topRight())
viewport_topLeft = self.contentView.mapToGlobal(
self.contentView.viewport().rect().topLeft())
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
dock_y = viewport_topRight.y() # + (viewport_height * .10)
dock_y = viewport_topRight.y()
dock_height = viewport_height * .999
if self.intended_for == 'bookmarks':
dock_width = desktop_size.width() // 5.5
dock_x = viewport_topLeft.x()
self.main_window.bookToolBar.bookmarkButton.setChecked(True)
elif self.intended_for == 'annotations':
dock_width = desktop_size.width() // 5.5
dock_x = viewport_topRight.x() - dock_width + 1
self.main_window.bookToolBar.annotationButton.setChecked(True)
elif self.intended_for == 'notes':
if self.notes_only:
dock_width = dock_height = desktop_size.width() // 5.5
dock_x = QtGui.QCursor.pos().x()
dock_y = QtGui.QCursor.pos().y()
else:
dock_width = desktop_size.width() // 5.5
dock_x = viewport_topRight.x() - dock_width + 1
self.main_window.active_bookmark_docks.append(self)
self.main_window.active_docks.append(self)
self.setGeometry(dock_x, dock_y, dock_width, dock_height)
def hideEvent(self, event=None):
if self.intended_for == 'bookmarks':
self.main_window.bookToolBar.bookmarkButton.setChecked(False)
elif self.intended_for == 'annotations':
self.main_window.bookToolBar.annotationButton.setChecked(False)
elif self.intended_for == 'notes':
if self.notes_only:
annotationNoteEdit = self.findChild(QtWidgets.QTextEdit)
if self.current_annotation:
self.current_annotation['note'] = annotationNoteEdit.toPlainText()
try:
self.main_window.active_bookmark_docks.remove(self)
self.main_window.active_docks.remove(self)
except ValueError:
pass