summaryrefslogtreecommitdiff
path: root/urwid/main_loop.py
diff options
context:
space:
mode:
authorIan Ward <ian@excess.org>2011-07-05 17:25:38 -0400
committerIan Ward <ian@excess.org>2011-07-05 17:25:38 -0400
commit7519abaf644aa254cea41926b81c8c57669a1308 (patch)
tree0fa591651b6442e107aa8efb0dcd01ce7c187057 /urwid/main_loop.py
parent18e0dbc31369aac2361171f6e52c3fb9b96eba68 (diff)
downloadurwid-7519abaf644aa254cea41926b81c8c57669a1308.tar.gz
use main_loop and no magic for vterm updates
Diffstat (limited to 'urwid/main_loop.py')
-rwxr-xr-xurwid/main_loop.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/urwid/main_loop.py b/urwid/main_loop.py
index bc3fd9f..da48863 100755
--- a/urwid/main_loop.py
+++ b/urwid/main_loop.py
@@ -94,6 +94,7 @@ class MainLoop(object):
self.event_loop = event_loop
self._input_timeout = None
+ self._watch_pipes = {}
def set_alarm_in(self, sec, callback, user_data=None):
@@ -172,8 +173,47 @@ class MainLoop(object):
os.close(pipe_rd)
watch_handle = self.event_loop.watch_file(pipe_rd, cb)
+ self._watch_pipes[pipe_wr] = (watch_handle, pipe_rd)
return pipe_wr
+ def remove_watch_pipe(self, write_fd):
+ """
+ Close the read end of the pipe and remove the watch created
+ by watch_pipe(). You are responsible for closing the write
+ end of the pipe.
+
+ Returns True if the watch pipe exists, False otherwise
+ """
+ try:
+ watch_handle, pipe_rd = self._watch_pipes.remove(write_fd)
+ except KeyError:
+ return False
+
+ if not self.event_loop.remove_watch_file(watch_handle):
+ return False
+ os.close(pipe_rd)
+ return True
+
+ def watch_file(self, fd, callback):
+ """
+ Call callback() when fd has some data to read. No parameters
+ are passed to callback.
+
+ Returns a handle that may be passed to remove_watch_file()
+
+ fd -- file descriptor to watch for input
+ callback -- function to call when input is available
+ """
+ return self.event_loop.watch_file(fd, callback)
+
+ def remove_watch_file(self, handle):
+ """
+ Remove a watch file.
+
+ Returns True if the watch file exists, False otherwise.
+ """
+ return self.event_loop.remove_watch_file(handle)
+
def run(self):
"""