Skip to content

Commit

Permalink
Finalized cross platform support for build system.
Browse files Browse the repository at this point in the history
  • Loading branch information
mush42 committed Jan 13, 2021
1 parent 769ec3d commit 759477d
Show file tree
Hide file tree
Showing 39 changed files with 1,415 additions and 302 deletions.
8 changes: 6 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
recursive-include bookworm/resources/soundfiles *
recursive-include bookworm/resources/non_breaking_prefixes *
include bookworm/bookworm.ico
recursive-include bookworm/resources/docs *.html *.txt
recursive-include bookworm/resources/icons *.ico
recursive-include bookworm/resources/non_breaking_prefixes *.txt
recursive-include bookworm/resources/soundfiles *.wav
recursive-include bookworm/resources/locale *.mo
recursive-exclude tests *

Binary file added bookworm/bookworm.ico
Binary file not shown.
26 changes: 3 additions & 23 deletions bookworm/bookworm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,16 @@
"""Make sure that runtime components are OK and run the app."""

import sys


def check_runtime_components():
"""
Make sure that critical runtime components are OK.
Raise EnvironmentError.
"""
# TODO: Make sure that .NET Framework 4.0 or higher
# is available in the target system.
try:
# This is a basic sanity check
import clr
import System
except:
raise EnvironmentError
from bookworm.platform_services import check_runtime_components


def main():
try:
check_runtime_components()
except EnvironmentError:
except EnvironmentError as e:
import wx

wx.SafeShowMessage(
"Unable To Start",
"Bookworm is unable to start because some key components are missing from your system.\n"
"Bookworm requires that the .NET Framework v4.0 or a later version is present in the target system.\n"
"Head over to the following link to download and install the .NET Framework v4.0:\n"
"https://www.microsoft.com/en-us/download/details.aspx?id=17718",
)
wx.SafeShowMessage("Unable To Start", e.args[0])
sys.exit(1)
try:
from bookworm import bootstrap
Expand Down
7 changes: 4 additions & 3 deletions bookworm/gui/book_viewer/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,10 @@ def onRestartWithDebugMode(self, event):
restart_application(debug=True)

def onOpenDocumentation(self, event):
help_filename = f"bookworm.{'html' if app.is_frozen else 'md'}"
lang = app.current_language.given_lang
docs = paths.docs_path(lang, help_filename)
docs = paths.docs_path(
app.current_language.pylang,
"bookworm.html"
)
wx.LaunchDefaultApplication(str(docs))


Expand Down
13 changes: 6 additions & 7 deletions bookworm/i18n/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ def get_available_locales(force_update=False):
def set_locale(locale_identifier):
log.debug(f"Setting application locale to {locale_identifier}.")
available_locales = tuple(get_available_locales().values())
localeinfo = LocaleInfo(locale_identifier)
if localeinfo not in available_locales:
localeinfo = (
localeinfo.parent
if localeinfo.parent in available_locales
else _AVAILABLE_LOCALES["default"]
)
if locale_identifier in _AVAILABLE_LOCALES:
localeinfo = _AVAILABLE_LOCALES[locale_identifier]
else:
localeinfo = _AVAILABLE_LOCALES["default"]
config.conf["general"]["language"] = "default"
config.save()
lang = localeinfo.pylang
try:
translation = gettext.translation(
Expand Down
150 changes: 0 additions & 150 deletions bookworm/i18n/core.py.back

This file was deleted.

4 changes: 2 additions & 2 deletions bookworm/ocr/ocr_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _get_ocr_options(self, from_cache=True, **dlg_kw):
saved_values = {}
if pre_saved:
saved_values["lang"] = [
l.given_lang for l in get_recognition_languages()
l.pylang for l in get_recognition_languages()
].index(pre_saved[0])
saved_values["zoom_factor"] = pre_saved[1]
saved_values["should_enhance"] = pre_saved[2]
Expand Down Expand Up @@ -237,7 +237,7 @@ def _get_ocr_options_from_dlg(self, saved_values=None, **dlg_kw):
ocr_opts = dlg.ShowModal()
if ocr_opts is not None:
res = list(ocr_opts)
res[0] = langs[res[0]].given_lang
res[0] = langs[res[0]].pylang
return res

def onScanCurrentPage(self, event):
Expand Down
40 changes: 16 additions & 24 deletions bookworm/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from platform_utils import paths as path_finder
from functools import wraps
from bookworm import app
from bookworm.runtime import IS_RUNNING_PORTABLE
from bookworm.runtime import CURRENT_PACKAGING_MODE, PackagingMode


log = logging.getLogger("bookworm.paths")


DATA_PATH_DEBUG = Path(bookworm.__path__[0]).parent / ".appdata"
# The appdata path when running from source
DATA_PATH_SOURCE = Path.cwd() / ".appdata"


def merge_paths(func):
Expand All @@ -26,21 +26,20 @@ def merge_paths_wrapper(*a):

@merge_paths
def data_path():
if not app.is_frozen:
data_path = DATA_PATH_DEBUG
if CURRENT_PACKAGING_MODE is PackagingMode.Installed:
data_path = Path(path_finder.app_data_path(app.name))
elif CURRENT_PACKAGING_MODE is PackagingMode.Portable:
data_path = app_path("user-config")
else:
if IS_RUNNING_PORTABLE:
data_path = app_path("user-config")
else:
data_path = Path(path_finder.app_data_path(app.display_name))
data_path = DATA_PATH_SOURCE
if not data_path.exists():
data_path.mkdir(parents=True, exist_ok=True)
return data_path


@merge_paths
def app_path():
if app.is_frozen:
if CURRENT_PACKAGING_MODE in (PackagingMode.Installed, PackagingMode.Portable):
return Path(path_finder.app_path())
else:
import bookworm
Expand Down Expand Up @@ -68,9 +67,7 @@ def logs_path():

@merge_paths
def locale_path():
if app.is_frozen:
return app_path("resources", "locale")
return Path(app.__file__).parent / "resources" / "locale"
return app_path("resources", "locale")


@merge_paths
Expand All @@ -84,25 +81,20 @@ def db_path():

@merge_paths
def docs_path():
if not app.is_frozen:
parent = Path(DATA_PATH_DEBUG).parent
path = parent / "docs" / "userguides"
else:
path = app_path("resources", "docs")
path = app_path("resources", "docs")
if not path.exists():
log.warning(f"Documentation files was not found in {path}. Folder not Found.")
return path


@merge_paths
def home_data_path():
if app.is_frozen:
if IS_RUNNING_PORTABLE:
path = data_path(".saved_data")
else:
path = Path.home() / f".{app.name}"
if CURRENT_PACKAGING_MODE is PackagingMode.Installed:
path = Path.home() / f".{app.name}"
elif CURRENT_PACKAGING_MODE is PackagingMode.Portable:
path = data_path(".saved_data")
else:
path = DATA_PATH_DEBUG / "home_data"
path = DATA_PATH_SOURCE / "home_data"
if not path.exists():
log.debug("%s path does not exist, creating..." % (path,))
path.mkdir(parents=True, exist_ok=True)
Expand Down
6 changes: 6 additions & 0 deletions bookworm/platform_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
import sys

PLATFORM = sys.platform


if PLATFORM == 'win32':
from ._win32 import check_runtime_components
else:
from ._linux import check_runtime_components
20 changes: 20 additions & 0 deletions bookworm/platform_services/_win32/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# coding: utf-8


def check_runtime_components():
"""
Make sure that critical runtime components are OK.
Raise EnvironmentError.
"""
# TODO: Make sure that .NET Framework 4.0 or higher
# is available in the target system.
try:
# This is a basic sanity check
import clr
import System
except:
raise EnvironmentError(
"Bookworm is unable to start because some key components are missing from your system.\n"
"Bookworm requires that the .NET Framework v4.0 or a later version is present in the target system.\n"
"Head over to the following link to download and install the .NET Framework v4.0:\n"
"https://www.microsoft.com/en-us/download/details.aspx?id=17718",
)
Loading

0 comments on commit 759477d

Please sign in to comment.