Using Pythonista

This page gives an overview of the Pythonista UI and also contains some useful tips and tricks to help you get the most out of it.

The Script Library

../_images/library.png

The Pythonista UI is divided into three panels: The script library, the code editor, and the interactive prompt. You can switch between these panels with left and right swipe gestures.

The script library shows all the scripts you’ve written and those that are included as examples. You can either view them as a list, or as code snippet previews. Tap the button in the lower-right corner to switch between the two viewing modes.

To create a new script, tap the new_icon button. You can either start with a blank slate, or a choose a template that makes it easier to work with the interactive graphics capabilities of the scene module.

To delete scripts or create new folders, tap the Edit button. You can then select one or more scripts and use the buttons at the bottom to delete the selected files or to move them to a different folder.

The script library also shows non-Python files, e.g. data files that your scripts work with. For common file types (e.g. images, PDFs), a QuickLook preview is shown when you select them in the list.

The Interactive Prompt

The interactive prompt is the easiest way to get started with Python. Every time you enter a line of code, it is executed immediately, so you get quick feedback and can experiment with the syntax. Even if you know nothing about Python, you’ll be able to use the prompt as a powerful calculator.

../_images/prompt.png

You can get to the prompt at any time by doing a left swipe gesture. This area is also used for text output of any scripts that you run and for keyboard input (e.g. when you use the raw_input() function, see the included Random Numbers script for an example).

When you enter code, completions are suggested automatically. If you find this distracting, you can turn it off in the settings. To repeat a command you’ve used before, you can use the history popup.

The output area is also used to show images that you create with the PIL (Python Imaging Library). You can see this in the included “Image Effects” example.

The Editor

If you’ve used any programming editor before, you’ll probably feel right at home in Pythonista. For the most part, the editor behaves very similar to any other text area on iOS, but there are some additional features that might not be obvious at first.

First off, the keyboard contains additional keys with special characters that are useful for programming. These additional keys also work as a gesture area: You can slide across them with your finger to move the cursor, which makes it easier to position it precisely.

../_images/keyboard.png

For navigating in complex scripts, you can tap the name of the script at the top of the screen, to get a popup of all functions, classes, and methods. This is also where you can rename a file.

If you use the scene or sound modules, you can use the + button at the top to insert images, sounds, colors and fonts. The colors and fonts can also be useful for the console and canvas modules.

../_images/actions.png

One very powerful feature of the editor is that it is programmable itself. You can use the editor module for replacing text, positioning the cursor, etc. You can then add your own scripts to the action menu (from the settings), so that you can run them directly from the editor when working on a different script. Have a look at the documentation about the editor module for some interesting examples.

Tip: Tap with two fingers to select an entire line.

Using External Keyboards

You can connect a Bluetooth keyboards to your iOS device from the system preferences. Pythonista supports all the common keyboard shortcuts and a few additional ones.

Common keyboard shortcuts (these work in all text areas on iOS):

  • Command + X – Cut
  • Command + C – Copy
  • Command + V – Paste
  • Command + Z – Undo
  • Command + Shift + Z – Redo
  • Command + A – Select All

Pythonista keyboard shortcuts:

  • Command + R – Run
  • Command + Space Bar – Switch between editor and interactive prompt
  • Command + F – Toggle search
  • Command + K – Clear console output

Please note that these shortcuts only work when a text area has keyboard focus.

The Pythonista URL Scheme

Pythonista can be launched from other apps using the pythonista://... URL scheme. For more information and a reference of the parameters you can pass, please read the chapter The Pythonista URL Scheme.

Settings

../_images/settings.png

You can access the settings from anywhere by tapping the gear icon.

Editor

  • Color Theme: Allows you to change the syntax highlighting colors
  • Editor Font: Select from five different monospace fonts
  • Editor Font Size: The size of the font to use in the editor (from 12 to 24)
  • Line Spacing: The line spacing in the editor (between 1.0 and 1.5)
  • Indentation: You can configure the width of tab characters in the editor, and whether to use spaces (“soft tabs”) for indentation. Note that the built-in examples are written with “hard” tabs, so if you want to edit them, it’s recommended that you either leave “soft tabs” off, or that you use the built-in “Convert Indentation...” action before editing. The Show Mixed Indentation setting makes the other sort of indentation characters visible in the editor, i.e. if you use soft tabs, tab characters are made visible.
  • Code Completion: Enable or disable code completion suggestions in the editor (there is a separate setting for code completion in the interactive prompt)
  • Auto-Pair Characters: Controls whether the closing part of paired characters, like parentheses or brackets, is inserted automatically
  • Highlight Matching ( ): Controls whether matching pairs of parentheses are highlighted when positioning the cursor (also applies to brackets and curly braces)
  • Actions Menu: Allows you to remove built-in actions (e.g. “Copy”, “Convert Indentation”) from the actions menu. Custom script actions can be added directly from the menu.

Interactive Prompt

  • Output Font: The font to use for text output
  • Output Font Size: The font size in the text output area
  • Code Completion: Enable or disable code completion in the interactive prompt (there is a separate setting for code completion in the script editor)