summaryrefslogtreecommitdiff
path: root/urwid/display_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'urwid/display_common.py')
-rwxr-xr-xurwid/display_common.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/urwid/display_common.py b/urwid/display_common.py
index b539f53..3f0e975 100755
--- a/urwid/display_common.py
+++ b/urwid/display_common.py
@@ -26,7 +26,7 @@ try:
except ImportError:
pass # windows
-from urwid.util import int_scale
+from urwid.util import StoppingContext, int_scale
from urwid import signals
from urwid.compat import B, bytes3
@@ -719,11 +719,29 @@ class BaseScreen(object):
started = property(lambda self: self._started)
def start(self):
+ """Set up the screen.
+
+ May be used as a context manager, in which case `stop` will
+ automatically be called at the end of the block:
+
+ with screen.start():
+ ...
+ """
self._started = True
+ return StoppingContext(self)
def stop(self):
self._started = False
+ def run_wrapper(self, fn, *args, **kwargs):
+ """Start the screen, call a function, then stop the screen. Extra
+ arguments are passed to `start`.
+
+ Deprecated in favor of calling `start` as a context manager.
+ """
+ with self.start(*args, **kwargs):
+ return fn()
+
def register_palette(self, palette):
"""Register a set of palette entries.