| 567 | |
| 568 | |
| 569 | class URWIDRepl(repl.Repl): |
| 570 | _time_between_redraws = 0.05 # seconds |
| 571 | |
| 572 | def __init__(self, event_loop, palette, interpreter, config): |
| 573 | super().__init__(interpreter, config) |
| 574 | |
| 575 | self._redraw_handle = None |
| 576 | self._redraw_pending = False |
| 577 | self._redraw_time = 0 |
| 578 | |
| 579 | self.listbox = BPythonListBox(urwid.SimpleListWalker([])) |
| 580 | |
| 581 | self.tooltip = urwid.ListBox(urwid.SimpleListWalker([])) |
| 582 | self.tooltip.grid = None |
| 583 | self.overlay = Tooltip(self.listbox, self.tooltip) |
| 584 | self.stdout_hist = "" # native str (unicode in Py3) |
| 585 | |
| 586 | self.frame = urwid.Frame(self.overlay) |
| 587 | |
| 588 | if urwid.get_encoding_mode() == "narrow": |
| 589 | input_filter = decoding_input_filter |
| 590 | else: |
| 591 | input_filter = None |
| 592 | |
| 593 | # This constructs a raw_display.Screen, which nabs sys.stdin/out. |
| 594 | self.main_loop = urwid.MainLoop( |
| 595 | self.frame, |
| 596 | palette, |
| 597 | event_loop=event_loop, |
| 598 | unhandled_input=self.handle_input, |
| 599 | input_filter=input_filter, |
| 600 | handle_mouse=False, |
| 601 | ) |
| 602 | |
| 603 | # String is straight from bpython.cli |
| 604 | self.statusbar = Statusbar( |
| 605 | config, |
| 606 | _( |
| 607 | " <%s> Rewind <%s> Save <%s> Pastebin " |
| 608 | " <%s> Pager <%s> Show Source " |
| 609 | ) |
| 610 | % ( |
| 611 | config.undo_key, |
| 612 | config.save_key, |
| 613 | config.pastebin_key, |
| 614 | config.last_output_key, |
| 615 | config.show_source_key, |
| 616 | ), |
| 617 | self.main_loop, |
| 618 | ) |
| 619 | self.frame.set_footer(self.statusbar.widget) |
| 620 | self.interact = URWIDInteraction( |
| 621 | self.config, self.statusbar, self.frame |
| 622 | ) |
| 623 | |
| 624 | self.edits = [] |
| 625 | self.edit = None |
| 626 | self.current_output = None |