Statusbar object, ripped off from bpython.cli. This class provides the status bar at the bottom of the screen. It has message() and prompt() methods for user interactivity, as well as settext() and clear() methods for changing its appearance. The check() method needs to be called r
| 155 | |
| 156 | |
| 157 | class Statusbar: |
| 158 | """Statusbar object, ripped off from bpython.cli. |
| 159 | |
| 160 | This class provides the status bar at the bottom of the screen. |
| 161 | It has message() and prompt() methods for user interactivity, as |
| 162 | well as settext() and clear() methods for changing its appearance. |
| 163 | |
| 164 | The check() method needs to be called repeatedly if the statusbar is |
| 165 | going to be aware of when it should update its display after a message() |
| 166 | has been called (it'll display for a couple of seconds and then disappear). |
| 167 | |
| 168 | It should be called as: |
| 169 | foo = Statusbar('Initial text to display') |
| 170 | or, for a blank statusbar: |
| 171 | foo = Statusbar() |
| 172 | |
| 173 | The "widget" attribute is an urwid widget. |
| 174 | """ |
| 175 | |
| 176 | signals = ["prompt_result"] |
| 177 | |
| 178 | def __init__(self, config, s=None, main_loop=None): |
| 179 | self.config = config |
| 180 | self.timer = None |
| 181 | self.main_loop = main_loop |
| 182 | self.s = s or "" |
| 183 | |
| 184 | self.text = urwid.Text(("main", self.s)) |
| 185 | # use wrap mode 'clip' to just cut off at the end of line |
| 186 | self.text.set_wrap_mode("clip") |
| 187 | |
| 188 | self.edit = StatusbarEdit(("main", "")) |
| 189 | urwid.connect_signal(self.edit, "prompt_enter", self._on_prompt_enter) |
| 190 | |
| 191 | self.widget = urwid.Columns([self.text, self.edit]) |
| 192 | |
| 193 | def _check(self, callback, userdata=None): |
| 194 | """This is the method is called from the timer to reset the status bar.""" |
| 195 | self.timer = None |
| 196 | self.settext(self.s) |
| 197 | |
| 198 | def message(self, s, n=3): |
| 199 | """Display a message for a short n seconds on the statusbar and return |
| 200 | it to its original state.""" |
| 201 | |
| 202 | self.settext(s) |
| 203 | self.timer = self.main_loop.set_alarm_in(n, self._check) |
| 204 | |
| 205 | def _reset_timer(self): |
| 206 | """Reset the timer from message.""" |
| 207 | if self.timer is not None: |
| 208 | self.main_loop.remove_alarm(self.timer) |
| 209 | self.timer = None |
| 210 | |
| 211 | def prompt(self, s=None, single=False): |
| 212 | """Prompt the user for some input (with the optional prompt 's'). After |
| 213 | the user hit enter the signal 'prompt_result' will be emitted and the |
| 214 | status bar will be reset. If single is True, the first keypress will be |