Skip to content

Commit 94f569a

Browse files
author
Sebastian Ramacher
committed
Update the documentation of some prompt related methods.
1 parent 52d2fd7 commit 94f569a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

bpython/urwid.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,19 @@ def message(self, s, n=3):
218218
self.settext(s)
219219
self.timer = self.main_loop.set_alarm_in(n, self._check)
220220

221+
def _reset_timer(self):
222+
"""Reset the timer from message."""
223+
if self.timer is not None:
224+
self.main_loop.remove_alarm(self.timer)
225+
self.timer = None
226+
221227
def prompt(self, s=None, single=False):
222228
"""Prompt the user for some input (with the optional prompt 's'). After
223229
the user hit enter the signal 'prompt_result' will be emited and the
224230
status bar will be reset. If single is True, the first keypress will be
225231
returned."""
226232

227-
if self.timer is not None:
228-
self.main_loop.remove_alarm(self.timer)
229-
self.timer = None
233+
self._reset_timer()
230234

231235
self.edit.single = single
232236
self.edit.set_caption(('main', s or '?'))
@@ -243,9 +247,7 @@ def settext(self, s, permanent=False):
243247
the new value will be permanent. If that status bar is in prompt mode,
244248
the prompt will be aborted. """
245249

246-
if self.timer is not None:
247-
self.main_loop.remove_alarm(self.timer)
248-
self.timer = None
250+
self._reset_timer()
249251

250252
# hide the edit and display the text widget
251253
if self.edit in self.widget.widget_list:
@@ -533,7 +535,8 @@ def notify(self, s, n=10):
533535

534536
def prompt(self, s, callback=None, single=False):
535537
"""Prompt the user for input. The result will be returned via calling
536-
callback."""
538+
callback. Note that there can only be one prompt active. But the
539+
callback can already start a new prompt."""
537540

538541
if self.callback is not None:
539542
raise Exception('Prompt already in progress')
@@ -545,8 +548,11 @@ def prompt(self, s, callback=None, single=False):
545548
def _prompt_result(self, text):
546549
self.frame.set_focus('body')
547550
if self.callback is not None:
548-
self.callback(text)
549-
self.callback = None
551+
# The callback might want to start another prompt, so reset it
552+
# before calling the callback.
553+
callback = self.callback
554+
self.callback = None
555+
callback(text)
550556

551557

552558
class URWIDRepl(repl.Repl):

0 commit comments

Comments
 (0)