More work on the new viewer

This commit is contained in:
Kovid Goyal 2018-09-23 09:01:32 +05:30
parent 8b0cdbad13
commit b862af3844
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 41 additions and 3 deletions

View File

@ -47,6 +47,7 @@ def get_data(name):
return f.read(), guess_type(name) return f.read(), guess_type(name)
except EnvironmentError as err: except EnvironmentError as err:
prints('Failed to read from book file: {} with error: {}'.format(name, as_unicode(err))) prints('Failed to read from book file: {} with error: {}'.format(name, as_unicode(err)))
return None, None
class UrlSchemeHandler(QWebEngineUrlSchemeHandler): class UrlSchemeHandler(QWebEngineUrlSchemeHandler):

View File

@ -2,15 +2,21 @@
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import bound_methods, hash_literals from __python__ import bound_methods, hash_literals
import traceback
from elementmaker import E from elementmaker import E
from read_book.globals import runtime, ui_operations from gettext import gettext as _
from ajax import ajax
from modals import error_dialog
from qt import from_python from qt import from_python
from read_book.globals import runtime, ui_operations
def container_div(id): def container_div(id):
return E.div(id=id, style='margin: 0; padding: 0; display: none') return E.div(id=id, style='margin: 0; padding: 0; display: none')
runtime.is_standalone_viewer = True runtime.is_standalone_viewer = True
book_manifest = None
def get_file(book, name, proceed): def get_file(book, name, proceed):
@ -29,9 +35,39 @@ def show_error(title, msg, details):
pass # TODO: Implement this pass # TODO: Implement this
def manifest_received(end_type, xhr, ev):
nonlocal book_manifest
if end_type is 'load':
book_manifest = xhr.response
else:
error_dialog(_('Could not open book'), _(
'Failed to load book manifest, click "Show details" for more info'),
xhr.error_html or None)
@from_python @from_python
def start_book_load(): def start_book_load():
print(111111111111111) ajax('book/calibre-book-manifest.json', manifest_received, ok_code=0).send()
def onerror(msg, script_url, line_number, column_number, error_object):
if error_object is None:
# This happens for cross-domain errors (probably javascript injected
# into the browser via extensions/ userscripts and the like). It also
# happens all the time when using Chrom on Safari, so ignore this
# type of error
console.log(f'Unhandled error from external javascript, ignoring: {msg} {script_url} {line_number}')
return
console.log(error_object)
try:
fname = script_url.rpartition('/')[-1] or script_url
msg = msg + '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>'
details = ''
details = traceback.format_exception(error_object).join('')
error_dialog(_('Unhandled error'), msg, details)
return True
except:
console.log('There was an error in the unhandled exception handler')
if window is window.top: if window is window.top:
@ -42,6 +78,7 @@ if window is window.top:
ui_operations.show_error = show_error ui_operations.show_error = show_error
document.body.appendChild(E.div(id='loading')) document.body.appendChild(E.div(id='loading'))
document.body.appendChild(E.div(id='view')) document.body.appendChild(E.div(id='view'))
window.onerror = onerror
else: else:
# iframe # iframe
pass pass