Make the first page a manual cover display

Remove .css files to ensure fidelity to font settings
This commit is contained in:
BasioMeusPuga
2018-03-10 21:01:07 +05:30
parent 60d1e58bc4
commit b41352f2d0
5 changed files with 36 additions and 8 deletions

6
TODO
View File

@@ -49,16 +49,17 @@ TODO
✓ Deletion ✓ Deletion
✓ Cache next and previous images ✓ Cache next and previous images
✓ Set context menu for definitions and the like ✓ Set context menu for definitions and the like
✓ Paragraph indentation
Search document using QTextCursor? Search document using QTextCursor?
Comic view keyboard shortcuts Comic view keyboard shortcuts
Filetypes: Filetypes:
✓ epub support
✓ Homegrown solution please
✓ cbz, cbr support ✓ cbz, cbr support
✓ Keep font settings enabled but only for background color ✓ Keep font settings enabled but only for background color
✓ mobi, azw support ✓ mobi, azw support
Limit the extra files produced by KindleUnpack Limit the extra files produced by KindleUnpack
Have them save to memory Have them save to memory
epub support
Homegrown solution please
Other: Other:
✓ Define every widget in code ✓ Define every widget in code
Bugs: Bugs:
@@ -77,6 +78,7 @@ TODO
Pagination Pagination
Use embedded fonts Use embedded fonts
Scrolling: Smooth / By Line Scrolling: Smooth / By Line
Spacebar should not cut off lines at the top
Shift to logging instead of print statements Shift to logging instead of print statements
txt, doc, chm, djvu, fb2 support txt, doc, chm, djvu, fb2 support
Include icons for filetype emblems Include icons for filetype emblems

View File

@@ -218,8 +218,8 @@ class EPUB:
chapter_source = unquote(chapter_source.split('#')[0]) chapter_source = unquote(chapter_source.split('#')[0])
self.book['navpoint_dict'][chapter_source] = chapter_title self.book['navpoint_dict'][chapter_source] = chapter_title
def parse_chapters(self, split_large_xml=False): def parse_chapters(self, temp_dir=None, split_large_xml=False):
no_title_chapter = 1 no_title_chapter = 0
self.book['book_list'] = [] self.book['book_list'] = []
for i in self.book['chapters_in_order']: for i in self.book['chapters_in_order']:
chapter_data = self.read_from_zip(i).decode() chapter_data = self.read_from_zip(i).decode()
@@ -234,6 +234,13 @@ class EPUB:
(fallback_title, chapter_data)) (fallback_title, chapter_data))
no_title_chapter += 1 no_title_chapter += 1
cover_path = os.path.join(temp_dir, os.path.basename(self.filename)) + '- cover'
with open(cover_path, 'wb') as cover_temp:
cover_temp.write(self.book['cover'])
self.book['book_list'][0] = (
'Cover', f'<center><img src="{cover_path}" alt="Cover"></center>')
else: else:
# https://stackoverflow.com/questions/14444732/how-to-split-a-html-page-to-multiple-pages-using-python-and-beautiful-soup # https://stackoverflow.com/questions/14444732/how-to-split-a-html-page-to-multiple-pages-using-python-and-beautiful-soup
markup = BeautifulSoup(chapter_data, 'xml') markup = BeautifulSoup(chapter_data, 'xml')

View File

@@ -17,7 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os import os
import sys
import zipfile import zipfile
from ePub.read_epub import EPUB from ePub.read_epub import EPUB
@@ -63,7 +62,7 @@ class ParseEPUB:
extract_path = os.path.join(self.temp_dir, self.file_md5) extract_path = os.path.join(self.temp_dir, self.file_md5)
zipfile.ZipFile(self.filename).extractall(extract_path) zipfile.ZipFile(self.filename).extractall(extract_path)
self.book_ref.parse_chapters() self.book_ref.parse_chapters(temp_dir=self.temp_dir)
file_settings = { file_settings = {
'images_only': False} 'images_only': False}
return self.book['book_list'], file_settings return self.book['book_list'], file_settings

View File

@@ -35,6 +35,7 @@ class ParseMOBI:
self.filename = filename self.filename = filename
self.epub_filepath = None self.epub_filepath = None
self.split_large_xml = False self.split_large_xml = False
self.temp_dir = temp_dir
self.extract_dir = os.path.join(temp_dir, file_md5) self.extract_dir = os.path.join(temp_dir, file_md5)
def read_book(self): def read_book(self):
@@ -82,7 +83,8 @@ class ParseMOBI:
extract_path = os.path.join(self.extract_dir) extract_path = os.path.join(self.extract_dir)
zipfile.ZipFile(self.epub_filepath).extractall(extract_path) zipfile.ZipFile(self.epub_filepath).extractall(extract_path)
self.book_ref.parse_chapters(self.split_large_xml) self.book_ref.parse_chapters(
temp_dir=self.temp_dir, split_large_xml=self.split_large_xml)
file_settings = { file_settings = {
'images_only': False} 'images_only': False}
return self.book['book_list'], file_settings return self.book['book_list'], file_settings

View File

@@ -72,6 +72,17 @@ class Tab(QtWidgets.QWidget):
self.window().temp_dir.path(), self.metadata['hash']) self.window().temp_dir.path(), self.metadata['hash'])
relative_paths = [] relative_paths = []
for i in os.walk(relative_path_root): for i in os.walk(relative_path_root):
# TODO
# Rename the .css files to something else here and keep
# a record of them
# Currently, I'm just removing them for the sake of simplicity
for j in i[2]:
file_extension = os.path.splitext(j)[1]
if file_extension == '.css':
file_path = os.path.join(relative_path_root, j)
os.remove(file_path)
relative_paths.append(os.path.join(relative_path_root, i[0])) relative_paths.append(os.path.join(relative_path_root, i[0]))
self.contentView.setSearchPaths(relative_paths) self.contentView.setSearchPaths(relative_paths)
@@ -283,13 +294,20 @@ class Tab(QtWidgets.QWidget):
block_format.setLineHeight( block_format.setLineHeight(
line_spacing, QtGui.QTextBlockFormat.ProportionalHeight) line_spacing, QtGui.QTextBlockFormat.ProportionalHeight)
block_format.setTextIndent(50)
# Give options for alignment # Give options for alignment
alignment_dict = { alignment_dict = {
'left': QtCore.Qt.AlignLeft, 'left': QtCore.Qt.AlignLeft,
'right': QtCore.Qt.AlignRight, 'right': QtCore.Qt.AlignRight,
'center': QtCore.Qt.AlignCenter, 'center': QtCore.Qt.AlignCenter,
'justify': QtCore.Qt.AlignJustify} 'justify': QtCore.Qt.AlignJustify}
block_format.setAlignment(alignment_dict[text_alignment])
current_index = self.window().bookToolBar.tocBox.currentIndex()
if current_index == 0:
block_format.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignHCenter)
else:
block_format.setAlignment(alignment_dict[text_alignment])
# Also for padding # Also for padding
# Using setViewPortMargins for this disables scrolling in the margins # Using setViewPortMargins for this disables scrolling in the margins