Appendix A: Frame-based editing – the basics
A.1. Basic editing
The Strype editor allows the creation and manipulation of Python programs using the mouse or keyboard. All editing can be achieved with keyboard commands.
Frames
In Strype, program statements are represented by frames – coloured boxes which may be nested within each other (shown under the "My code" heading in Figure A.1). Each Python statement is represented by a frame.
Some frames have a distinctive background colour. Simple frames (such as assignments or function calls) have the same colour as the code background, and no visible outline. They are still frames, and can be manipulated like all other frames.
Frames have slots – areas that must be filled in to complete the frame. Text slots are used for expressions and accept textual input. Frame slots hold nested frames. In an if-statement, for example, the condition is held in a text slot, while the body is held in a frame slot.
Inserting frames
Strype has a frame cursor (the blue bar in Figure A.1) that indicates the current editing position.
A panel in the top right of the main interface (the frame palette) shows all available frames which may be inserted at the current cursor position (see Figure A.1).
A frame can be inserted at the current position in one of three ways:
-
You can click on the frame in the frame palette with the mouse.
-
You can press
SpaceorTABto move focus to the frame palette and then press the shortcut key shown there. For example, pressingSpace–wwill insert a while-loop, orSpace–cwill insert a function call. -
You can just start typing a Python statement at the frame cursor. As soon as it is clear what kind of statement you want, Strype will convert your input into the appropriate frame. For example, if you type
"if "(with the space character at the end), Strype will insert an if-frame. If you type"=", you will get an assignment frame.
Tip: Several frames can be inserted without first typing the Space or TAB key. They are a comment, an assignment, and a blank line. This is because they can be immediately converted: when you insert them as text, it is immediately clear what type of frame you want, and you will instantly see the right frame.
Cursor movement and selection
The frame cursor is moved using the cursor keys, which can also be used to select one of more frames.
| Key | Function |
|---|---|
|
Move the frame cursor one line up or down. |
|
Enter the next/previous text slot. |
|
Select text in the current text slot. |
|
Move the frame cursor up/down at the current frame level (MacOS). |
|
Move the frame cursor up/down at the current frame level (Windows). |
|
Select the frame(s) above/below the cursor. Use repeatedly to select multiple frames. |
Surrounding frames
You can wrap existing frames in a surrounding control frame (such as a loop or conditional), by selecting the intended body frame(s), and then inserting the control frame.
For example, try selecting a few frames, and then press Space–i to insert an if-frame. This will place the selected frames inside an if-statement.
Surrounding text
Similar functionality exists in text slots. If you insert a symbol that is usually used as a pair, such as a bracket, parenthesis, or quote, the matching closing symbol is automatically added as well.
If you wish to add quotes or brackets to existing text, select the text to go inside the brackets first:
and then insert the surrounding character:
This applies to all paired characters, including all quotes and bracket types.
The context menu
Right-clicking a frame with the mouse displays its context menu (Figure A.2). The context menu offers some useful functions for frames.
Context menu functions can be applied to multiple frames at the same time by first creating a multi-frame selection, and then using the context menu.
Some context menu functions can be applied using keyboard shortcuts; these are shown in the context menu.
Deleting frames
Frames can be deleted using the backspace and delete keys.
For a compound frame (such as an if-statement or a loop), the entire frame can be deleted (including children), or the outer frame can be deleted, leaving the body intact.
To delete the entire frame, place the cursor after the frame and use backspace.
To delete just the outer frame, place the cursor after the frame header and use backspace.
These functions can also be applied via the context menu.
Moving frames
To move a frame, drag it with the mouse pointer to the desired location (Figure A.3). The purple frame cursor indicates the potential target location. Note that you will need to drag from an area with the frame background as dragging text will select it; we find it easiest to drag the right-hand end of the frames where often there is no text.
Frames can also be moved using the keyboard with frame selection, followed by cut/paste operations.
A.2. Convenience functions
Auto-completion
When inserting function calls or assignments, auto-completion can offer available identifiers. To activate auto-completion, use Ctrl-Space. This displays the auto-complete dialogue (Figure A.4); typing a prefix narrows the offered selection. Use the arrow keys and Enter to select an offered choice.
Instant auto-complete
If, with the frame cursor visible, you activate auto-completion (Ctrl-Space), a function call frame will be inserted and auto-complete activated in one action. There is no need to insert the function call frame separately first.
Auto-completion for strings
If you use auto-completion (Ctrl-Space) while the cursor is inside a string, the auto-completion dialogue will offer all file names for file available in Strype’s built-in, read-only file system.
Disabling frames
Frames can be temporarily disabled without a need to delete them. Disabling is used in Strype instead of "commenting out" code. Disabled frames are shown with a blurred appearance.
Frames can be disabled using the context menu, or the keyboard shortcut shown in the menu.
If multiple frames are selected when the Disable keyboard shortcut is used, the state of each frame is toggled. This can be used to alternate between two different test statements: If one test statement is enabled and the other is disabled, select both frames and invoke the 'Disable' toggle. This will alternately activate each statement.