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
diff --git a/checkbox_ng/urwid_ui.py b/checkbox_ng/urwid_ui.py
index 572cba8..9d4af34 100644
--- a/checkbox_ng/urwid_ui.py
+++ b/checkbox_ng/urwid_ui.py
@@ -22,9 +22,11 @@
22============================================================22============================================================
23"""23"""
2424
25import os
25import time26import time
2627
27from gettext import gettext as _28from gettext import gettext as _
29import urwid.raw_display
28import urwid30import urwid
2931
30from plainbox.abc import IJobResult32from plainbox.abc import IJobResult
@@ -35,6 +37,26 @@ test_info_list = ()
35show_job_ids = False37show_job_ids = False
3638
3739
40class ASCIIScreen(urwid.raw_display.Screen):
41 def draw_screen(self, size, r):
42 _trans_table = "?" * 32 + "".join([chr(x) for x in range(32, 256)])
43 line = []
44 for row in r.content():
45 for a, cs, run in row:
46 line.append(run.decode().translate(_trans_table))
47 line.append("\n")
48 print("".join(line))
49
50 def get_cols_rows(self):
51 return 80, 24
52
53
54if os.getenv("DISABLE_URWID_ESCAPE_CODES"):
55 Screen = ASCIIScreen
56else:
57 Screen = urwid.raw_display.Screen
58
59
38class FlagUnitWidget(urwid.TreeWidget):60class FlagUnitWidget(urwid.TreeWidget):
39 # apply an attribute to the expand/unexpand icons61 # apply an attribute to the expand/unexpand icons
40 unexpanded_icon = urwid.AttrMap(62 unexpanded_icon = urwid.AttrMap(
@@ -250,7 +272,7 @@ class CategoryNode(urwid.ParentNode):
250 else:272 else:
251 value = next(273 value = next(
252 (job['partial_id'], job['name']) for job in test_info_list274 (job['partial_id'], job['name']) for job in test_info_list
253 if job["id"] == key)275 if job["id"] == key)
254 return JobNode(276 return JobNode(
255 value, parent=self, key=key, depth=self.get_depth() + 1)277 value, parent=self, key=key, depth=self.get_depth() + 1)
256278
@@ -351,7 +373,7 @@ class CategoryBrowser:
351 """Run the urwid MainLoop."""373 """Run the urwid MainLoop."""
352 self.loop = urwid.MainLoop(374 self.loop = urwid.MainLoop(
353 self.view, self.palette, unhandled_input=self.unhandled_input,375 self.view, self.palette, unhandled_input=self.unhandled_input,
354 handle_mouse=False)376 handle_mouse=False, screen=Screen())
355 self.loop.run()377 self.loop.run()
356 selection = []378 selection = []
357 global test_info_list, _widget_cache379 global test_info_list, _widget_cache
@@ -651,7 +673,7 @@ class TestPlanBrowser():
651 def run(self):673 def run(self):
652 self.loop = urwid.MainLoop(674 self.loop = urwid.MainLoop(
653 self.frame, self.palette, unhandled_input=self.unhandled_input,675 self.frame, self.palette, unhandled_input=self.unhandled_input,
654 handle_mouse=False)676 handle_mouse=False, screen=Screen())
655 self.loop.run()677 self.loop.run()
656 try:678 try:
657 return next(i.tp_id for i in self.radio_button_group if i.state)679 return next(i.tp_id for i in self.radio_button_group if i.state)
@@ -712,7 +734,7 @@ def interrupt_dialog(host):
712 raise urwid.ExitMainLoop()734 raise urwid.ExitMainLoop()
713735
714 urwid.MainLoop(frame, palette, unhandled_input=unhandled,736 urwid.MainLoop(frame, palette, unhandled_input=unhandled,
715 handle_mouse=False).run()737 handle_mouse=False, screen=Screen()).run()
716 try:738 try:
717 index = next(739 index = next(
718 radio_button_group.index(i) for i in radio_button_group if i.state)740 radio_button_group.index(i) for i in radio_button_group if i.state)
@@ -852,7 +874,7 @@ class ManifestBrowser:
852 """Run the urwid MainLoop."""874 """Run the urwid MainLoop."""
853 self.loop = urwid.MainLoop(875 self.loop = urwid.MainLoop(
854 self.frame, self.palette, unhandled_input=self.unhandled_input,876 self.frame, self.palette, unhandled_input=self.unhandled_input,
855 handle_mouse=False)877 handle_mouse=False, screen=Screen())
856 self.loop.run()878 self.loop.run()
857 for w in self._widget_cache:879 for w in self._widget_cache:
858 self._manifest_out.update({w.id: w.value})880 self._manifest_out.update({w.id: w.value})
@@ -901,7 +923,8 @@ def resume_dialog(duration):
901 if timer.update():923 if timer.update():
902 loop.set_alarm_in(0.1, update_timer, timer)924 loop.set_alarm_in(0.1, update_timer, timer)
903925
904 loop = urwid.MainLoop(frame, palette, handle_mouse=False)926 loop = urwid.MainLoop(
927 frame, palette, handle_mouse=False, screen=Screen())
905 update_timer(loop, timer)928 update_timer(loop, timer)
906 loop.run()929 loop.run()
907930

Subscribers

People subscribed via source and target branches