Get console print working from within the iframe as well

This commit is contained in:
Kovid Goyal 2017-05-28 11:16:46 +05:30
parent bce5112268
commit 5e7c2fbde5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 1 deletions

View File

@ -118,6 +118,7 @@ class IframeBoss:
print('Unknown action in message to iframe from parent: ' + data.action)
def initialize(self, data):
nonlocal print
self.gcm_from_parent, self.gcm_to_parent = GCM(data.secret.subarray(0, 32)), GCM(data.secret.subarray(32))
scroll_viewport.update_window_size(data.width, data.height)
if data.translations:
@ -128,9 +129,13 @@ class IframeBoss:
window.addEventListener('wheel', self.onwheel)
window.addEventListener('keydown', self.onkeydown)
document.documentElement.addEventListener('contextmenu', self.oncontextmenu)
create_touch_handlers()
self.color_scheme = data.color_scheme
self.encrypted_communications = True
print = self.print_to_parent
create_touch_handlers()
def print_to_parent(self, *args):
self.send_message('print', string=' '.join(map(str, args)))
def onerror(self, msg, script_url, line_number, column_number, error_object):
if error_object:

View File

@ -119,6 +119,7 @@ class View:
'bump_font_size': self.bump_font_size,
'find_in_spine': self.on_find_in_spine,
'request_size': self.on_request_size,
'print': self.on_print,
}
self.currently_showing = {}
@ -158,6 +159,9 @@ class View:
w, h = self.iframe_size()
self.send_message('window_size', width=w, height=h)
def on_print(self, data):
print(data.string)
def find(self, text, backwards):
self.send_message('find', text=text, backwards=backwards, searched_in_spine=False)