From 5e7c2fbde57d33c7f6c878da80d64284a303732c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 28 May 2017 11:16:46 +0530 Subject: [PATCH] Get console print working from within the iframe as well --- src/pyj/read_book/iframe.pyj | 7 ++++++- src/pyj/read_book/view.pyj | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 8e8088b427..55f0cdce4a 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -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: diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index d5b5d92686..06c6c39c90 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -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)