Merge ~sylvain-pineau/checkbox-ng:urwid_ascii_screen into checkbox-ng:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 4c2811d8a398de6f0a9c1fa55078c577523e7735
Merged at revision: 80c63d08f713de26ca57672e59a459da556c1a1b
Proposed branch: ~sylvain-pineau/checkbox-ng:urwid_ascii_screen
Merge into: checkbox-ng:master
Diff against target: 97 lines (+29/-6)
1 file modified
checkbox_ng/urwid_ui.py (+29/-6)
Reviewer Review Type Date Requested Status
Jonathan Cave (community) Approve
Review via email: mp+392778@code.launchpad.net

Commit message

New urwid screen class to render widgets w/o all the escape characters. The get_input method and all the other methods are provided by raw_display to stay close to the original. Only draw_screen is overridden to render ASCII only.

The ASCIIScreen is enabled via the DISABLE_URWID_ESCAPE_CODES env var and only meant for functional testing.

Description of the change

New urwid screen class to render widgets w/o all the escape characters. The get_input method and all the other methods are provided by raw_display to stay close to the original. Only draw_screen is overridden to render ASCII only.

The ASCIIScreen is enabled via the DISABLE_URWID_ESCAPE_CODES env var and only meant for functional testing.

To post a comment you must log in.
Revision history for this message
Jonathan Cave (jocave) wrote :

Looks useful, thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_ng/urwid_ui.py b/checkbox_ng/urwid_ui.py
2index 572cba8..9d4af34 100644
3--- a/checkbox_ng/urwid_ui.py
4+++ b/checkbox_ng/urwid_ui.py
5@@ -22,9 +22,11 @@
6 ============================================================
7 """
8
9+import os
10 import time
11
12 from gettext import gettext as _
13+import urwid.raw_display
14 import urwid
15
16 from plainbox.abc import IJobResult
17@@ -35,6 +37,26 @@ test_info_list = ()
18 show_job_ids = False
19
20
21+class ASCIIScreen(urwid.raw_display.Screen):
22+ def draw_screen(self, size, r):
23+ _trans_table = "?" * 32 + "".join([chr(x) for x in range(32, 256)])
24+ line = []
25+ for row in r.content():
26+ for a, cs, run in row:
27+ line.append(run.decode().translate(_trans_table))
28+ line.append("\n")
29+ print("".join(line))
30+
31+ def get_cols_rows(self):
32+ return 80, 24
33+
34+
35+if os.getenv("DISABLE_URWID_ESCAPE_CODES"):
36+ Screen = ASCIIScreen
37+else:
38+ Screen = urwid.raw_display.Screen
39+
40+
41 class FlagUnitWidget(urwid.TreeWidget):
42 # apply an attribute to the expand/unexpand icons
43 unexpanded_icon = urwid.AttrMap(
44@@ -250,7 +272,7 @@ class CategoryNode(urwid.ParentNode):
45 else:
46 value = next(
47 (job['partial_id'], job['name']) for job in test_info_list
48- if job["id"] == key)
49+ if job["id"] == key)
50 return JobNode(
51 value, parent=self, key=key, depth=self.get_depth() + 1)
52
53@@ -351,7 +373,7 @@ class CategoryBrowser:
54 """Run the urwid MainLoop."""
55 self.loop = urwid.MainLoop(
56 self.view, self.palette, unhandled_input=self.unhandled_input,
57- handle_mouse=False)
58+ handle_mouse=False, screen=Screen())
59 self.loop.run()
60 selection = []
61 global test_info_list, _widget_cache
62@@ -651,7 +673,7 @@ class TestPlanBrowser():
63 def run(self):
64 self.loop = urwid.MainLoop(
65 self.frame, self.palette, unhandled_input=self.unhandled_input,
66- handle_mouse=False)
67+ handle_mouse=False, screen=Screen())
68 self.loop.run()
69 try:
70 return next(i.tp_id for i in self.radio_button_group if i.state)
71@@ -712,7 +734,7 @@ def interrupt_dialog(host):
72 raise urwid.ExitMainLoop()
73
74 urwid.MainLoop(frame, palette, unhandled_input=unhandled,
75- handle_mouse=False).run()
76+ handle_mouse=False, screen=Screen()).run()
77 try:
78 index = next(
79 radio_button_group.index(i) for i in radio_button_group if i.state)
80@@ -852,7 +874,7 @@ class ManifestBrowser:
81 """Run the urwid MainLoop."""
82 self.loop = urwid.MainLoop(
83 self.frame, self.palette, unhandled_input=self.unhandled_input,
84- handle_mouse=False)
85+ handle_mouse=False, screen=Screen())
86 self.loop.run()
87 for w in self._widget_cache:
88 self._manifest_out.update({w.id: w.value})
89@@ -901,7 +923,8 @@ def resume_dialog(duration):
90 if timer.update():
91 loop.set_alarm_in(0.1, update_timer, timer)
92
93- loop = urwid.MainLoop(frame, palette, handle_mouse=False)
94+ loop = urwid.MainLoop(
95+ frame, palette, handle_mouse=False, screen=Screen())
96 update_timer(loop, timer)
97 loop.run()
98

Subscribers

People subscribed via source and target branches