Industrial-Strength Consoles
The previous console is extremely simple and allows only one statement at a time. Ideally, something like the interactive prompt in PythonWin would be preferable. There is actually quite a lot of work involved in writing such a window, and we won’t go through the code to do it here. As text is entered a line at a time, your interpreter window needs to decide if it’s a complete expression and when to process the input, as well as suggest indent levels for subsequent lines, and so on. The event-handling depends a great deal on the type of GUI widget used to build the console.
If you want to build such a console, look at the file
code.py
in the standard Python library. This
contains a function called
interact()
that defines an interactive console
written in Python. It needs adapting, but shows the general approach;
as each line is entered, it tries to evaluate the current text
buffer, and assumes the statement is incomplete if it gets an error.
You could modify this to provide hooks for your VB console.
Code.py is used by both IDLE and Pythonwin to
emulate the Python interactive mode.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access