From 71a339187f6ba56090d8e8060ced82ce81048566 Mon Sep 17 00:00:00 2001 From: Rusko124 Date: Tue, 27 Nov 2018 16:53:38 +0600 Subject: [PATCH 1/4] Support unicode for title of webpage asset --- viewer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viewer.py b/viewer.py index e304ccc27..9a17096ee 100755 --- a/viewer.py +++ b/viewer.py @@ -243,7 +243,7 @@ def load_browser(url=None): def browser_send(command, cb=lambda _: True): global browser_focus_lost - fl = lambda e: 'FOCUS_LOST' in unicode(e) + fl = lambda e: 'FOCUS_LOST' in unicode(e.decode('utf-8')) if not (browser is None) and browser.process.alive: while not browser.process._pipe_queue.empty(): # flush stdout browser.next() From d8ffe69d28b9b6a4d2da91f254713a483a32fd6f Mon Sep 17 00:00:00 2001 From: Rusko124 Date: Tue, 27 Nov 2018 17:05:20 +0600 Subject: [PATCH 2/4] changes --- viewer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viewer.py b/viewer.py index 9a17096ee..782b25cfc 100755 --- a/viewer.py +++ b/viewer.py @@ -243,7 +243,7 @@ def load_browser(url=None): def browser_send(command, cb=lambda _: True): global browser_focus_lost - fl = lambda e: 'FOCUS_LOST' in unicode(e.decode('utf-8')) + fl = lambda e: 'FOCUS_LOST' in unicode(e, encoding='utf-8') if not (browser is None) and browser.process.alive: while not browser.process._pipe_queue.empty(): # flush stdout browser.next() From cd1e45f1a6c320a37bc729e91a8af89f5723cddc Mon Sep 17 00:00:00 2001 From: Rusko124 Date: Wed, 28 Nov 2018 11:06:51 +0600 Subject: [PATCH 3/4] Added test and some edits --- tests/viewer_test.py | 3 +++ viewer.py | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/viewer_test.py b/tests/viewer_test.py index 2e1fc937d..33c51058f 100644 --- a/tests/viewer_test.py +++ b/tests/viewer_test.py @@ -67,6 +67,9 @@ def test_send(self): self.u.browser_send('test_cmd') m_put.assert_called_once_with('test_cmd\n') + self.u.browser_send('event TITLE 标题') + m_put.assert_called_with('event TITLE \xe6\xa0\x87\xe9\xa2\x98\n') + def test_dead(self): self.p_loadb.start() self.u.browser_send(None) diff --git a/viewer.py b/viewer.py index 782b25cfc..dd649cce5 100755 --- a/viewer.py +++ b/viewer.py @@ -243,7 +243,7 @@ def load_browser(url=None): def browser_send(command, cb=lambda _: True): global browser_focus_lost - fl = lambda e: 'FOCUS_LOST' in unicode(e, encoding='utf-8') + fl = lambda e: 'FOCUS_LOST' in unicode(e.decode('utf-8')) if not (browser is None) and browser.process.alive: while not browser.process._pipe_queue.empty(): # flush stdout browser.next() @@ -266,7 +266,8 @@ def browser_send(command, cb=lambda _: True): def browser_clear(force=False): """Load a black page. Default cb waits for the page to load.""" - browser_url('file://' + BLACK_PAGE, force=force, cb=lambda buf: 'LOAD_FINISH' in buf and BLACK_PAGE in buf) + browser_url('file://' + BLACK_PAGE, force=force, cb=lambda buf: 'LOAD_FINISH' in unicode(buf.decode('utf-8')) + and BLACK_PAGE in unicode(buf.decode('utf-8'))) def browser_url(url, cb=lambda _: True, force=False): @@ -287,7 +288,8 @@ def browser_url(url, cb=lambda _: True, force=False): def view_image(uri): browser_clear() - browser_send('js window.setimg("{0}")'.format(uri), cb=lambda b: 'COMMAND_EXECUTED' in b and 'setimg' in b) + browser_send('js window.setimg("{0}")'.format(uri), cb=lambda b: 'COMMAND_EXECUTED' in unicode(b.decode('utf-8')) + and 'setimg' in unicode(b.decode('utf-8'))) def view_video(uri, duration): @@ -408,7 +410,7 @@ def asset_loop(scheduler): elif 'web' in mime: # FIXME If we want to force periodic reloads of repeated web assets, force=True could be used here. # See e38e6fef3a70906e7f8739294ffd523af6ce66be. - browser_url(uri, cb=lambda b: 'LOAD_FINISH' in b) + browser_url(uri, cb=lambda b: 'LOAD_FINISH' in unicode(b.decode('utf-8'))) elif 'video' or 'streaming' in mime: view_video(uri, asset['duration']) else: From dcd5bb7e9a474aa6a26e08fcab4826475dd8135f Mon Sep 17 00:00:00 2001 From: Rusko124 Date: Wed, 28 Nov 2018 11:19:43 +0600 Subject: [PATCH 4/4] edits code style --- viewer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/viewer.py b/viewer.py index dd649cce5..e7231b833 100755 --- a/viewer.py +++ b/viewer.py @@ -266,8 +266,9 @@ def browser_send(command, cb=lambda _: True): def browser_clear(force=False): """Load a black page. Default cb waits for the page to load.""" - browser_url('file://' + BLACK_PAGE, force=force, cb=lambda buf: 'LOAD_FINISH' in unicode(buf.decode('utf-8')) - and BLACK_PAGE in unicode(buf.decode('utf-8'))) + browser_url('file://' + BLACK_PAGE, force=force, + cb=lambda buf: 'LOAD_FINISH' in unicode(buf.decode('utf-8')) and + BLACK_PAGE in unicode(buf.decode('utf-8'))) def browser_url(url, cb=lambda _: True, force=False): @@ -288,8 +289,9 @@ def browser_url(url, cb=lambda _: True, force=False): def view_image(uri): browser_clear() - browser_send('js window.setimg("{0}")'.format(uri), cb=lambda b: 'COMMAND_EXECUTED' in unicode(b.decode('utf-8')) - and 'setimg' in unicode(b.decode('utf-8'))) + browser_send('js window.setimg("{0}")'.format(uri), + cb=lambda b: 'COMMAND_EXECUTED' in unicode(b.decode('utf-8')) and + 'setimg' in unicode(b.decode('utf-8'))) def view_video(uri, duration):