PythonCard integrates a rich, high-level interactive Python shell. This document describes how to launch and use this shell as you create PythonCard applications. It is based on Version 0.6.5 of PythonCard.
The shell is based on the PyCrust package created by Patrick O'Brien of Orbtech. The release of PyCrust included with wxPython 2.3.2.1 is version 0.7. This document is based on version 0.7.2 of PyCrust in cvs which you can get from SourceForge. This newer version of PyCrust will be included with wxPython 2.3.3, expected out sometime in May. There may be some features or key bindings described below that are not available if you don't have the cvs version of PyCrust.
In many ways, the PythonCard shell resembles IDLE, the Python editor that is included in Python distributions. IDLE is Python's default editor. But the PythonCard shell is more extensive and more robust both in its editing capabilities and in its programming support than IDLE.
As you can see from Figure 1, the shell allows you to do interactive
programming at the standard Python prompt of three angle brackets (">>>").
It behaves like IDLE, so there's nothing new to learn in this respect.
Figure 1. Using PythonCard Shell as Interactive Programming Environment
Table 1 shows all of the key bindings defined in the PythonCard shell and describes their usage.
Key Combination |
Usage |
Home |
Go to the beginning of the line |
Shift + Home |
Select from current cursor position to the beginning
of the line |
End |
Go to the end of the line |
Shift + End |
Select from the current cursor position to the end
of the line |
Alt + Right Arrow |
Move cursor to the right roughly by a word |
Alt + Left Arrow |
Move cursor to the left roughly by a word |
Ctrl + C |
Copy the selection to the clipboard |
Ctrl + Shift + C | Copy the selection including the prompts, if any,
to the clipboard |
Ctrl + X |
Cut the selection to the clipboard |
Ctrl + V |
Paste the clipboard contents at the cursor location |
Ctrl + Shift + V |
Paste the current multi-line clipboard contents
at the cursor location |
Ctrl + Up Arrow |
Retrieve most recent History item |
Ctrl + Enter |
Inserts a blank line between existing lines in a
multiline command. |
Alt + P |
Retrieve most recent History item |
Ctrl + Down Arrow |
Retrieve next History item in the queue |
Alt + N |
Retrieve next History item in the queue |
Shift + Up Arrow |
Retrieve previous History item |
Shift + Down Arrow |
Retrieve next History item in the queue |
F8 |
Retrieve a specific History item by typing its first
few characters and then pressing F8 |
One of the biggest time-saving features built into the PythonCard shell
is auto-completion. Whenever you type a period in identifying a Python
or PythonCard object, method, or property, the shell displays a popup
menu with all of the legal completions to that statement that the shell
knows about. For example, in Figure 4, we imported the standard "os" module
and then typed "os" followed by a period. The popup menu shown in the
figure appears.
shell.autoComplete = 1
shell.autoCompleteIncludeSingle = 0
shell.autoCompleteIncludeMagic = 1
Similarly to the auto-completion popup described in the preceding section,
the PythonCard shell also includes the ability to automatically display
important documentation for any function or method. Simply type the method
or function name and the opening (left) parenthesis and the shell displays
helpful information describing the function. These "call tips" attempt to
display on their first line all of the arguments expected by a callable object.
Where the object involved is the class name, the arguments expected by the
class constructor are displayed. The second line of the call tip displays
the docstring for the object if it has one.
Figure 5 demonstrates this feature. We have typed "os.fdopen(" and the
resulting tool tip tells us the required and optional parameters and
what the function does as well as what it returns.
You can copy, paste, edit, and execute multi-line functions and compound statements in the PythonCard shell. This can be a huge time-saver when you want to re-execute a method you've defined in the interactive editor. To do so, simply use any of the history retrieval methods outlined in Table 1 to copy any group of multiple lines and then edit them in place. If you, e.g., define a function or class in the shell and you make a mistake, you can avoid the usually mandatory complete re-typing of the code by copying the whole thing and then editing the mistakes. You can also use the PythonCard shell in conjunction with another Python-aware editor. You could, e.g., create a class in another editor, then copy its definition and paste it into the shell to experiment with it. Each time you need a new copy of the class definition, simply paste it again.
You may find yourself occasionally wanting to re-execute multiple
commands , each of which may be a single line or a multi-line command.
In that situation, pasting those lines into the shell using Shift+Ctrl+V
will paste all the lines and run all of the commands contained in the selection.
If you want to copy multi-line commands from the shell into another
file (e.g., for documentation purposes), you can select and then use Ctrl+C
to copy those lines. This will strip the Python shell prompts out of the copied
material. If, however, you wish to retain those prompts, use Shift+Ctrl+C
to perform the copy and the prompts will be preserved when you paste the
selection into another window or file.