File: shell.html

package info (click to toggle)
pythoncard 0.8.1-8.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,352 kB
  • ctags: 4,594
  • sloc: python: 42,401; makefile: 55; sh: 22
file content (248 lines) | stat: -rw-r--r-- 13,394 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
    <link rel="stylesheet" href="PythonCard.css" type="text/css" />
    <title>PythonCard Documentation: The Shell</title>
  </head>
  <body>
    <div id="banner">
    <h1>PythonCard</h1>
    </div>
<?php include "sidebar.php" ?>
    <div id="content">
    <h2>Using the Shell in PythonCard</h2>
    <p><strong>Version 1.2 of August 2, 2002</strong></p>
    <p>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.</p>
    <p>The shell is based on the <a href="http://sourceforge.net/projects/pycrust">
PyCrust</a>
    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.</p>
    <h3>Overview of Basic Shell Functionality</h3>
    <p>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.</p>
    <p>As you can see from Figure 1, the shell allows you to do interactive
    programming at the standard Python prompt of three angle brackets 
    ("&gt;&gt;&gt;"). It behaves like IDLE, so there's nothing new to learn in 
    this respect.</p>
    <p class="imageCaption"><img src="images/shellfig1.png" alt="PythonCard Shell" /><br />
    Figure 1. Using PythonCard Shell as Interactive Programming Environment</p>
    <p>Figure 1 also illustrates the shell's inclusion of syntax highlighting and 
    coloring. In its current release, it does not support customization of these 
    color highlights.</p>
    <p>Pressing Enter anywhere on a line in the shell always processes the command
    on that line if that line is the last one in the current editing window. 
    Pressing Enter on any other line copies that line's contents and places them 
    on the last line in the window, enabling you to execute the command again or 
    modify it slightly. This feature is quite valuable during testing when you 
    often type the same commands repeatedly. In Figure 2, we positioned the cursor
    at the end of the line containing the simple statement &quot;5+2&quot; and
    pressed Enter. Notice that 5+2 now appears as the last line in the editor. 
    Pressing Enter now produces the expected output of &quot;7&quot; on the next 
    line in the editor.</p>
    <p class="imageCaption"><img src="images/shellfig2.png" alt="Copying commands in the shell" /><br />
    Figure 2. Copying a Previous Command Line With Enter Key</p>
    <p>You can use the ESCape key to change your mind about a line of Python code
    you are entering that has not yet been executed bypressing Enter. This will 
    simply erase all the characters on the current line and return your cursor to
    the Python prompt.</p>
    <p>You can always obtain some basic help in the use of the shell by typing 
    &quot;shell.help()&quot; in the interactive editor area and pressing Enter.
    The result will look something like Figure 3.</p>
    <p class="imageCaption"><img src="images/shellfig3.png" alt="Help in the shell" /><br />
    Figure 3. Result of Typing &quot;shell.help()&quot; in PythonCard Shell</p>
    <p>The arrow keys navigate up, down, left and right in text displayed in the 
    shell, as you'd expect. Holding down the Alt key with the right or left arrow
    moves the cursor by the rough equivalent of a &quot;word&quot; in the 
    direction of the arrow, with movement continuing across line boundaries.</p>
    <p>By default, lines typed into the shell do not wrap. If you wish to see the
    lines in your shell window wrap at the right border of the shell window,
    type in the shell: shell.SetWrapMode(1). To turn it back off, type 
    shell.SetWrapMode(0).</p>
    <h3>Key Bindings in the Shell</h3>
    <p>Table 1 shows all of the key bindings defined in the PythonCard shell and 
    describes their usage.</p>
    <p class="imageCaption">Table 1. Key Bindings in PythonCard Shell</p>
    <table cellpadding="2" cellspacing="2" border="1" width="75%">
      <tr>
        <th>Key Combination</th>
        <th>Usage</th>
      </tr>
      <tr>
        <td>Home</td>
        <td>Go to the beginning of the line</td>
      </tr>
      <tr>
        <td>Shift + Home</td>
        <td>Select from current cursor position to the beginning of the line</td>
      </tr>
      <tr>
        <td>End</td>
        <td>Go to the end of the line</td>
      </tr>
      <tr>
        <td>Shift + End</td>
        <td>Select from the current cursor position to the end of the line</td>
      </tr>
      <tr>
        <td>Alt + Right Arrow</td>
        <td>Move cursor to the right roughly by a word</td>
      </tr>
      <tr>
        <td>Alt + Left Arrow</td>
        <td>Move cursor to the left roughly by a word</td>
      </tr>
      <tr>
        <td>Ctrl + C</td>
        <td>Copy the selection to the clipboard</td>
      </tr>
      <tr>
        <td>Ctrl + Shift + C</td>
        <td>Copy the selection including the prompts, if any, to the clipboard</td>
      </tr>
      <tr>
        <td>Ctrl + X</td>
        <td>Cut the selection to the clipboard</td>
      </tr>
      <tr>
        <td>Ctrl + V</td>
        <td>Paste the clipboard contents at the cursor location</td>
      </tr>
      <tr>
        <td>Ctrl + Shift + V</td>
        <td>Paste the current multi-line clipboard contents at the cursor location</td>
      </tr>
      <tr>
        <td>Ctrl + Up Arrow</td>
        <td>Retrieve most recent History item</td>
      </tr>
      <tr>
        <td>Ctrl + Enter</td>
        <td>Inserts a blank line between existing lines in a multiline command.</td>
      </tr>
      <tr>
        <td>Alt + P</td>
        <td>Retrieve most recent History item</td>
      </tr>
      <tr>
        <td>Ctrl + Down Arrow</td>
        <td>Retrieve next History item in the queue</td>
      </tr>
      <tr>
        <td>Alt + N</td>
        <td>Retrieve next History item in the queue</td>
      </tr>
      <tr>
        <td>Shift + Up Arrow</td>
        <td>Retrieve previous History item</td>
      </tr>
      <tr>
        <td>Shift + Down Arrow</td>
        <td>Retrieve next History item in the queue</td>
      </tr>
      <tr>
        <td>F8</td>
        <td>Retrieve a specific History item by typing its first few characters and then pressing F8</td>
      </tr>
    </table>
    <h3>Auto-Completion in the Shell</h3>
    <p>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 &quot;os&quot; module and 
    then typed &quot;os&quot; followed by a period. The popup menu shown in the
    figure appears.</p>
    <p class="imageCaption"><img src="images/shellfig4.png" alt="Shell with pop-up" /><br />
    Figure 4. Auto-CompletionPopup Menu</p>
    <p>There are three ways to find the text you wish to type to complete this 
    portion of the descriptor:</p>
    <ol>
      <li>You can keep typing. The popup menu uses incremental search to keep
      scrolling to the next string that matches what you are typing.</li>
      <li>You can scroll the popup menu with the mouse in the usual way and
      select the proper completion string.</li>
      <li>You can use the arrow keys to move around inside the popup menu and
      select the proper completion string.</li>
    </ol>
    <p>Once you have selected the completion string you want, you can press Enter
    or the Tab key to insert it into the text at the insertion point.</p>
    <p>If the auto-completion menu gets in your way, you can click anywhere 
    outside its boundaries or simply press the ESCape key to close it.</p>
    <p>You can turn this auto-completion feature on and off by typing appropriate
    commands in the shell. To turn the feature on, type in the shell:</p>
    <p class="code">shell.autoComplete = 1</p>
    <p>To turn the feature off, substitute a zero in the above command.</p>
    <p>Special Python attributes are prefixed with underscore characters. Some 
    of these attributes use only a single underscore while others use two. You 
    can include or exclude each of these types of attributes in the 
    auto-completion list that appears in the shell by setting two different 
    variables: autoCompleteIncludeSingle and autoCompleteIncludeDouble. For 
    example, to exclude attributes preceded by single underscores from the list, 
    type:</p>
    <p class="code">shell.autoCompleteIncludeSingle = 0</p>
    <p>Similarly, setting autoCompleteIncludeSingle to a value of 1 will include 
    those attributes. The same is true for the autoCompleteIncludeDouble 
    setting.</p>
    <p>Python objects include another type of attribute, often referred to as 
    &quot;magic attributes.&quot; These attributes' values can only be obtained 
    by calling the object's _getAttributeNames() method, if it has one. You can 
    determine whether these attributes are included in the auto-completion popup 
    by setting the variable autoCompleteIncludeMagic to 1 to include them, 0 to 
    exclude them:</p>
    <p class="code">shell.autoCompleteIncludeMagic = 1</p>
    <h3>Documentation Auto-Display in the Shell</h3>
    <p>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 &quot;call tips&quot; 
    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.</p>
    <p>Figure 5 demonstrates this feature. We have typed &quot;os.fdopen(&quot; 
    and the resulting tool tip tells us the required and optional parameters and 
    what the function does as well as what it returns.</p>
    <p class="imageCaption"><img src="images/shellfig5.png" alt="Tool tips in the shell" /><br />
    Figure 5. Tool Tip Shows Documentation String While Typing Functions and Methods</p>
    <p>Virtually all of PythonCard's built-in functions and methods have 
    docstrings associated with them or will have prior to the final release of 
    the product.</p>
    <h3>Editing and Retrieving Functions and Compound Statements in the Shell</h3>
    <p>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.</p>
    <p>You may find yourself occasionally wanting to re-execute multiple 
    <em>commands</em> , 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.</p>
    <p>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 <em>retain</em> 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.</p>
    <?php include "footer.php" ?>
    <p>$Revision: 1.5 $ : $Author: kasplat $ : Last updated $Date: 2004/07/26 15:35:31 $</p>
    </div>
  </body>
</html>