def event_loop(self, toplevel=None):
    prev_quit_loop = self.quit_event_loop
    try:
        import pygments
    except ImportError:
        if (not hasattr(self, 'pygments_message_shown')):
            self.pygments_message_shown = True
            self.message("Package 'pygments' not found. Syntax highlighting disabled.")
    WELCOME_LEVEL = 'e039'
    if (CONFIG['seen_welcome'] < WELCOME_LEVEL):
        CONFIG['seen_welcome'] = WELCOME_LEVEL
        from pudb import VERSION
        self.message(("Welcome to PudB %s!\n\nPuDB is a full-screen, console-based visual debugger for Python.  Its goal is to provide all the niceties of modern GUI-based debuggers in a more lightweight and keyboard-friendly package. PuDB allows you to debug code right where you write and test it--in a terminal. If you've worked with the excellent (but nowadays ancient) DOS-based Turbo Pascal or C tools, PuDB's UI might look familiar.\n\nIf you're new here, welcome! The help screen (invoked by hitting '?' after this message) should get you on your way.\n\nChanges in version 2021.1:\n\n- Add shortcut to edit files in source and stack view (Gábor Vecsei)\n- Major improvements to the variable view (Michael van der Kamp)\n- Better internal error reporting (Michael van der Kamp)\n\nChanges in version 2020.1:\n\n- Add vi keys for the sidebar (Asbjørn Apeland)\n- Add -m command line switch (Elias Dorneles)\n- Debug forked processes (Jonathan Striebel)\n- Robustness and logging for internal errors (Michael Vanderkamp)\n- 'Reverse' remote debugging (jen6)\n\nChanges in version 2019.2:\n\n- Auto-hide the command line (Mark Blakeney)\n- Improve help and add jump to breakpoint (Mark Blakeney)\n- Drop Py2.6 support\n- Show callable attributes in var view\n- Allow scrolling sidebar with j/k\n- Fix setting breakpoints in Py3.8 (Aaron Meurer)\n\nChanges in version 2019.1:\n\n- Allow 'space' as a key to expand variables (Enrico Troeger)\n- Have a persistent setting on variable visibility \n  (Enrico Troeger)\n- Enable/partially automate opening the debugger in another \n  terminal (Anton Barkovsky)\n- Make sidebar scrollable with j/k (Clayton Craft)\n- Bug fixes.\n\nChanges in version 2018.1:\n\n- Bug fixes.\n\nChanges in version 2017.1.4:\n\n- Bug fixes.\n\nChanges in version 2017.1.3:\n\n- Add handling of safely_stringify_for_pudb to allow custom \n  per-type stringification.\n- Add support for custom shells.\n- Better support for 2-wide characters in the var view.\n- Bug fixes.\n\nChanges in version 2017.1.2:\n\n- Bug fixes.\n\nChanges in version 2017.1.1:\n\n- IMPORTANT: 2017.1 and possibly earlier versions had a \n  bug with exponential growth of shell history for the \n  'classic' shell, which (among other problems) could lead\n  to slow startup of the classic shell. Check the file\n\n  ~/.config/pudb/shell-history\n\n  for size (and useful content) and delete/trim as needed.\n\nChanges in version 2017.1:\n\n- Many, many bug fixes (thank you to all who contributed!)\n\nChanges in version 2016.2:\n\n- UI improvements for disabled breakpoints.\n- Bug fixes.\n\nChanges in version 2016.1:\n\n- Fix module browser on Py3.\n\nChanges in version 2015.4:\n\n- Support for (somewhat rudimentary) remote debugging\n  through a telnet connection.\n- Fix debugging of generated code in Python 3.\n\nChanges in version 2015.3:\n\n- Disable set_trace lines from the UI (Aaron Meurer)\n- Better control over attribute visibility (Ned Batchelder)\n\nChanges in version 2015.2:\n\n- ptpython support (P. Varet)\n- Improved rxvt support (Louper Rouch)\n- More keyboard shortcuts in the command line(Alex Sheluchin)\n\nChanges in version 2015.1:\n\n- Add solarized theme (Rinat Shigapov)\n- More keyboard shortcuts in the command line(Alexander Corwin)\n\nChanges in version 2014.1:\n\n- Make prompt-on-quit optional (Mike Burr)\n- Make tab completion in the built-in shell saner\n- Fix handling of unicode source\n  (reported by Morten Nielsen and Buck Golemon)\n\nChanges in version 2013.5.1:\n\n- Fix loading of saved breakpoint conditions (Antoine Dechaume)\n- Fixes for built-in command line\n- Theme updates\n\nChanges in version 2013.5:\n\n- Add command line window\n- Uses curses display driver when appropriate\n\nChanges in version 2013.4:\n\n- Support for debugging generated code\n\nChanges in version 2013.3.5:\n\n- IPython fixes (Aaron Meurer)\n- Py2/3 configuration fixes (Somchai Smythe)\n- PyPy fixes (Julian Berman)\n\nChanges in version 2013.3.4:\n\n- Don't die if curses doesn't like what stdin/out are\n  connected to.\n\nChanges in version 2013.3.3:\n\n- As soon as pudb is loaded, you can break to the debugger by\n  evaluating the expression 'pu.db', where 'pu' is a new \n  'builtin' that pudb has rudely shoved into the interpreter.\n\nChanges in version 2013.3.2:\n\n- Don't attempt to do signal handling if a signal handler\n  is already set (Fix by Buck Golemon).\n\nChanges in version 2013.3.1:\n\n- Don't ship {ez,distribute}_setup at all.\n  It breaks more than it helps.\n\nChanges in version 2013.3:\n\n- Switch to setuptools as a setup helper.\n\nChanges in version 2013.2:\n\n- Even more bug fixes.\n\nChanges in version 2013.1:\n\n- Ctrl-C will now break to the debugger in a way that does\n  not terminate the program\n- Lots of bugs fixed\n\nChanges in version 2012.3:\n\n- Python 3 support (contributed by Brad Froehle)\n- Better search box behavior (suggested by Ram Rachum)\n- Made it possible to go back and examine state from 'finished' window. (suggested by Aaron Meurer)\n\nChanges in version 2012.2.1:\n\n- Don't touch config files during install.\n\nChanges in version 2012.2:\n\n- Add support for BPython as a shell.\n- You can now run 'python -m pudb script.py' on Py 2.6+.\n  '-m pudb.run' still works--but it's four keystrokes longer! :)\n\nChanges in version 2012.1:\n\n- Work around an API change in IPython 0.12.\n\nChanges in version 2011.3.1:\n\n- Work-around for bug in urwid >= 1.0.\n\nChanges in version 2011.3:\n\n- Finer-grained string highlighting (contributed by Aaron Meurer)\n- Prefs tweaks, instant-apply, top-down stack (contributed by Aaron Meurer)\n- Size changes in sidebar boxes (contributed by Aaron Meurer)\n- New theme 'midnight' (contributed by Aaron Meurer)\n- Support for IPython 0.11 (contributed by Chris Farrow)\n- Suport for custom stringifiers (contributed by Aaron Meurer)\n- Line wrapping in variables view (contributed by Aaron Meurer)\n\nChanges in version 2011.2:\n\n- Fix for post-mortem debugging (contributed by 'Sundance')\n\nChanges in version 2011.1:\n\n- Breakpoints saved between sessions\n- A new 'dark vim' theme\n(both contributed by Naveen Michaud-Agrawal)\n\nChanges in version 0.93:\n\n- Stored preferences (no more pesky IPython prompt!)\n- Themes\n- Line numbers (optional)\n" % VERSION))
        from pudb.settings import save_config
        save_config(CONFIG)
        self.run_edit_config()
    try:
        if (toplevel is None):
            toplevel = self.top
        self.size = self.screen.get_cols_rows()
        self.quit_event_loop = False
        while (not self.quit_event_loop):
            canvas = toplevel.render(self.size, focus=True)
            self.screen.draw_screen(self.size, canvas)
            keys = self.screen.get_input()
            for k in keys:
                if (k == 'window resize'):
                    self.size = self.screen.get_cols_rows()
                else:
                    try:
                        toplevel.keypress(self.size, k)
                    except Exception:
                        self.show_internal_exc_dlg(sys.exc_info())
        return self.quit_event_loop
    finally:
        self.quit_event_loop = prev_quit_loop
def event_loop(self, toplevel=None):
    prev_quit_loop = self.quit_event_loop
    try:
        import pygments
    except ImportError:
        if (not hasattr(self, 'pygments_message_shown')):
            self.pygments_message_shown = True
            self.message("Package 'pygments' not found. Syntax highlighting disabled.")
    WELCOME_LEVEL = 'e039'
    if (CONFIG['seen_welcome'] < WELCOME_LEVEL):
        CONFIG['seen_welcome'] = WELCOME_LEVEL
        from pudb import VERSION
        self.message(("Welcome to PudB %s!\n\nPuDB is a full-screen, console-based visual debugger for Python.  Its goal is to provide all the niceties of modern GUI-based debuggers in a more lightweight and keyboard-friendly package. PuDB allows you to debug code right where you write and test it--in a terminal. If you've worked with the excellent (but nowadays ancient) DOS-based Turbo Pascal or C tools, PuDB's UI might look familiar.\n\nIf you're new here, welcome! The help screen (invoked by hitting '?' after this message) should get you on your way.\n\nChanges in version 2021.1:\n\n- Add shortcut to edit files in source and stack view (Gábor Vecsei)\n- Major improvements to the variable view (Michael van der Kamp)\n- Better internal error reporting (Michael van der Kamp)\n\nChanges in version 2020.1:\n\n- Add vi keys for the sidebar (Asbjørn Apeland)\n- Add -m command line switch (Elias Dorneles)\n- Debug forked processes (Jonathan Striebel)\n- Robustness and logging for internal errors (Michael Vanderkamp)\n- 'Reverse' remote debugging (jen6)\n\nChanges in version 2019.2:\n\n- Auto-hide the command line (Mark Blakeney)\n- Improve help and add jump to breakpoint (Mark Blakeney)\n- Drop Py2.6 support\n- Show callable attributes in var view\n- Allow scrolling sidebar with j/k\n- Fix setting breakpoints in Py3.8 (Aaron Meurer)\n\nChanges in version 2019.1:\n\n- Allow 'space' as a key to expand variables (Enrico Troeger)\n- Have a persistent setting on variable visibility \n  (Enrico Troeger)\n- Enable/partially automate opening the debugger in another \n  terminal (Anton Barkovsky)\n- Make sidebar scrollable with j/k (Clayton Craft)\n- Bug fixes.\n\nChanges in version 2018.1:\n\n- Bug fixes.\n\nChanges in version 2017.1.4:\n\n- Bug fixes.\n\nChanges in version 2017.1.3:\n\n- Add handling of safely_stringify_for_pudb to allow custom \n  per-type stringification.\n- Add support for custom shells.\n- Better support for 2-wide characters in the var view.\n- Bug fixes.\n\nChanges in version 2017.1.2:\n\n- Bug fixes.\n\nChanges in version 2017.1.1:\n\n- IMPORTANT: 2017.1 and possibly earlier versions had a \n  bug with exponential growth of shell history for the \n  'classic' shell, which (among other problems) could lead\n  to slow startup of the classic shell. Check the file\n\n  ~/.config/pudb/shell-history\n\n  for size (and useful content) and delete/trim as needed.\n\nChanges in version 2017.1:\n\n- Many, many bug fixes (thank you to all who contributed!)\n\nChanges in version 2016.2:\n\n- UI improvements for disabled breakpoints.\n- Bug fixes.\n\nChanges in version 2016.1:\n\n- Fix module browser on Py3.\n\nChanges in version 2015.4:\n\n- Support for (somewhat rudimentary) remote debugging\n  through a telnet connection.\n- Fix debugging of generated code in Python 3.\n\nChanges in version 2015.3:\n\n- Disable set_trace lines from the UI (Aaron Meurer)\n- Better control over attribute visibility (Ned Batchelder)\n\nChanges in version 2015.2:\n\n- ptpython support (P. Varet)\n- Improved rxvt support (Louper Rouch)\n- More keyboard shortcuts in the command line(Alex Sheluchin)\n\nChanges in version 2015.1:\n\n- Add solarized theme (Rinat Shigapov)\n- More keyboard shortcuts in the command line(Alexander Corwin)\n\nChanges in version 2014.1:\n\n- Make prompt-on-quit optional (Mike Burr)\n- Make tab completion in the built-in shell saner\n- Fix handling of unicode source\n  (reported by Morten Nielsen and Buck Golemon)\n\nChanges in version 2013.5.1:\n\n- Fix loading of saved breakpoint conditions (Antoine Dechaume)\n- Fixes for built-in command line\n- Theme updates\n\nChanges in version 2013.5:\n\n- Add command line window\n- Uses curses display driver when appropriate\n\nChanges in version 2013.4:\n\n- Support for debugging generated code\n\nChanges in version 2013.3.5:\n\n- IPython fixes (Aaron Meurer)\n- Py2/3 configuration fixes (Somchai Smythe)\n- PyPy fixes (Julian Berman)\n\nChanges in version 2013.3.4:\n\n- Don't die if curses doesn't like what stdin/out are\n  connected to.\n\nChanges in version 2013.3.3:\n\n- As soon as pudb is loaded, you can break to the debugger by\n  evaluating the expression 'pu.db', where 'pu' is a new \n  'builtin' that pudb has rudely shoved into the interpreter.\n\nChanges in version 2013.3.2:\n\n- Don't attempt to do signal handling if a signal handler\n  is already set (Fix by Buck Golemon).\n\nChanges in version 2013.3.1:\n\n- Don't ship {ez,distribute}_setup at all.\n  It breaks more than it helps.\n\nChanges in version 2013.3:\n\n- Switch to setuptools as a setup helper.\n\nChanges in version 2013.2:\n\n- Even more bug fixes.\n\nChanges in version 2013.1:\n\n- Ctrl-C will now break to the debugger in a way that does\n  not terminate the program\n- Lots of bugs fixed\n\nChanges in version 2012.3:\n\n- Python 3 support (contributed by Brad Froehle)\n- Better search box behavior (suggested by Ram Rachum)\n- Made it possible to go back and examine state from 'finished' window. (suggested by Aaron Meurer)\n\nChanges in version 2012.2.1:\n\n- Don't touch config files during install.\n\nChanges in version 2012.2:\n\n- Add support for BPython as a shell.\n- You can now run 'python -m pudb script.py' on Py 2.6+.\n  '-m pudb.run' still works--but it's four keystrokes longer! :)\n\nChanges in version 2012.1:\n\n- Work around an API change in IPython 0.12.\n\nChanges in version 2011.3.1:\n\n- Work-around for bug in urwid >= 1.0.\n\nChanges in version 2011.3:\n\n- Finer-grained string highlighting (contributed by Aaron Meurer)\n- Prefs tweaks, instant-apply, top-down stack (contributed by Aaron Meurer)\n- Size changes in sidebar boxes (contributed by Aaron Meurer)\n- New theme 'midnight' (contributed by Aaron Meurer)\n- Support for IPython 0.11 (contributed by Chris Farrow)\n- Suport for custom stringifiers (contributed by Aaron Meurer)\n- Line wrapping in variables view (contributed by Aaron Meurer)\n\nChanges in version 2011.2:\n\n- Fix for post-mortem debugging (contributed by 'Sundance')\n\nChanges in version 2011.1:\n\n- Breakpoints saved between sessions\n- A new 'dark vim' theme\n(both contributed by Naveen Michaud-Agrawal)\n\nChanges in version 0.93:\n\n- Stored preferences (no more pesky IPython prompt!)\n- Themes\n- Line numbers (optional)\n" % VERSION))
        from pudb.settings import save_config
        save_config(CONFIG)
        self.run_edit_config()
    try:
        if (toplevel is None):
            toplevel = self.top
        self.size = self.screen.get_cols_rows()
        self.quit_event_loop = False
        while (not self.quit_event_loop):
            canvas = toplevel.render(self.size, focus=True)
            self.screen.draw_screen(self.size, canvas)
            keys = self.screen.get_input()
            for k in keys:
                if (k == 'window resize'):
                    self.size = self.screen.get_cols_rows()
                else:
                    try:
                        toplevel.keypress(self.size, k)
                    except Exception:
                        self.show_internal_exc_dlg(sys.exc_info())
        return self.quit_event_loop
    finally:
        self.quit_event_loop = prev_quit_loop