Skip to content

Commit

Permalink
Added cancellation capability to the export_to_text function. Made th…
Browse files Browse the repository at this point in the history
…e generation of the PyInstaller's version_info.txt file dynamic using jinja2 templates.
  • Loading branch information
mush42 committed Feb 24, 2021
1 parent e28de4f commit 317f1bd
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ bookworm/resources/docs/*
bookworm/resources/icons/*
bookworm/bookworm.ico
bookworm/resources/image_data.py
scripts/builder/assets/version_info.txt
scripts/builder/assets/bookworm-logo.bmp
scripts/builder/assets/bookworm.bmp
scripts/builder/assets/bookworm.ico
Expand Down
7 changes: 4 additions & 3 deletions bookworm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

name = "bookworm"
display_name = "Bookworm"
author = "Blind Pandas Team"
description = "The Universally accessible eBook reader"
author = "Blind Pandas"
author_email = "info@blindpandas.com"
version = "0.3a0"
version_ex = "0.2.0.5"
version_ex = "0.3.0.0"
url = "https://github.com/blindpandas/bookworm"
website = "https://blindpandas.com/bookworm/"
update_url = "https://blindpandas.com/bookworm/current_version.json"
copyright = f"Copyright (c) 2020 {author} and {display_name} contributors."
copyright = f"Copyright (c) 2021 {author} and {display_name} contributors."
is_frozen = getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS")
arch = "x86" if struct.calcsize("P") == 4 else "x64"
debug = False
Expand Down
2 changes: 1 addition & 1 deletion bookworm/document_formats/base/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def can_render_pages(self):
return DocumentCapability.GRAPHICAL_RENDERING in self.capabilities

def export_to_text(self, target_filename: t.PathLike):
yield from QueueProcess(
return QueueProcess(
target=doctools.export_to_plain_text,
args=(self, target_filename),
name="bookworm-exporter",
Expand Down
5 changes: 5 additions & 0 deletions bookworm/document_formats/base/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def export_to_plain_text(doc, target_filename, channel):
if out.write(doc.metadata.title or ""):
out.write(f"{NEWLINE}{'-' * 30}{NEWLINE}")
for n in range(total):
if channel.is_cancellation_requested():
out.close()
doc.close()
channel.cancel()
return
text = doc.get_page_content(n)
out.write(f"{text}{NEWLINE}\f{NEWLINE}")
channel.push(n)
Expand Down
14 changes: 8 additions & 6 deletions bookworm/gui/book_viewer/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bookworm.document_formats import DocumentCapability as DC
from bookworm.signals import config_updated, reader_book_loaded, reader_book_unloaded
from bookworm.concurrency import call_threaded, process_worker
from bookworm.gui.components import RobustProgressDialog
from bookworm import ocr
from bookworm import speech
from bookworm.reader import EBookReader
Expand Down Expand Up @@ -172,17 +173,19 @@ def onExportAsPlainText(self, event):
if not filename.strip():
return
total = len(self.reader.document)
dlg = wx.ProgressDialog(
dlg = RobustProgressDialog(
self.view,
# Translators: the title of a dialog showing
# the progress of book export process
_("Exporting Book"),
# Translators: the message of a dialog showing the progress of book export
_("Converting your book to plain text."),
parent=self.view,
maximum=total,
style=wx.PD_APP_MODAL | wx.PD_REMAINING_TIME | wx.PD_AUTO_HIDE,
maxvalue=total,
can_hide=True,
can_abort=True
)
process = self.reader.document.export_to_text(filename)
dlg.set_abort_callback(process.cancel)
self._continue_with_export_to_text(process, dlg, total)

@call_threaded
Expand All @@ -194,8 +197,7 @@ def _continue_with_export_to_text(self, process, progress_dlg, total):
progress,
_("Exporting Page {} of {}...").format(progress + 1, total),
)
wx.CallAfter(progress_dlg.Close)
wx.CallAfter(progress_dlg.Destroy)
progress_dlg.Dismiss()

def onRecentFileItem(self, event):
clicked_id = event.GetId()
Expand Down
1 change: 1 addition & 0 deletions invoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ folders_to_clean:
- scripts/Bookworm*update.bundle
- scripts/Bookworm*portable.zip
- scripts/release-info.json
- scripts/builder/assets/version_info.txt
- scripts/builder/assets/bookworm.bmp
- scripts/builder/assets/bookworm-logo.bmp
- scripts/builder/assets/bookworm.ico
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
black==20.8b1
distro==1.5.0;sys_platform=="linux"
invoke==1.5.0
jinja2==2.11.3
PyInstaller==4.2
pytest==6.1.0
wheel==0.35.1
2 changes: 1 addition & 1 deletion scripts/bookworm.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CreateShortCut "$SMPROGRAMS\$StartMenuFolder\$%IAPP_DISPLAY_NAME% English User G
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall $%IAPP_DISPLAY_NAME%.lnk" "$INSTDIR\Uninstall.exe"
!insertmacro MUI_STARTMENU_WRITE_END
WriteUninstaller "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$%IAPP_NAME%" "DisplayName" "$%IAPP_DISPLAY_NAME% - The universally accessible eBook reader"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$%IAPP_NAME%" "DisplayName" "$%IAPP_DISPLAY_NAME% - $%IAPP_DESCRIPTION%"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$%IAPP_NAME%" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$%IAPP_NAME%" "InstallLocation" $INSTDIR
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" "Publisher" "$%IAPP_AUTHOR%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0.
filevers=(0, 3, 0, 0),
prodvers=(0, 3, 0, 0),
filevers=({{ app_version_tuple }}),
prodvers=({{ app_version_tuple }}),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file.
Expand All @@ -29,13 +29,13 @@ VSVersionInfo(
[
StringTable(
u'040904B0',
[StringStruct(u'CompanyName', u'Blind Pandas'),
StringStruct(u'FileDescription', u'Bookworm. The universally accessible eBook reader'),
StringStruct(u'FileVersion', u'0.3a0'),
StringStruct(u'LegalCopyright', u'Copyright (C) 2021 Blind Pandas'),
StringStruct(u'OriginalFilename', u'Bookworm.exe'),
StringStruct(u'ProductName', u'Bookworm'),
StringStruct(u'ProductVersion', u'0.3a0')])
[StringStruct(u'CompanyName', u'{{ app_author }}'),
StringStruct(u'FileDescription', u'{{ app_description }}'),
StringStruct(u'FileVersion', u'{{ app_version }}'),
StringStruct(u'LegalCopyright', u'{{ app_copyright }}'),
StringStruct(u'OriginalFilename', u'{{ app_name }}.exe'),
StringStruct(u'ProductName', u'{{ app_name }}'),
StringStruct(u'ProductVersion', u'{{ app_version }}')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
Expand Down
25 changes: 24 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pathlib import Path
from tempfile import TemporaryDirectory
from zipfile import ZipFile, ZIP_LZMA
from jinja2 import Environment, FileSystemLoader
from invoke import task, call
from invoke.exceptions import UnexpectedExit

Expand Down Expand Up @@ -83,6 +84,7 @@ def _add_envars(context):
"IAPP_ARCH": arch,
"IAPP_NAME": app.name,
"IAPP_DISPLAY_NAME": app.display_name,
"IAPP_DESCRIPTION": app.description,
"IAPP_VERSION": app.version,
"IAPP_VERSION_EX": app.version_ex,
"IAPP_AUTHOR": app.author,
Expand Down Expand Up @@ -502,8 +504,29 @@ def install_bookworm(c):
print("Finished installing packages.")


@task
@make_env
def make_version_info_file(c):
from bookworm import app

print("Generating version info file...")
env = Environment(loader=FileSystemLoader(PROJECT_ROOT / "scripts" / "builder"))
vinfo_tpl = env.get_template("version_info.txt.tpl")
output = vinfo_tpl.render(
app_version_tuple=app.version_ex.replace(".", ", ").strip(),
app_author=app.author,
app_description=app.description,
app_version=app.version,
app_copyright=app.copyright,
app_name=app.display_name,
)
outfile = PROJECT_ROOT / "scripts" / "builder" / "assets" / "version_info.txt"
outfile.write_text(output)
print(f"Version info file was generated at {outfile}")


@task(
pre=(install_bookworm,),
pre=(install_bookworm, make_version_info_file,),
post=(
copy_deps,
copy_uwp_services_lib,
Expand Down

0 comments on commit 317f1bd

Please sign in to comment.