Upload 16 files
Browse files- Appex.md +164 -0
- Canvas.md +367 -0
- Console.md +104 -0
- Dialogs.md +139 -0
- Editor.md +141 -0
- FAQ.md +84 -0
- Location.md +61 -0
- Motion.md +29 -0
- Notifications.md +89 -0
- ObjectiveC.md +303 -0
- Scene.md +0 -0
- Shortcuts.md +111 -0
- Sound.md +183 -0
- URLScheme.md +69 -0
- Ui.md +0 -0
- WhatsNew.md +633 -0
Appex.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`appex`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#module-appex "appex: Utilities for Pythonista's Share Sheet Extension") — Utilities for Pythonista’s Share Sheet Extension[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#module-appex "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`appex`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#module-appex "appex: Utilities for Pythonista's Share Sheet Extension") module provides functions for interacting with Pythonista’s share sheet extension that allows you to use Python scripting within other apps on iOS.
|
| 4 |
+
|
| 5 |
+
## The Share Extension[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#the-share-extension "Permalink to this heading")
|
| 6 |
+
|
| 7 |
+
Note
|
| 8 |
+
|
| 9 |
+
See also: [Pythonista Shortcuts / Share Extension](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/pythonista_shortcuts.html#pythonista-share-extension)
|
| 10 |
+
|
| 11 |
+
Pythonista’s _share_ extension allows you to process data from other apps through the standard iOS share sheet.
|
| 12 |
+
|
| 13 |
+
To use it for the first time, you have to invoke the share sheet in some app that supports it, e.g. Safari, then tap either “More…” (iOS 12 and earlier) or “Edit Actions…” (iOS 13+) turn on the “Run Pythonista Script” action. You only need to do this once – after you’ve activated the action, it will show up automatically.
|
| 14 |
+
|
| 15 |
+
After it’s activated, you can invoke a “Mini Pythonista” from almost any app that uses the share sheet. The _share_ extension includes an interactive console, a basic script editor, and you can add shortcut icons for running your favorite scripts quickly.
|
| 16 |
+
|
| 17 |
+
When an app uses the share sheet, it typically passes some data to it – e.g. the current page’s URL in Safari, text in Notes, or an image in Photos. You can access (and process) that data using the functions in this module, e.g. [`appex.get_url()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_url "appex.get_url"), [`appex.get_text()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_text "appex.get_text") etc.
|
| 18 |
+
|
| 19 |
+
Special considerations for running scripts in the share extension:
|
| 20 |
+
|
| 21 |
+
- When you present a [`ui.View`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.View "ui.View") (using [`ui.View.present()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.View.present "ui.View.present")), the presentation style is ignored. On iPhone, the presentation is always full-screen, on iPad, the view will cover the main view of the app extension, and it’s not possible to create full-screen views.
|
| 22 |
+
|
| 23 |
+
- Some functions, most importantly [`webbrowser.open()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/webbrowser.html#webbrowser.open "webbrowser.open"), will not work within a share extension script. The [`notification`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS")module is also unavailable.
|
| 24 |
+
|
| 25 |
+
- The camera is not available to app extensions, so [`photos.capture_image()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/photos.html#photos.capture_image "photos.capture_image")will not work.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## The Today Widget[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#the-today-widget "Permalink to this heading")
|
| 29 |
+
|
| 30 |
+
Warning
|
| 31 |
+
|
| 32 |
+
This module still contains functions related to Pythonista’s iOS 8-style “Today Widget”. While the widget is still part of Pythonista and works on iOS 16, it is not recommended to use it anymore, and it might not be supported on future versions of iOS. Directly converting this to a new (iOS 15-style) widget is not possible, because the entire concept of widgets has changed quite a bit. If you just want to trigger a script from a widget, you might also want to consider using the Shortcuts app widget instead (see also [Siri and Shortcuts App](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/pythonista_shortcuts.html#siri-shortcuts)).
|
| 33 |
+
|
| 34 |
+
The _Today widget_ allows you to run a single script within a widget that is quickly accessible from anywhere on iOS, by pulling down Notification Center (and showing the “Today” tab), on the first page of the home screen, or even from the lock screen (by swiping right).
|
| 35 |
+
|
| 36 |
+
To activate the Today widget, you have to tap the _Edit_ button in the Today view, and select the Pythonista widget. You also have to select a script that the widget should run – you can do this in Pythonista’s settings. To get started, you may want to try one of the scripts in the included _Examples/Widget_ folder.
|
| 37 |
+
|
| 38 |
+
Note
|
| 39 |
+
|
| 40 |
+
The Today widget requires iOS 10 or later, and only supports Python 3.
|
| 41 |
+
|
| 42 |
+
The selected script will run every time the widget is shown. Typically, it will use the [`set_widget_view()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.set_widget_view "appex.set_widget_view") function to show a simple user interface (created with the [`ui`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#module-ui "ui: Native GUI for iOS") module) in the widget.
|
| 43 |
+
|
| 44 |
+
Compared to the share extension, the capabilities of the Today widget are more limited. Only a subset of Pythonista’s APIs are available, and it gets a significantly smaller amount of RAM from the system than both the main app and the share extension.
|
| 45 |
+
|
| 46 |
+
Special considerations for running scripts in the Today widget:
|
| 47 |
+
|
| 48 |
+
Warning
|
| 49 |
+
|
| 50 |
+
Memory is very limited in the widget – if your script runs well in the main app, but you see a “Could not load” message in the widget (or the widget is empty), it is likely that your script used too much memory and was terminated by the system. You can also try rebooting your device when this happens.
|
| 51 |
+
|
| 52 |
+
- Dialogs (everything in the [`dialogs`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#module-dialogs "dialogs"), [`console.alert()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.alert "console.alert") etc.) are _not_ available in the widget.
|
| 53 |
+
|
| 54 |
+
- The [`ui.View.present()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.View.present "ui.View.present") method is not available. To show a user interface in the widget, you have to use the [`set_widget_view()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.set_widget_view "appex.set_widget_view") function.
|
| 55 |
+
|
| 56 |
+
- If you find the widget getting stuck, you can terminate the process manually by tapping and holding it with two fingers for about 3 seconds.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
## Functions[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#functions "Permalink to this heading")
|
| 60 |
+
|
| 61 |
+
appex.is_running_extension()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.is_running_extension "Permalink to this definition")
|
| 62 |
+
|
| 63 |
+
Return True if the script is running within an app extension (share extension or widget), False otherwise.
|
| 64 |
+
|
| 65 |
+
In case you want to test your script in the main app, you can e.g. use this to load dummy data to replace the share sheet’s input.
|
| 66 |
+
|
| 67 |
+
appex.is_widget()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.is_widget "Permalink to this definition")
|
| 68 |
+
|
| 69 |
+
Return True if the script is running within the Today widget, False otherwise.
|
| 70 |
+
|
| 71 |
+
appex.finish(_js=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.finish "Permalink to this definition")
|
| 72 |
+
|
| 73 |
+
Close the share sheet extension. The optional js parameter is only relevant when the extension is shown in Safari. It specifies a piece of JavaScript code that is evaluated in the context of the current web page, after the Pythonista sheet is closed. Calling this function from the main app has no effect.
|
| 74 |
+
|
| 75 |
+
appex.get_attachments(_uti='public.data'_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_attachments "Permalink to this definition")
|
| 76 |
+
|
| 77 |
+
Return a list of attachments that match the given type identifier. In most cases, it is a lot easier to use the type-specific functions (like [`get_image()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_image "appex.get_image"), [`get_url()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_url "appex.get_url")…) instead.
|
| 78 |
+
|
| 79 |
+
appex.get_images(_image_type='pil'_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_images "Permalink to this definition")
|
| 80 |
+
|
| 81 |
+
Return a list of images in the input of the share sheet. image_type can be either ‘ui’ or ‘pil’. If the type is ‘ui’, [`ui.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.Image "ui.Image") instances will be returned, otherwise [`PIL`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html#module-PIL "PIL") images. If there are no images in the input, the return value will be an empty list.
|
| 82 |
+
|
| 83 |
+
appex.get_image(_image_type='pil_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_image "Permalink to this definition")
|
| 84 |
+
|
| 85 |
+
Return the first image in the input of the share sheet. image_type can be either ‘ui’ or ‘pil’. If the type is ‘ui’, a [`ui.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.Image "ui.Image") instance will be returned, otherwise a [`PIL`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html#module-PIL "PIL") image. If there are no images in the input, the return value will be an empty list.
|
| 86 |
+
|
| 87 |
+
appex.get_image_data()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_image_data "Permalink to this definition")
|
| 88 |
+
|
| 89 |
+
Return raw image data for the first image in the share sheet’s input. The data is returned as a byte string. If there is no image in the input, the return value is None.
|
| 90 |
+
|
| 91 |
+
appex.get_images_data()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_images_data "Permalink to this definition")
|
| 92 |
+
|
| 93 |
+
Return raw image data for all images in the share sheet’s input. The data is returned as a list of byte strings. If there are no images in the input, the return value is an empty list.
|
| 94 |
+
|
| 95 |
+
appex.get_text()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_text "Permalink to this definition")
|
| 96 |
+
|
| 97 |
+
Return text input of the share sheet (as a unicode string). If there is no text in the input, the return value is None.
|
| 98 |
+
|
| 99 |
+
appex.get_urls()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_urls "Permalink to this definition")
|
| 100 |
+
|
| 101 |
+
Return a list of URLs in the share sheet’s input. If there are no URLs in the input, the return value is an empty list.
|
| 102 |
+
|
| 103 |
+
appex.get_url()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_url "Permalink to this definition")
|
| 104 |
+
|
| 105 |
+
Return the first URL in the share sheet’s input. If there is no URL in the input, the return value is None.
|
| 106 |
+
|
| 107 |
+
appex.get_file_paths()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_file_paths "Permalink to this definition")
|
| 108 |
+
|
| 109 |
+
Return a list of file paths in the share sheet’s input. If there are no file paths in the input, the return value is an empty list.
|
| 110 |
+
|
| 111 |
+
appex.get_file_path()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_file_path "Permalink to this definition")
|
| 112 |
+
|
| 113 |
+
Return the first file path in the share sheet’s input. If there is no file path in the input, the return value is None.
|
| 114 |
+
|
| 115 |
+
appex.get_vcards()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_vcards "Permalink to this definition")
|
| 116 |
+
|
| 117 |
+
Return a list of VCard records in the share sheet’s input. Each record is represented as a string. If there are no Vcards in the input, the return value is an empty list.
|
| 118 |
+
|
| 119 |
+
appex.get_vcard()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_vcard "Permalink to this definition")
|
| 120 |
+
|
| 121 |
+
Return the first VCard record in the share sheet’s input. The record is represented as a string. If there are no Vcards in the input, the return value is None.
|
| 122 |
+
|
| 123 |
+
appex.get_web_page_info()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_web_page_info "Permalink to this definition")
|
| 124 |
+
|
| 125 |
+
When the share sheet is shown in Safari, return information about the currently loaded page. The return value is a dict, and usually contains the following keys (all values are unicode strings):
|
| 126 |
+
|
| 127 |
+
- `'url'`: The full URL of the page (`document.URL`) – if you need only this value, you can use [`get_url()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_url "appex.get_url") instead (which also works in other apps)
|
| 128 |
+
|
| 129 |
+
- `'title'`: The title of the page (`document.title`)
|
| 130 |
+
|
| 131 |
+
- `'html'`: The HTML source code of the page – Please note that this is constructed from `document.documentElement.outerHTML`, and may not necessarily be exactly the same as what was loaded from the server (e.g. in case of DOM manipulation via JavaScript etc.)
|
| 132 |
+
|
| 133 |
+
- `'selection_html'`: Selected text (in HTML format, preserves formatting, links etc.)
|
| 134 |
+
|
| 135 |
+
- `'selection_text'`: Selected text (as plain text)
|
| 136 |
+
|
| 137 |
+
- `'cookie'`: The value of `document.cookie`
|
| 138 |
+
|
| 139 |
+
- `'referrer'`: The value of `document.referrer`
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
Missing values are represented by an empty string.
|
| 143 |
+
|
| 144 |
+
If the share sheet is shown in another app (not Safari), or if information about the current page cannot be retrieved, an empty dict is returned.
|
| 145 |
+
|
| 146 |
+
appex.get_widget_view()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.get_widget_view "Permalink to this definition")
|
| 147 |
+
|
| 148 |
+
Warning
|
| 149 |
+
|
| 150 |
+
The “Today Widget” is deprecated, please see the note [here](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#today-widget).
|
| 151 |
+
|
| 152 |
+
Return the view that is currently shown in the Today widget (or None if no view was set via [`set_widget_view()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.set_widget_view "appex.set_widget_view")).
|
| 153 |
+
|
| 154 |
+
appex.set_widget_view(_view_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#appex.set_widget_view "Permalink to this definition")
|
| 155 |
+
|
| 156 |
+
Warning
|
| 157 |
+
|
| 158 |
+
The “Today Widget” is deprecated, please see the note [here](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/appex.html#today-widget).
|
| 159 |
+
|
| 160 |
+
Set the widget’s view to a [`ui.View`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.View "ui.View") object. The view is automatically resized to fill the widget, and the view’s current height is used as the expanded height of the widget (when the “Show More” button is tapped). If the view’s height is <= 120, the widget does not show a “Shore More” button, and only the compact widget display mode is used.
|
| 161 |
+
|
| 162 |
+
To remove the current view from the widget, pass None instead of a view object.
|
| 163 |
+
|
| 164 |
+
If the script is running in the main app, a simulated widget view is shown.
|
Canvas.md
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`canvas`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") — Vector Graphics[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#module-canvas "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
## Introduction[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#introduction "Permalink to this heading")
|
| 4 |
+
|
| 5 |
+
The [`canvas`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") module contains functions for creating non-interactive, 2D vector graphics on iOS. It is suitable for drawing simple graphs/diagrams or line art.
|
| 6 |
+
|
| 7 |
+
All functions work on a single canvas that is shown in the output area of Pythonista. Images created this way can be exported to the device’s photo library or copied to the clipboard, though it is currently not possible to do this programmatically.
|
| 8 |
+
|
| 9 |
+
The coordinate system has its origin in the bottom-left corner, coordinates are floats. Colors are generally represented as RGB(A) with components in the range 0.0 - 1.0.
|
| 10 |
+
|
| 11 |
+
Minimal example that draws a red circle:
|
| 12 |
+
|
| 13 |
+
#Draw a red circle filling the entire canvas
|
| 14 |
+
import canvas
|
| 15 |
+
w = h = 512
|
| 16 |
+
canvas.set_size(w, h)
|
| 17 |
+
canvas.set_fill_color(1, 0, 0)
|
| 18 |
+
canvas.fill_ellipse(0, 0, w, h)
|
| 19 |
+
|
| 20 |
+
## Configuring the Canvas[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#configuring-the-canvas "Permalink to this heading")
|
| 21 |
+
|
| 22 |
+
The following functions can be used to configure the overall drawing behavior of the canvas. You typically begin any drawing by calling [`set_size()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_size "canvas.set_size").
|
| 23 |
+
|
| 24 |
+
If you want to improve the performance of your drawing, you might want to add a call to [`begin_updates()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_updates "canvas.begin_updates") before you start drawing, balanced by a call to [`end_updates()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.end_updates "canvas.end_updates") at the end. This will basically avoid showing intermediate results, which speeds things up, but it might also often be helpful to see these intermediate results while working on your drawing code.
|
| 25 |
+
|
| 26 |
+
canvas.clear()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.clear "Permalink to this definition")
|
| 27 |
+
|
| 28 |
+
Clears the canvas. You can also clear the canvas with the [`set_size()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_size "canvas.set_size") function, which also resets all graphics state (e.g. transformations, fill color, etc.).
|
| 29 |
+
|
| 30 |
+
canvas.get_size()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.get_size "Permalink to this definition")
|
| 31 |
+
|
| 32 |
+
Return the size of the canvas as a tuple of width and height.
|
| 33 |
+
|
| 34 |
+
canvas.set_size(_width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_size "Permalink to this definition")
|
| 35 |
+
|
| 36 |
+
Set the size of the canvas (min. 16x16, max. 2048x2048) and reset all graphics state (e.g. transformations, fill color, etc.).
|
| 37 |
+
|
| 38 |
+
canvas.begin_updates()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_updates "Permalink to this definition")
|
| 39 |
+
|
| 40 |
+
Begins a group of drawing operations. Results will not be visible until[`end_updates()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.end_updates "canvas.end_updates") is called. This can significantly improve performance.
|
| 41 |
+
|
| 42 |
+
canvas.end_updates()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.end_updates "Permalink to this definition")
|
| 43 |
+
|
| 44 |
+
Forces all buffered drawing to be displayed on the screen
|
| 45 |
+
|
| 46 |
+
(see also [`begin_updates()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_updates "canvas.begin_updates"))
|
| 47 |
+
|
| 48 |
+
canvas.save_png(_filename_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_png "Permalink to this definition")
|
| 49 |
+
|
| 50 |
+
Save the current content of the canvas to a PNG file.
|
| 51 |
+
|
| 52 |
+
## Setting Drawing Parameters[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#setting-drawing-parameters "Permalink to this heading")
|
| 53 |
+
|
| 54 |
+
Using these functions affects any drawing operations that follow. For example, calling [`set_fill_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_fill_color "canvas.set_fill_color") with a red color will make any following call to [`fill_rect()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_rect "canvas.fill_rect") draw a red rectangle, until you set a different color.
|
| 55 |
+
|
| 56 |
+
canvas.set_aa_enabled(_flag_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_aa_enabled "Permalink to this definition")
|
| 57 |
+
|
| 58 |
+
Enables or disables antialiasing.
|
| 59 |
+
|
| 60 |
+
canvas.set_alpha(_alpha_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_alpha "Permalink to this definition")
|
| 61 |
+
|
| 62 |
+
Sets the global alpha value.
|
| 63 |
+
|
| 64 |
+
(see also [`set_blend_mode()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_blend_mode "canvas.set_blend_mode"))
|
| 65 |
+
|
| 66 |
+
canvas.set_blend_mode(_mode_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_blend_mode "Permalink to this definition")
|
| 67 |
+
|
| 68 |
+
Sets the active blend mode. Can be one of the constants listed under [Blend Modes](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#blend-modes).
|
| 69 |
+
|
| 70 |
+
(see also [`set_alpha()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_alpha "canvas.set_alpha"))
|
| 71 |
+
|
| 72 |
+
canvas.set_fill_color(_r_, _g_, _b_[, _a_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_fill_color "Permalink to this definition")
|
| 73 |
+
|
| 74 |
+
Sets the fill color.
|
| 75 |
+
|
| 76 |
+
canvas.set_line_width(_width_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_line_width "Permalink to this definition")
|
| 77 |
+
|
| 78 |
+
Sets the line width.
|
| 79 |
+
|
| 80 |
+
(see also [`set_stroke_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_stroke_color "canvas.set_stroke_color"))
|
| 81 |
+
|
| 82 |
+
canvas.set_stroke_color(_r_, _g_, _b_[, _a_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_stroke_color "Permalink to this definition")
|
| 83 |
+
|
| 84 |
+
Sets the active stroke color.
|
| 85 |
+
|
| 86 |
+
(see also [`set_line_width()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_line_width "canvas.set_line_width"))
|
| 87 |
+
|
| 88 |
+
## Vector Drawing Functions[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#vector-drawing-functions "Permalink to this heading")
|
| 89 |
+
|
| 90 |
+
The following functions are used for drawing vector paths and shapes.
|
| 91 |
+
|
| 92 |
+
The canvas always has a current path that can be manipulated with the add_… functions. You can construct arbitrarily complex paths using[`add_line()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_line "canvas.add_line"), [`add_curve()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_curve "canvas.add_curve"), etc. and then fill or stroke the path with [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path") or [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"). If you intend to fill a path, you might want to close it first with [`close_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.close_path "canvas.close_path").
|
| 93 |
+
|
| 94 |
+
Filling or drawing a path has the side effect of clearing the current path.
|
| 95 |
+
|
| 96 |
+
The following example draws a star shape with some configurable parameters:
|
| 97 |
+
|
| 98 |
+
#Draw a star
|
| 99 |
+
import canvas
|
| 100 |
+
from math import sin, cos, pi
|
| 101 |
+
|
| 102 |
+
def draw_star(x, y, inner_r, outer_r, jags):
|
| 103 |
+
canvas.move_to(w / 2, h / 2 + inner_r)
|
| 104 |
+
for i in range(jags * 2):
|
| 105 |
+
angle = (2 * pi / jags) * i / 2
|
| 106 |
+
r = inner_r if i % 2 == 0 else outer_r
|
| 107 |
+
x = w / 2 + r * sin(angle)
|
| 108 |
+
y = h / 2 + r * cos(angle)
|
| 109 |
+
canvas.add_line(x, y)
|
| 110 |
+
canvas.close_path()
|
| 111 |
+
canvas.set_line_width(3)
|
| 112 |
+
canvas.draw_path()
|
| 113 |
+
|
| 114 |
+
w = h = 600
|
| 115 |
+
jags = 7 #Number of jags
|
| 116 |
+
inner_r = 120 #Inner radius
|
| 117 |
+
outer_r = 250 #Outer radius
|
| 118 |
+
canvas.set_size(w, h)
|
| 119 |
+
draw_star(w/2, h/2, inner_r, outer_r, jags)
|
| 120 |
+
|
| 121 |
+
canvas.add_curve(_cp1x_, _cp1y_, _cp2x_, _cp2y_, _x_, _y_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_curve "Permalink to this definition")
|
| 122 |
+
|
| 123 |
+
Adds a cubic bezier curve to (x, y) to the current path, with the control points (cp1x, cp1y) and (cp2x, cp2y).
|
| 124 |
+
|
| 125 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"), [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path"))
|
| 126 |
+
|
| 127 |
+
canvas.add_ellipse(_x_, _y_, _width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_ellipse "Permalink to this definition")
|
| 128 |
+
|
| 129 |
+
Adds an ellipse to the current path.
|
| 130 |
+
|
| 131 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"), [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path"))
|
| 132 |
+
|
| 133 |
+
canvas.add_line(_x_, _y_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_line "Permalink to this definition")
|
| 134 |
+
|
| 135 |
+
Adds a straight line to the current path.
|
| 136 |
+
|
| 137 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"), [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path"), [`move_to()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.move_to "canvas.move_to"))
|
| 138 |
+
|
| 139 |
+
canvas.add_quad_curve(_cpx_, _cpy_, _x_, _y_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_quad_curve "Permalink to this definition")
|
| 140 |
+
|
| 141 |
+
Adds a quadratic bezier curve to (x, y) to the current path with (cpx, cpy) as the control point.
|
| 142 |
+
|
| 143 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"), [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path"))
|
| 144 |
+
|
| 145 |
+
canvas.add_rect(_x_, _y_, _width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_rect "Permalink to this definition")
|
| 146 |
+
|
| 147 |
+
Adds a rectangle to the current path.
|
| 148 |
+
|
| 149 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"), [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path"))
|
| 150 |
+
|
| 151 |
+
canvas.begin_path()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "Permalink to this definition")
|
| 152 |
+
|
| 153 |
+
Begins a new path. Use [`add_line()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_line "canvas.add_line"), [`add_rect()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_rect "canvas.add_rect"), etc. to add shapes to this path and [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path") or [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path") to make it visible.
|
| 154 |
+
|
| 155 |
+
canvas.clip()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.clip "Permalink to this definition")
|
| 156 |
+
|
| 157 |
+
Clips subsequent drawing to the current path.
|
| 158 |
+
|
| 159 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"))
|
| 160 |
+
|
| 161 |
+
canvas.close_path()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.close_path "Permalink to this definition")
|
| 162 |
+
|
| 163 |
+
Closes the current path.
|
| 164 |
+
|
| 165 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"), [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path"))
|
| 166 |
+
|
| 167 |
+
canvas.draw_ellipse(_x_, _y_, _width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_ellipse "Permalink to this definition")
|
| 168 |
+
|
| 169 |
+
Draws an ellipse in a rectangle
|
| 170 |
+
|
| 171 |
+
(see also [`set_stroke_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_stroke_color "canvas.set_stroke_color"), [`set_line_width()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_line_width "canvas.set_line_width"))
|
| 172 |
+
|
| 173 |
+
canvas.draw_line(_x1_, _y1_, _x2_, _y2_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_line "Permalink to this definition")
|
| 174 |
+
|
| 175 |
+
Draws a line between two points
|
| 176 |
+
|
| 177 |
+
(see also [`set_stroke_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_stroke_color "canvas.set_stroke_color"), [`set_line_width()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_line_width "canvas.set_line_width"))
|
| 178 |
+
|
| 179 |
+
canvas.draw_path()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "Permalink to this definition")
|
| 180 |
+
|
| 181 |
+
Draws the outline of the current path with the active line width and color.
|
| 182 |
+
|
| 183 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`fill_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "canvas.fill_path"), [`set_stroke_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_stroke_color "canvas.set_stroke_color"), [`set_line_width()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_line_width "canvas.set_line_width"))
|
| 184 |
+
|
| 185 |
+
canvas.draw_rect(_x_, _y_, _width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_rect "Permalink to this definition")
|
| 186 |
+
|
| 187 |
+
Draws the outline of a rectangle
|
| 188 |
+
|
| 189 |
+
(see also [`set_stroke_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_stroke_color "canvas.set_stroke_color"), [`set_line_width()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_line_width "canvas.set_line_width"))
|
| 190 |
+
|
| 191 |
+
canvas.fill_ellipse(_x_, _y_, _width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_ellipse "Permalink to this definition")
|
| 192 |
+
|
| 193 |
+
Fills an ellipse in a rectangle
|
| 194 |
+
|
| 195 |
+
(see also [`draw_ellipse()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_ellipse "canvas.draw_ellipse"))
|
| 196 |
+
|
| 197 |
+
canvas.fill_path()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_path "Permalink to this definition")
|
| 198 |
+
|
| 199 |
+
Fills the current path with the active fill color.
|
| 200 |
+
|
| 201 |
+
(see also [`begin_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.begin_path "canvas.begin_path"), [`draw_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_path "canvas.draw_path"), [`set_fill_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_fill_color "canvas.set_fill_color"))
|
| 202 |
+
|
| 203 |
+
canvas.fill_pixel(_x_, _y_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_pixel "Permalink to this definition")
|
| 204 |
+
|
| 205 |
+
Fills a pixel with the current fill color
|
| 206 |
+
|
| 207 |
+
canvas.fill_rect(_x_, _y_, _width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.fill_rect "Permalink to this definition")
|
| 208 |
+
|
| 209 |
+
Fills a rectangle
|
| 210 |
+
|
| 211 |
+
canvas.move_to(_x_, _y_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.move_to "Permalink to this definition")
|
| 212 |
+
|
| 213 |
+
Moves the “pen” to a given point.
|
| 214 |
+
|
| 215 |
+
(see also [`add_line()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.add_line "canvas.add_line"))
|
| 216 |
+
|
| 217 |
+
## Transforms[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#transforms "Permalink to this heading")
|
| 218 |
+
|
| 219 |
+
Using the following transformation functions, you can manipulate the current transformation matrix (CTM) of your canvas. This can for example be used to draw rotated or scaled shapes. When you transform the canvas, you’re essentially changing the coordinate system which affects all drawing that follows this change.
|
| 220 |
+
|
| 221 |
+
It is often useful to be apply a transformation only temporarily. This can be done with the [`save_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_gstate "canvas.save_gstate") and [`restore_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.restore_gstate "canvas.restore_gstate")functions. [`save_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_gstate "canvas.save_gstate") takes a snapshot of the current transformation (and other graphics state parameters, such as fill color) and puts it on a stack. Calling [`restore_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.restore_gstate "canvas.restore_gstate") afterwards restores the last state that was put on the stack.
|
| 222 |
+
|
| 223 |
+
In case you want to completely reset any transformations, but you didn’t save the graphics state, you can use the [`set_size()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_size "canvas.set_size") function.
|
| 224 |
+
|
| 225 |
+
The following example draws a clock face with rotated labels:
|
| 226 |
+
|
| 227 |
+
# Draw a clock face
|
| 228 |
+
import canvas
|
| 229 |
+
from math import pi
|
| 230 |
+
|
| 231 |
+
canvas.set_size(600, 600)
|
| 232 |
+
canvas.set_fill_color(0.7, 0.7, 0.7)
|
| 233 |
+
canvas.fill_ellipse(0, 0, 600, 600)
|
| 234 |
+
canvas.set_fill_color(0, 0, 0)
|
| 235 |
+
canvas.fill_ellipse(290, 290, 20, 20)
|
| 236 |
+
|
| 237 |
+
for i in range(12):
|
| 238 |
+
canvas.save_gstate()
|
| 239 |
+
canvas.translate(300, 300)
|
| 240 |
+
canvas.rotate(-2 * pi / 12.0 * i)
|
| 241 |
+
canvas.set_fill_color(0, 0, 0)
|
| 242 |
+
s = 40
|
| 243 |
+
fnt = 'Helvetica-Bold'
|
| 244 |
+
n = str(12 if i == 0 else i)
|
| 245 |
+
w, h = canvas.get_text_size(n, fnt, s)
|
| 246 |
+
canvas.draw_text(n, -w/2, 240, fnt, s)
|
| 247 |
+
canvas.restore_gstate()
|
| 248 |
+
|
| 249 |
+
canvas.restore_gstate()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.restore_gstate "Permalink to this definition")
|
| 250 |
+
|
| 251 |
+
Sets the current graphics state to the state most recently saved with [`save_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_gstate "canvas.save_gstate").
|
| 252 |
+
|
| 253 |
+
canvas.rotate(_angle_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.rotate "Permalink to this definition")
|
| 254 |
+
|
| 255 |
+
Rotates the current transformation matrix.
|
| 256 |
+
|
| 257 |
+
(see also [`save_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_gstate "canvas.save_gstate"), [`restore_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.restore_gstate "canvas.restore_gstate"))
|
| 258 |
+
|
| 259 |
+
canvas.save_gstate()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_gstate "Permalink to this definition")
|
| 260 |
+
|
| 261 |
+
Pushes a copy of the current graphics state (transformation, selected colors etc.) onto the graphics state stack.
|
| 262 |
+
|
| 263 |
+
(see also [`restore_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.restore_gstate "canvas.restore_gstate"))
|
| 264 |
+
|
| 265 |
+
canvas.scale(_sx_, _sy_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.scale "Permalink to this definition")
|
| 266 |
+
|
| 267 |
+
Scales the current transformation matrix.
|
| 268 |
+
|
| 269 |
+
(see also [`save_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_gstate "canvas.save_gstate"), [`restore_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.restore_gstate "canvas.restore_gstate"))
|
| 270 |
+
|
| 271 |
+
canvas.translate(_tx_, _ty_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.translate "Permalink to this definition")
|
| 272 |
+
|
| 273 |
+
Translates the current transformation matrix.
|
| 274 |
+
|
| 275 |
+
(see also [`save_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.save_gstate "canvas.save_gstate"), [`restore_gstate()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.restore_gstate "canvas.restore_gstate"))
|
| 276 |
+
|
| 277 |
+
## Drawing Bitmap Images[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#drawing-bitmap-images "Permalink to this heading")
|
| 278 |
+
|
| 279 |
+
Although it is primarily designed for vector graphics, the [`canvas`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") module also has some functions for drawing bitmap images, similar to the [`scene`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") module. You can draw named images or the current contents of the clipboard.
|
| 280 |
+
|
| 281 |
+
canvas.draw_image(_image_name_, _x_, _y_[, _width_, _height_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_image "Permalink to this definition")
|
| 282 |
+
|
| 283 |
+
Draws the image with the given name in a rectangle. If width and height are omitted, the image is drawn at its natural size.
|
| 284 |
+
|
| 285 |
+
canvas.draw_clipboard(_x_, _y_, _width_, _height_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_clipboard "Permalink to this definition")
|
| 286 |
+
|
| 287 |
+
Draw the image in the clipboard in a given rectangle.
|
| 288 |
+
|
| 289 |
+
canvas.get_clipboard_size()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.get_clipboard_size "Permalink to this definition")
|
| 290 |
+
|
| 291 |
+
Return the size of the image in the clipboard as a tuple of width and height, in points. On a retina screen, one point corresponds to two pixels. Returns (0,0) if the clipboard is empty.
|
| 292 |
+
|
| 293 |
+
canvas.get_image_size(_image_name_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.get_image_size "Permalink to this definition")
|
| 294 |
+
|
| 295 |
+
Returns the size of the image with the given name as a tuple of width and height, in points. On a retina screen, one point corresponds to two pixels. Returns (0, 0) if no image with this name exists.
|
| 296 |
+
|
| 297 |
+
## Drawing Text[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#drawing-text "Permalink to this heading")
|
| 298 |
+
|
| 299 |
+
The [`canvas`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") module has two simple functions for drawing and measuring text.
|
| 300 |
+
|
| 301 |
+
The color of the text that is drawn with [`draw_text()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_text "canvas.draw_text") is determined by previous calls to [`set_fill_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_fill_color "canvas.set_fill_color").
|
| 302 |
+
|
| 303 |
+
canvas.draw_text(_text_, _x_, _y_, _font_name='Helvetica'_, _font_size=16.0_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.draw_text "Permalink to this definition")
|
| 304 |
+
|
| 305 |
+
Draw a single line of text at a given point. The point represents the origin of the line, i.e. its lower-left corner.
|
| 306 |
+
|
| 307 |
+
canvas.get_text_size(_text_, _font_name='Helvetica'_, _font_size=16.0_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.get_text_size "Permalink to this definition")
|
| 308 |
+
|
| 309 |
+
Get the size of a line of text as it was drawn by the draw_text() function as a tuple of (width, height).
|
| 310 |
+
|
| 311 |
+
## Blend Modes[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#blend-modes "Permalink to this heading")
|
| 312 |
+
|
| 313 |
+
The following blend modes can be used with [`set_blend_mode()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.set_blend_mode "canvas.set_blend_mode"):
|
| 314 |
+
|
| 315 |
+
canvas.BLEND_NORMAL[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_NORMAL "Permalink to this definition")
|
| 316 |
+
|
| 317 |
+
canvas.BLEND_MULTIPLY[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_MULTIPLY "Permalink to this definition")
|
| 318 |
+
|
| 319 |
+
canvas.BLEND_DIFFERENCE[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_DIFFERENCE "Permalink to this definition")
|
| 320 |
+
|
| 321 |
+
canvas.BLEND_SCREEN[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_SCREEN "Permalink to this definition")
|
| 322 |
+
|
| 323 |
+
canvas.BLEND_OVERLAY[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_OVERLAY "Permalink to this definition")
|
| 324 |
+
|
| 325 |
+
canvas.BLEND_DARKEN[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_DARKEN "Permalink to this definition")
|
| 326 |
+
|
| 327 |
+
canvas.BLEND_LIGHTEN[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_LIGHTEN "Permalink to this definition")
|
| 328 |
+
|
| 329 |
+
canvas.BLEND_COLOR_DODGE[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_COLOR_DODGE "Permalink to this definition")
|
| 330 |
+
|
| 331 |
+
canvas.BLEND_COLOR_BURN[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_COLOR_BURN "Permalink to this definition")
|
| 332 |
+
|
| 333 |
+
canvas.BLEND_SOFT_LIGHT[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_SOFT_LIGHT "Permalink to this definition")
|
| 334 |
+
|
| 335 |
+
canvas.BLEND_HARD_LIGHT[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_HARD_LIGHT "Permalink to this definition")
|
| 336 |
+
|
| 337 |
+
canvas.BLEND_DIFFERENCE
|
| 338 |
+
|
| 339 |
+
canvas.BLEND_EXCLUSION[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_EXCLUSION "Permalink to this definition")
|
| 340 |
+
|
| 341 |
+
canvas.BLEND_HUE[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_HUE "Permalink to this definition")
|
| 342 |
+
|
| 343 |
+
canvas.BLEND_SATURATION[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_SATURATION "Permalink to this definition")
|
| 344 |
+
|
| 345 |
+
canvas.BLEND_COLOR[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_COLOR "Permalink to this definition")
|
| 346 |
+
|
| 347 |
+
canvas.BLEND_LUMINOSITY[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_LUMINOSITY "Permalink to this definition")
|
| 348 |
+
|
| 349 |
+
canvas.BLEND_CLEAR[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_CLEAR "Permalink to this definition")
|
| 350 |
+
|
| 351 |
+
canvas.BLEND_COPY[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_COPY "Permalink to this definition")
|
| 352 |
+
|
| 353 |
+
canvas.BLEND_SOURCE_IN[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_SOURCE_IN "Permalink to this definition")
|
| 354 |
+
|
| 355 |
+
canvas.BLEND_SOURCE_OUT[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_SOURCE_OUT "Permalink to this definition")
|
| 356 |
+
|
| 357 |
+
canvas.BLEND_SOURCE_ATOP[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_SOURCE_ATOP "Permalink to this definition")
|
| 358 |
+
|
| 359 |
+
canvas.BLEND_DESTINATION_OVER[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_DESTINATION_OVER "Permalink to this definition")
|
| 360 |
+
|
| 361 |
+
canvas.BLEND_DESTINATION_ATOP[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_DESTINATION_ATOP "Permalink to this definition")
|
| 362 |
+
|
| 363 |
+
canvas.BLEND_XOR[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_XOR "Permalink to this definition")
|
| 364 |
+
|
| 365 |
+
canvas.BLEND_PLUS_DARKER[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/canvas.html#canvas.BLEND_PLUS_DARKER "Permalink to this definition")
|
| 366 |
+
|
| 367 |
+
canvas.BLEND_PLUS_LIGHTER
|
Console.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`console`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#module-console "console: Utilities for Console Output and Various System Services") — Utilities for Console Output and Various System Services[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#module-console "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`console`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#module-console "console: Utilities for Console Output and Various System Services") module provides functions to control the text output area and keyboard input in Pythonista.
|
| 4 |
+
|
| 5 |
+
There are also several functions for presenting simple modal dialogs, and to access system services like the “Open in…” menu and QuickLook.
|
| 6 |
+
|
| 7 |
+
console.clear()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.clear "Permalink to this definition")
|
| 8 |
+
|
| 9 |
+
Clears the console output
|
| 10 |
+
|
| 11 |
+
console.set_font([_name_, _size_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.set_font "Permalink to this definition")
|
| 12 |
+
|
| 13 |
+
Sets the font and font size for following output. Call with no parameters to reset to default.
|
| 14 |
+
|
| 15 |
+
console.set_color(_r_, _g_, _b_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.set_color "Permalink to this definition")
|
| 16 |
+
|
| 17 |
+
Sets the RGB color for following output. The components are floats between 0.0 and 1.0.
|
| 18 |
+
|
| 19 |
+
console.secure_input([_prompt_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.secure_input "Permalink to this definition")
|
| 20 |
+
|
| 21 |
+
This function is similar to the built-in raw_input function, but the user’s input is hidden, so that it’s suitable to request passwords and other sensitive information.
|
| 22 |
+
|
| 23 |
+
console.show_image(_image_path_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.show_image "Permalink to this definition")
|
| 24 |
+
|
| 25 |
+
Show an image, loaded from a file, in the console output area.
|
| 26 |
+
|
| 27 |
+
console.alert(_title_[, _message_, _button1_, _button2_, _button3_, _hide_cancel_button=False_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.alert "Permalink to this definition")
|
| 28 |
+
|
| 29 |
+
Show an alert dialog with up to three custom buttons. The selected button is returned as an integer (button1 => 1 …). Unless hide_cancel_button is True, all alert dialogs contain a ‘Cancel’ button that sends a KeyboardInterrupt.
|
| 30 |
+
|
| 31 |
+
console.input_alert(_title_[, _message_, _input_, _ok_button_title_, _hide_cancel_button=False_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.input_alert "Permalink to this definition")
|
| 32 |
+
|
| 33 |
+
Show a dialog with a single text field. The text field can be pre-filled with the inputparameter. The text that was entered by the user is returned. The ‘Cancel’ button sends a KeyboardInterrupt.
|
| 34 |
+
|
| 35 |
+
console.password_alert(_title_[, _message_, _password_, _ok_button_title_, _hide_cancel_button=False_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.password_alert "Permalink to this definition")
|
| 36 |
+
|
| 37 |
+
Show a dialog with a password entry text field. The password field can be pre-filled with the password parameter. The password that was entered by the user is returned. The ‘Cancel’ button sends a KeyboardInterrupt(which will usually stop the script).
|
| 38 |
+
|
| 39 |
+
console.login_alert(_title_[, _message_, _login_, _password_, _ok_button_title_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.login_alert "Permalink to this definition")
|
| 40 |
+
|
| 41 |
+
Show a dialog with two text fields, one for a login, one for a password. The text fields can be pre-filled with the login and passwordparameters. Returns a tuple of the entered text as (login, password). The ‘Cancel’ button sends a KeyboardInterrupt (which will usually stop the script).
|
| 42 |
+
|
| 43 |
+
console.show_activity()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.show_activity "Permalink to this definition")
|
| 44 |
+
|
| 45 |
+
Show the animated “network activity indicator” in the status bar.
|
| 46 |
+
|
| 47 |
+
The spinner is automatically hidden when a script ends. Calling this function when the spinner is already visible has no effect.
|
| 48 |
+
|
| 49 |
+
console.hide_activity()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.hide_activity "Permalink to this definition")
|
| 50 |
+
|
| 51 |
+
Hide the animated “network activity indicator” in the status bar.
|
| 52 |
+
|
| 53 |
+
The spinner is automatically hidden when a script ends. Calling this function when the spinner is not visible has no effect.
|
| 54 |
+
|
| 55 |
+
console.hud_alert(_message_[, _icon_, _duration_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.hud_alert "Permalink to this definition")
|
| 56 |
+
|
| 57 |
+
Show a HUD-style alert with the given message. The icon can be either `'success'`(the default, a checkmark symbol), or `'error'` (a cross symbol).
|
| 58 |
+
|
| 59 |
+
The duration parameter determines how long the alert is shown on screen. It can be between 0.25 and 5.0 seconds. The default is 1.8 seconds. The function blocks until the alert is dismissed.
|
| 60 |
+
|
| 61 |
+
console.write_link(_title_, _link_url_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.write_link "Permalink to this definition")
|
| 62 |
+
|
| 63 |
+
Print a tappable link to the console with the given title and URL. Depending on the URL, it is either opened in the built-in browser (for http, https and file URLs), or opened in a different app (if possible).
|
| 64 |
+
|
| 65 |
+
If a custom text color is set via [`set_color()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.set_color "console.set_color"), the color of the link text is the same as that, otherwise, a default link color is used.
|
| 66 |
+
|
| 67 |
+
console.hide_output()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.hide_output "Permalink to this definition")
|
| 68 |
+
|
| 69 |
+
Hide the console output area with a sliding animation.
|
| 70 |
+
|
| 71 |
+
console.quicklook(_file_path_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.quicklook "Permalink to this definition")
|
| 72 |
+
|
| 73 |
+
Show a full-screen preview of the local file(s) at the given path. It is possible to pass a sequence of paths (e.g. a list), in order to preview multiple files at once. The function returns when the preview is dismissed.
|
| 74 |
+
|
| 75 |
+
Many common file formats are supported:
|
| 76 |
+
|
| 77 |
+
- iWork documents
|
| 78 |
+
|
| 79 |
+
- Microsoft Office documents (Office ‘97 and newer)
|
| 80 |
+
|
| 81 |
+
- Rich Text Format (RTF) documents
|
| 82 |
+
|
| 83 |
+
- PDF files
|
| 84 |
+
|
| 85 |
+
- Images
|
| 86 |
+
|
| 87 |
+
- Text files whose uniform type identifier (UTI) conforms to the public.text type
|
| 88 |
+
|
| 89 |
+
- Comma-separated value (csv) files
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
console.open_in(_file_path_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.open_in "Permalink to this definition")
|
| 93 |
+
|
| 94 |
+
Show the iOS “Open in…” menu for the specified file.
|
| 95 |
+
|
| 96 |
+
If an application was selected in the menu, its bundle identifier will be returned (for example `'com.getdropbox.Dropbox'`). If the menu was cancelled, or no application is installed that can open the file, the return value is None.
|
| 97 |
+
|
| 98 |
+
console.set_idle_timer_disabled(_flag_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.set_idle_timer_disabled "Permalink to this definition")
|
| 99 |
+
|
| 100 |
+
Disable or enable the idle timer (which puts the device to sleep after a certain period of inactivity).
|
| 101 |
+
|
| 102 |
+
console.is_in_background()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.is_in_background "Permalink to this definition")
|
| 103 |
+
|
| 104 |
+
Return True if the app is currently running in the background, False otherwise.
|
Dialogs.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`dialogs`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#module-dialogs "dialogs") — Easy-to-use UI Dialogs[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#module-dialogs "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`dialogs`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#module-dialogs "dialogs") module provides easy-to-use GUI dialogs for simple data input on iOS. It is mostly built on top of the [`ui`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#module-ui "ui: Native GUI for iOS") module, and while less flexible than using [`ui`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#module-ui "ui: Native GUI for iOS") directly, it is a lot easier to use and requires very few lines of code in most cases.
|
| 4 |
+
|
| 5 |
+
## Overview[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#overview "Permalink to this heading")
|
| 6 |
+
|
| 7 |
+
Most functions in this module present a dialog and return the user’s input. The following kinds of dialogs are supported:
|
| 8 |
+
|
| 9 |
+
- **Text Dialogs** present a multi-line text input area. The font and some keyboard attributes (autocorrection…) are customizable. (see [`text_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.text_dialog "dialogs.text_dialog"))
|
| 10 |
+
|
| 11 |
+
- **List Dialogs** present a list of items, allowing to select one or more of them. (see [`list_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.list_dialog "dialogs.list_dialog"))
|
| 12 |
+
|
| 13 |
+
- **Edit List Dialogs** also present a list of items, but instead of selecting an item, the list can be rearranged by the user, and items can be deleted from the list. (see [`edit_list_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.edit_list_dialog "dialogs.edit_list_dialog"))
|
| 14 |
+
|
| 15 |
+
- **Date/Time Dialogs** present a date picker – there are multiple variants for picking a date, time, or both, and there’s also a mode for picking a countdown/duration, e.g. for timers. (see [`date_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.date_dialog "dialogs.date_dialog"), [`time_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.time_dialog "dialogs.time_dialog"), [`datetime_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.datetime_dialog "dialogs.datetime_dialog"), [`duration_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.duration_dialog "dialogs.duration_dialog"))
|
| 16 |
+
|
| 17 |
+
- **Form Dialogs** present a list of customizable data input fields. The fields can contain switches (for boolean values), text/email/password fields (for strings), date pickers, and checkmarks (for multiple selection lists). This is the most flexible type of dialog, but it also requires the most configuration (see [`form_dialog()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.form_dialog "dialogs.form_dialog"))
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
## Dialog Functions[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialog-functions "Permalink to this heading")
|
| 21 |
+
|
| 22 |
+
dialogs.list_dialog(_title=''_, _items=None_, _multiple=False_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.list_dialog "Permalink to this definition")
|
| 23 |
+
|
| 24 |
+
Present a list of items and return the one(s) that were selected. When the dialog is cancelled, None is returned. The items list can contain any kind of object that can be converted to a string. To get more control over how each item is displayed in the list, you can also use a list of dictionaries (see [`ui.ListDataSource.items`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.ListDataSource.items "ui.ListDataSource.items") for details).
|
| 25 |
+
|
| 26 |
+
dialogs.edit_list_dialog(_title=''_, _items=None_, _move=True_, _delete=True_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.edit_list_dialog "Permalink to this definition")
|
| 27 |
+
|
| 28 |
+
Present a list of items that can be edited by the user. By default, the user can both rearrange the list and remove items; this behavior can be controlled with the move and delete parameters.
|
| 29 |
+
|
| 30 |
+
The return value is the modified list of items, or None if the dialog was cancelled.
|
| 31 |
+
|
| 32 |
+
dialogs.form_dialog(_title=''_, _fields=None_, _sections=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.form_dialog "Permalink to this definition")
|
| 33 |
+
|
| 34 |
+
Present a form dialog, similar to many settings interfaces.
|
| 35 |
+
|
| 36 |
+
Each field in the dialog is configured by dictionary. If there is only a single section of fields, the list of these field dictionaries can be passed as the fields parameter. If there should be multiple sections, each section is represented by a tuple (usually a 2-tuple containing the title of the section and its list of fields; an optional third item can contain footer text for the section).
|
| 37 |
+
|
| 38 |
+
The return value of this function is a dictionary of values for each field (or None, if the dialog was cancelled).
|
| 39 |
+
|
| 40 |
+
A field dictionary should contain the following keys:
|
| 41 |
+
|
| 42 |
+
- `'type'` – (required) the type of the field, this can be `'switch'`, `'text'`, `'url'`, `'email'`, `'password'`, `'number'`, `'check'`, `'datetime'`, `'date'`, or `'time'`
|
| 43 |
+
|
| 44 |
+
- `'key'` – the key of this field in the return value of the form
|
| 45 |
+
|
| 46 |
+
- `'value'` – the initial value of the field (for text/url/email/password/number fields, this should be a string, for switch fields a boolean (True/False), for datetime fields a datetime object)
|
| 47 |
+
|
| 48 |
+
- `'title'` – the human-readable title/label of the field
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
`'type'` is the only required key. If `'key'` is not present, the `'title'` is used instead. If both are missing, fields are numbered sequentially in the returned dictionary.
|
| 52 |
+
|
| 53 |
+
Optional keys for all field types:
|
| 54 |
+
|
| 55 |
+
- `'tint_color'` – the field’s tint color (the effect of this depends on the type of the field)
|
| 56 |
+
|
| 57 |
+
- `'icon'` – the name of a built-in image or a [`ui.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.Image "ui.Image") object
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Optional keys for text/url/email/password/number fields:
|
| 61 |
+
|
| 62 |
+
- `'placeholder'` – the text that is shown when the field is empty
|
| 63 |
+
|
| 64 |
+
- `'autocorrection'` – whether auto-correction should be enabled for this field (True/False)
|
| 65 |
+
|
| 66 |
+
- `'autocapitalization'` – auto-capitalization behavior for the text fields, for possible values, see [`ui.TextField.autocapitalization_type`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.TextField.autocapitalization_type "ui.TextField.autocapitalization_type")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
dialogs.text_dialog(_title=''_, _text=''_, _font=('<system>', 16)_, _autocorrection=None_, _autocapitalization=ui.AUTOCAPITALIZE_SENTENCES_, _spellchecking=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.text_dialog "Permalink to this definition")
|
| 70 |
+
|
| 71 |
+
Show a multi-line text editor sheet.
|
| 72 |
+
|
| 73 |
+
The behavior of the editor can be customized with the autocorrection, autocapitalization, and spellchecking parameters. The textparameter controls the initial text in the editor.
|
| 74 |
+
|
| 75 |
+
The edited text is returned as a string (if the dialog is cancelled, None is returned instead).
|
| 76 |
+
|
| 77 |
+
dialogs.date_dialog(_title=''_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.date_dialog "Permalink to this definition")
|
| 78 |
+
|
| 79 |
+
Show a date picker dialog, the return value is a [`datetime.datetime`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/datetime.html#datetime.datetime "datetime.datetime") object.
|
| 80 |
+
|
| 81 |
+
dialogs.time_dialog(_title=''_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.time_dialog "Permalink to this definition")
|
| 82 |
+
|
| 83 |
+
Show a time picker dialog, the return value is a [`datetime.datetime`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/datetime.html#datetime.datetime "datetime.datetime") object.
|
| 84 |
+
|
| 85 |
+
dialogs.datetime_dialog(_title=''_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.datetime_dialog "Permalink to this definition")
|
| 86 |
+
|
| 87 |
+
Show a date/time picker dialog, the return value is a [`datetime.datetime`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/datetime.html#datetime.datetime "datetime.datetime") object.
|
| 88 |
+
|
| 89 |
+
dialogs.duration_dialog(_title=''_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.duration_dialog "Permalink to this definition")
|
| 90 |
+
|
| 91 |
+
Show a duration picker dialog (e.g. for a countdown timer), the return value is the selected duration in seconds (e.g. 60.0 for 1 minute).
|
| 92 |
+
|
| 93 |
+
## Sharing[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#sharing "Permalink to this heading")
|
| 94 |
+
|
| 95 |
+
dialogs.share_image(_img_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.share_image "Permalink to this definition")
|
| 96 |
+
|
| 97 |
+
Show the system sharing dialog for a given image (can be either a [`ui.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.Image "ui.Image") or a [`PIL.Image.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/pillow/reference/Image.html#PIL.Image.Image "(in Pillow (PIL Fork) v9.0.0)")).
|
| 98 |
+
|
| 99 |
+
dialogs.share_text(_text_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.share_text "Permalink to this definition")
|
| 100 |
+
|
| 101 |
+
Show the system sharing dialog for a given string.
|
| 102 |
+
|
| 103 |
+
dialogs.share_url(_url_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.share_url "Permalink to this definition")
|
| 104 |
+
|
| 105 |
+
Show the system sharing dialog for a given URL.
|
| 106 |
+
|
| 107 |
+
## Importing Files[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#importing-files "Permalink to this heading")
|
| 108 |
+
|
| 109 |
+
dialogs.pick_document(_types=['public.data']_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.pick_document "Permalink to this definition")
|
| 110 |
+
|
| 111 |
+
Show the system’s document picker for importing a file, and return the file’s path (or None if the dialog is canceled).
|
| 112 |
+
|
| 113 |
+
types specifies the Universal Type Identifiers (UTIs) that should be selectable in the document picker. The default (`['public.data']`) makes all regular files selectable. A list of the system-defined UTIs are available in Apple’s [Uniform Type Identifiers Reference](https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html).
|
| 114 |
+
|
| 115 |
+
The return value is a temporary file. You can read it directly, but to keep a permanent copy, you must move it somewhere else.
|
| 116 |
+
|
| 117 |
+
## Alert Functions[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#alert-functions "Permalink to this heading")
|
| 118 |
+
|
| 119 |
+
These functions are imported from the [`console`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#module-console "console: Utilities for Console Output and Various System Services")module for convenience.
|
| 120 |
+
|
| 121 |
+
dialogs.alert()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.alert "Permalink to this definition")
|
| 122 |
+
|
| 123 |
+
see [`console.alert()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.alert "console.alert")
|
| 124 |
+
|
| 125 |
+
dialogs.input_alert()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.input_alert "Permalink to this definition")
|
| 126 |
+
|
| 127 |
+
see [`console.input_alert()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.input_alert "console.input_alert")
|
| 128 |
+
|
| 129 |
+
dialogs.login_alert()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.login_alert "Permalink to this definition")
|
| 130 |
+
|
| 131 |
+
see [`console.login_alert()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.login_alert "console.login_alert")
|
| 132 |
+
|
| 133 |
+
dialogs.password_alert()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.password_alert "Permalink to this definition")
|
| 134 |
+
|
| 135 |
+
see [`console.password_alert()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.password_alert "console.password_alert")
|
| 136 |
+
|
| 137 |
+
dialogs.hud_alert()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/dialogs.html#dialogs.hud_alert "Permalink to this definition")
|
| 138 |
+
|
| 139 |
+
see [`console.hud_alert()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/console.html#console.hud_alert "console.hud_alert")
|
Editor.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`editor`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#module-editor "editor: Scripting Pythonista's text editor") — Functions for scripting Pythonista’s text editor[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#module-editor "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`editor`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#module-editor "editor: Scripting Pythonista's text editor") module provides access to the script you’re currently editing. You can get and set the selected range and replace text in a given range.
|
| 4 |
+
|
| 5 |
+
Please note: Invalid input values for the selection and text manipulation functions (e.g. ranges that are out of bounds) are silently ignored as of now. This may change in a future release.
|
| 6 |
+
|
| 7 |
+
This module is especially useful in combination with the customizable actions menu (new in v1.1). You can add any script from your library to the menu for quickly running it directly from the editor, regardless of which script you’re currently editing. The menu is editable from the settings (Editor > Actions Menu).
|
| 8 |
+
|
| 9 |
+
This enables a couple of very interesting possibilities to extend the capabilities of the Pythonista app itself. To give you some inspiration, here are a couple of snippets that you could use as actions:
|
| 10 |
+
|
| 11 |
+
# Search StackOverflow for selected text
|
| 12 |
+
|
| 13 |
+
import editor
|
| 14 |
+
import webbrowser
|
| 15 |
+
|
| 16 |
+
text = editor.get_text()
|
| 17 |
+
s = editor.get_selection()
|
| 18 |
+
selection = text[s[0]:s[1]]
|
| 19 |
+
if len(selection) > 0:
|
| 20 |
+
from urllib import quote
|
| 21 |
+
q = quote(selection)
|
| 22 |
+
search_url = 'http://stackoverflow.com/search?q=' + q
|
| 23 |
+
webbrowser.open(search_url)
|
| 24 |
+
else:
|
| 25 |
+
from console import alert
|
| 26 |
+
i = alert('No Selection', 'Do you want to open the StackOverflow homepage?', 'StackOverflow')
|
| 27 |
+
if i == 1:
|
| 28 |
+
webbrowser.open('http://stackoverflow.com')
|
| 29 |
+
|
| 30 |
+
This sample searches the populer Q&A site [StackOverflow](http://stackoverflow.com/) for the selected text. If no text is selected, it pops up a dialog, asking if the homepage should be opened instead.
|
| 31 |
+
|
| 32 |
+
As an aside, the [`webbrowser`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for web browsers.") module also works with custom app URL schemes, so you could, for example, open [TweetBot](http://tapbots.com/software/tweetbot/) with `webbrowser.open('tweetbot:///post?text=Hello)`.
|
| 33 |
+
|
| 34 |
+
The following sample shows how to comment/uncomment selected lines, using the [`get_line_selection()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.get_line_selection "editor.get_line_selection") convenience function. It doesn’t require you to select the entirety of the lines you want to comment out, it will work on all lines that your selection is touching.:
|
| 35 |
+
|
| 36 |
+
#Comment/Uncomment selected lines
|
| 37 |
+
|
| 38 |
+
import editor
|
| 39 |
+
|
| 40 |
+
text = editor.get_text()
|
| 41 |
+
selection = editor.get_line_selection()
|
| 42 |
+
selected_text = text[selection[0]:selection[1]]
|
| 43 |
+
is_comment = selected_text.strip().startswith('#')
|
| 44 |
+
replacement = ''
|
| 45 |
+
for line in selected_text.splitlines():
|
| 46 |
+
if is_comment:
|
| 47 |
+
if line.strip().startswith('#'):
|
| 48 |
+
replacement += line[line.find('#') + 1:] + '\n'
|
| 49 |
+
else:
|
| 50 |
+
replacement += line + '\n'
|
| 51 |
+
else:
|
| 52 |
+
replacement += '#' + line + '\n'
|
| 53 |
+
|
| 54 |
+
editor.replace_text(selection[0], selection[1], replacement)
|
| 55 |
+
editor.set_selection(selection[0], selection[0] + len(replacement) - 1)
|
| 56 |
+
|
| 57 |
+
The following functions are provided by the [`editor`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#module-editor "editor: Scripting Pythonista's text editor") module:
|
| 58 |
+
|
| 59 |
+
editor.get_path()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.get_path "Permalink to this definition")
|
| 60 |
+
|
| 61 |
+
Return the absolute file path of the script that is currently open in the editor.
|
| 62 |
+
|
| 63 |
+
If no script is currently open, None is returned.
|
| 64 |
+
|
| 65 |
+
editor.get_text()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.get_text "Permalink to this definition")
|
| 66 |
+
|
| 67 |
+
Return the entire text of the script that is currently being edited.
|
| 68 |
+
|
| 69 |
+
Note that this may be different from reading the file returned from [`get_path()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.get_path "editor.get_path"), as not all changes may have been saved yet.
|
| 70 |
+
|
| 71 |
+
editor.get_selection()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.get_selection "Permalink to this definition")
|
| 72 |
+
|
| 73 |
+
Return the selected range as a tuple of the form (start, end).
|
| 74 |
+
|
| 75 |
+
If no file is currently open in the editor, Noneis returned.
|
| 76 |
+
|
| 77 |
+
editor.get_line_selection()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.get_line_selection "Permalink to this definition")
|
| 78 |
+
|
| 79 |
+
Return the range of all lines that are part of the current selection as a tuple of the form (start, end)
|
| 80 |
+
|
| 81 |
+
If no file is currently open in the editor, Noneis returned.
|
| 82 |
+
|
| 83 |
+
editor.set_selection(_start_, _end=None_, _scroll=False_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.set_selection "Permalink to this definition")
|
| 84 |
+
|
| 85 |
+
Set the selected range in the editor.
|
| 86 |
+
|
| 87 |
+
start and end must be integers. If end is None, the caret is positioned at start with no text selected.
|
| 88 |
+
|
| 89 |
+
editor.replace_text(_start_, _end_, _replacement_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.replace_text "Permalink to this definition")
|
| 90 |
+
|
| 91 |
+
Replace the text in the given range with replacement.
|
| 92 |
+
|
| 93 |
+
To insert/append text, a zero-length range can be used.
|
| 94 |
+
|
| 95 |
+
All changes can be undone by the user (using the regular undo key). Each separate call is a single undo step, regardless of how many characters were affected.
|
| 96 |
+
|
| 97 |
+
editor.make_new_file([_name_, _content_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.make_new_file "Permalink to this definition")
|
| 98 |
+
|
| 99 |
+
Create a new file and open it in the editor.
|
| 100 |
+
|
| 101 |
+
If a file with the given name already exists, a numeric suffix is automatically appended.content should be a string with the content of the new file. If omitted, an empty file is created.
|
| 102 |
+
|
| 103 |
+
The current file is automatically saved before opening the new one.
|
| 104 |
+
|
| 105 |
+
editor.open_file(_name_, _new_tab=False_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.open_file "Permalink to this definition")
|
| 106 |
+
|
| 107 |
+
Open the file with the given name in the editor.
|
| 108 |
+
|
| 109 |
+
Name can be a path filename relative to the script library’s root directory or an absolute path.
|
| 110 |
+
|
| 111 |
+
The .py extension can be omitted. The file that is currently open in the editor will automatically be saved.
|
| 112 |
+
|
| 113 |
+
editor.apply_ui_theme(_ui_view_, _theme_name=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.apply_ui_theme "Permalink to this definition")
|
| 114 |
+
|
| 115 |
+
Style a [`ui.View`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.View "ui.View") (and its descendents) with the given UI theme.
|
| 116 |
+
|
| 117 |
+
If theme_name is None (the default), the currently selected theme is used. Otherwise, it should be the name of a theme as shown in the settings.
|
| 118 |
+
|
| 119 |
+
editor.present_themed(_ui_view_, _theme_name=None_, _**kwargs_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.present_themed "Permalink to this definition")
|
| 120 |
+
|
| 121 |
+
Style a [`ui.View`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.View "ui.View") (and its descendents) with the given UI theme (using [`apply_ui_theme()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.apply_ui_theme "editor.apply_ui_theme")), and present the view.
|
| 122 |
+
|
| 123 |
+
Keyword arguments are passed on to [`ui.View.present()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.View.present "ui.View.present"), except for title_bar_color and title_color, which are set automatically, based on the theme.
|
| 124 |
+
|
| 125 |
+
editor.annotate_line(_lineno_, _text=''_, _style='warning'_, _expanded=True_, _filename=None_, _scroll=False_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.annotate_line "Permalink to this definition")
|
| 126 |
+
|
| 127 |
+
Annotate a line of code in the editor with a label.
|
| 128 |
+
|
| 129 |
+
lineno should be the 1-based line number in the file.
|
| 130 |
+
|
| 131 |
+
style can be ‘success’, ‘warning’ or ‘error’.
|
| 132 |
+
|
| 133 |
+
If expanded is False, only an icon is shown; tapping on the icon shows the text of the annotation. Otherwise, the text is shown immediately.
|
| 134 |
+
|
| 135 |
+
If filename is None, the line is annotated in the file that is currently open in the editor.
|
| 136 |
+
|
| 137 |
+
Invalid file names and line numbers are silently ignored.
|
| 138 |
+
|
| 139 |
+
editor.clear_annotations(_filename=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.clear_annotations "Permalink to this definition")
|
| 140 |
+
|
| 141 |
+
Remove all annotations that were added via [`annotate_line()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/editor.html#editor.annotate_line "editor.annotate_line").
|
FAQ.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Pythonista FAQ[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/faq.html#id1 "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
Note
|
| 4 |
+
|
| 5 |
+
This FAQ is work-in-progress. If you find something missing or your question is not answered, please send an email to [pythonista@omz-software.com](mailto:pythonista%40omz-software.com).
|
| 6 |
+
|
| 7 |
+
**Which version of Python does Pythonista support?**
|
| 8 |
+
|
| 9 |
+
Pythonista currently supports [Python 3.10](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/whatsnew/3.10.html).
|
| 10 |
+
|
| 11 |
+
Up until version 3.4, Pythonista also included a Python 2.7 interpreter, but as official support for Python 2.x has ended in 2020, it has been removed in version 3.4 of Pythonista.
|
| 12 |
+
|
| 13 |
+
**Which modules from the standard library work on iOS?**
|
| 14 |
+
|
| 15 |
+
Most of the Python standard library “just works” in Pythonista, but there are some notable exceptions and limitations:
|
| 16 |
+
|
| 17 |
+
- The [`subprocess`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/subprocess.html#module-subprocess "subprocess: Subprocess management.") and [`multiprocessing`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/multiprocessing.html#module-multiprocessing "multiprocessing: Process-based parallelism.")modules are present, but actually launching subprocesses will result in a [`PermissionError`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/exceptions.html#PermissionError "PermissionError"), due to the sandboxing restrictions on iOS. All scripts in Pythonista are running in the same process as the app itself.
|
| 18 |
+
|
| 19 |
+
- The [`readline`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/readline.html#module-readline "readline: GNU readline support for Python. (Unix)") and `curses` modules are not available, as Pythonista does not include a full terminal emulation.
|
| 20 |
+
|
| 21 |
+
- `Tkinter` is not supported. For building GUIs on iOS (in Pythonista), you can alternatively use the [`ui`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#module-ui "ui: Native GUI for iOS") module. Another (cross-platform) alternative would be to build a web-based GUI using e.g. [`bottle`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html#module-bottle "bottle")or [`flask`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html#module-flask "flask").
|
| 22 |
+
|
| 23 |
+
- The [`turtle`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/turtle.html#module-turtle "turtle: An educational framework for simple graphics applications") module is available as a custom port, but it doesn’t have full feature parity with other platforms. For most (learning) purposes, it should be sufficient though.
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
**Does Pythonista include module X?**
|
| 27 |
+
|
| 28 |
+
Please see the [list of Third-Party Modules](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html) that are bundled with Pythonista.
|
| 29 |
+
|
| 30 |
+
**Can I install additional modules?**
|
| 31 |
+
|
| 32 |
+
If the module is “pure Python” (i.e. no compiled C/C++ code), and doesn’t depend on any other modules that aren’t available in Pythonista, it’s possible to add additional modules by simply copying the module’s files to either your script’s containing folder, or to the special “site-packages” folder that you can view by selecting “Python Modules” in the file browser.
|
| 33 |
+
|
| 34 |
+
**Can I run scripts in the background?**
|
| 35 |
+
|
| 36 |
+
When you run a script in Pythonista, it continues running for a certain amount of time when you put the app in the background, but the script’s execution may be suspended after the app has been in the background for about 30 seconds (the exact time may vary).
|
| 37 |
+
|
| 38 |
+
This should be enough to e.g. load a request in Safari from a web server running in Pythonista, but if you need the script to be running for longer periods of time, the app needs to be in the foreground (e.g. in split view on an iPad).
|
| 39 |
+
|
| 40 |
+
**How can I pass arguments (sys.argv) to a script?**
|
| 41 |
+
|
| 42 |
+
Tap and hold the run (▷) button.
|
| 43 |
+
|
| 44 |
+
**Can I run scripts at specific times or triggered by other events?**
|
| 45 |
+
|
| 46 |
+
On iOS 14 and later, you can add “personal automations” in the Shortcuts app to automate running scripts (or other shortcuts) when various events happen (time of day, location, specific app launched, etc.). By using a “Run Pythonista Script” action in the automated shortcut, you can run it in response to these events. Please note that scripts that run in shortcuts have certain limitations, e.g. they can’t be interactive, and the amount of memory is quite limited. See the [`shortcuts`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#module-shortcuts "shortcuts: Shortcuts Automation and URL Scheme Utilities") module documentation for more information.
|
| 47 |
+
|
| 48 |
+
For more details on setting up personal automation, please see [Personal automation (Shortcuts User Guide)](https://support.apple.com/en-gb/guide/shortcuts/apd690170742/ios).
|
| 49 |
+
|
| 50 |
+
**How can I launch other apps from a script?**
|
| 51 |
+
|
| 52 |
+
You can use the [`webbrowser`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for web browsers.") module with custom URL schemes to launch other apps. Many system and third-party apps can be opened (and automated) with custom URL schemes.
|
| 53 |
+
|
| 54 |
+
Please note that opening URLs is not always possible when the script is running in an app extension (e.g. in the Shortcuts app).
|
| 55 |
+
|
| 56 |
+
**How can I launch Pythonista from other apps?**
|
| 57 |
+
|
| 58 |
+
You can use the [Pythonista URL Scheme](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/urlscheme.html)`pythonista3://` to launch Pythonista from other apps and to automate certain actions, like opening or running a script.
|
| 59 |
+
|
| 60 |
+
**How can I get files into Pythonista?**
|
| 61 |
+
|
| 62 |
+
You can use iCloud and the Files app to get files from other devices into Pythonista.
|
| 63 |
+
|
| 64 |
+
You can also import files from the system file picker by creating a new file (“+” button in the file browser), and then selecting “Import…”.
|
| 65 |
+
|
| 66 |
+
Another option is to use the share sheet extension. When sharing a file from any app that uses the standard share sheet, you can select the “Run Pythonista Script” action (once enabled), and then select “Import File”.
|
| 67 |
+
|
| 68 |
+
**Why do Pythonista’s local files not show up in the Files app?**
|
| 69 |
+
|
| 70 |
+
Pythonista’s local files are stored in a special folder that is shared between the main app and the app extensions (share sheet, shortcuts, keyboard…). This allows scripts running in either of these environments to share data easily.
|
| 71 |
+
|
| 72 |
+
Unfortunately, it is not easily possible to show this folder in the Files app, as the standard integration assumes that the app’s documents are in a folder that would only be accessible by the main app. It would be possible to work around this by building a file provider extension (essentially a Files app plugin), but so far, the effort required hasn’t seemed worth it.
|
| 73 |
+
|
| 74 |
+
You can still use the Files app with Pythonista’s iCloud documents, however.
|
| 75 |
+
|
| 76 |
+
**Can I use the camera in Pythonista?**
|
| 77 |
+
|
| 78 |
+
You can use the [`photos.capture_image()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/photos.html#photos.capture_image "photos.capture_image")function to show a camera interface and use the resulting image in your script.
|
| 79 |
+
|
| 80 |
+
Low-level access to the camera hardware (e.g. taking a picture without user interaction) is currently not supported, though you may be able to achieve this by using the [`objc_util`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") module for accessing Objective-C APIs directly.
|
| 81 |
+
|
| 82 |
+
**Does Pythonista support VoiceOver?**
|
| 83 |
+
|
| 84 |
+
Yes, Pythonista should be fully usable with VoiceOver, though there are some limitations when working with non-textual content (e.g. the UI editor, animations, etc.), and not all sample scripts are written with VoiceOver in mind. If you are using VoiceOver, and would like to suggest improvements or report issues, please send an email to [pythonista@omz-software.com](mailto:pythonista%40omz-software.com).
|
Location.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`location`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#module-location "location: Provides geo-location services on iOS") — Geo-Location Services on iOS[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#module-location "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`location`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#module-location "location: Provides geo-location services on iOS") module allows you to access geo-location data (e.g. GPS) on iOS. Additionally, you can use the [`location`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#module-location "location: Provides geo-location services on iOS") module to convert addresses to coordinates and vice-versa (geocoding and reverse-geocoding).
|
| 4 |
+
|
| 5 |
+
Note
|
| 6 |
+
|
| 7 |
+
The first time this module is used, a system-provided permission alert will be shown. Until you have given the app permission to access your location, most functions won’t return meaningful results.
|
| 8 |
+
|
| 9 |
+
Functions in the [`location`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#module-location "location: Provides geo-location services on iOS") module:
|
| 10 |
+
|
| 11 |
+
location.get_location()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.get_location "Permalink to this definition")
|
| 12 |
+
|
| 13 |
+
Return the most recently obtained location data. The return value is a dictionary containing various numbers that describe the current location (most importantly, ‘longitude’, ‘latitude’ and ‘timestamp’). This dictionary can be used as a parameter for the [`reverse_geocode()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.reverse_geocode "location.reverse_geocode") function. If no location data has been obtained yet (or you haven’t authorized the app), the return value may be None.
|
| 14 |
+
|
| 15 |
+
location.start_updates()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.start_updates "Permalink to this definition")
|
| 16 |
+
|
| 17 |
+
Start updating location data. This should be called before using [`get_location()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.get_location "location.get_location"). To save energy, it is recommended to call [`stop_updates()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.stop_updates "location.stop_updates") when you no longer need location data.
|
| 18 |
+
|
| 19 |
+
location.stop_updates()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.stop_updates "Permalink to this definition")
|
| 20 |
+
|
| 21 |
+
Stop updating location data.
|
| 22 |
+
|
| 23 |
+
location.geocode(_address_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.geocode "Permalink to this definition")
|
| 24 |
+
|
| 25 |
+
Try to convert an address dictionary to geo-coordinates. The return value is a list of possible coordinates (can be empty if no results are found). Each entry in the list is a dictionary with ‘longitude’ and ‘latitude’ keys.
|
| 26 |
+
|
| 27 |
+
Example:
|
| 28 |
+
|
| 29 |
+
import location
|
| 30 |
+
address_dict = {'Street': 'Infinite Loop', 'City': 'Cupertino', 'Country': 'USA'}
|
| 31 |
+
results = location.geocode(address_dict)
|
| 32 |
+
print results
|
| 33 |
+
|
| 34 |
+
location.render_map_snapshot(_lat_, _lng_, _width=1000_, _height=1000_, _map_type='standard'_, _show_poi=True_, _img_width=240_, _img_height=240_, _img_scale=0_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.render_map_snapshot "Permalink to this definition")
|
| 35 |
+
|
| 36 |
+
Render/download a snapshot image of the given map region (using the Apple Maps framework).
|
| 37 |
+
|
| 38 |
+
The lat and lng parameters determine the latitude and longitude of the map’s center. width and height (in meters) indirectly set the map’s scale factor. map_type can be `'standard'`, `'satellite'` or `'hybrid'`.
|
| 39 |
+
|
| 40 |
+
The return value is a [`ui.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.Image "ui.Image") with the given size (img_width/img_height) and scale (0 by default, i.e. the current device’s screen scale).
|
| 41 |
+
|
| 42 |
+
Example:
|
| 43 |
+
|
| 44 |
+
import location
|
| 45 |
+
img = location.render_map_snapshot(48.8582, 2.2945, map_type='satellite', img_width=512, img_height=512)
|
| 46 |
+
img.show()
|
| 47 |
+
|
| 48 |
+
location.reverse_geocode(_location_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.reverse_geocode "Permalink to this definition")
|
| 49 |
+
|
| 50 |
+
Try to convert a location (longitude/latitude) to a human-readable address. The locationparameter should be a dictionary containing values for ‘longitude’ and ‘latitude’. The return value is a list of possible address dictionaries (usually just one).
|
| 51 |
+
|
| 52 |
+
Example:
|
| 53 |
+
|
| 54 |
+
import location
|
| 55 |
+
coordinates = {'latitude': 37.331684, 'longitude': -122.030758}
|
| 56 |
+
results = location.reverse_geocode(coordinates)
|
| 57 |
+
print results
|
| 58 |
+
|
| 59 |
+
location.is_authorized()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/location.html#location.is_authorized "Permalink to this definition")
|
| 60 |
+
|
| 61 |
+
Returns True if access to location data is currently allowed, False otherwise (e.g. if the permission dialog hasn’t been shown yet or if access is denied due to parental controls).
|
Motion.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`motion`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#module-motion "motion: Provides motion sensor data on iOS") — Motion Sensor Data on iOS[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#module-motion "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`motion`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#module-motion "motion: Provides motion sensor data on iOS") module allows you to access your iOS device’s motion sensor data (accelerometer, gyroscope, magnetometer).
|
| 4 |
+
|
| 5 |
+
Functions in the [`motion`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#module-motion "motion: Provides motion sensor data on iOS") module:
|
| 6 |
+
|
| 7 |
+
motion.start_updates()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.start_updates "Permalink to this definition")
|
| 8 |
+
|
| 9 |
+
Start monitoring the device’s motion sensors. You should balance this with a [`stop_updates()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.stop_updates "motion.stop_updates") call to improve battery life. All the get… functions require that you call [`start_updates()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.start_updates "motion.start_updates") first, otherwise, no meaningful data will be returned.
|
| 10 |
+
|
| 11 |
+
motion.stop_updates()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.stop_updates "Permalink to this definition")
|
| 12 |
+
|
| 13 |
+
Stop monitoring the device’s motion sensors.
|
| 14 |
+
|
| 15 |
+
motion.get_gravity()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.get_gravity "Permalink to this definition")
|
| 16 |
+
|
| 17 |
+
Return the gravity vector (x, y, z).
|
| 18 |
+
|
| 19 |
+
motion.get_user_acceleration()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.get_user_acceleration "Permalink to this definition")
|
| 20 |
+
|
| 21 |
+
Return the acceleration the user is giving to the device. The total acceleration is equal to the gravity vector returned from [`get_gravity()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.get_gravity "motion.get_gravity") plus the user acceleration.
|
| 22 |
+
|
| 23 |
+
motion.get_attitude()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.get_attitude "Permalink to this definition")
|
| 24 |
+
|
| 25 |
+
Return the attitude of the device (roll, pitch, yaw).
|
| 26 |
+
|
| 27 |
+
motion.get_magnetic_field()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/motion.html#motion.get_magnetic_field "Permalink to this definition")
|
| 28 |
+
|
| 29 |
+
Return the magnetic field vector with respect to the device (x, y, z, accuracy).
|
Notifications.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`notification`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS") — Notifications on iOS[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#module-notification "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`notification`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS") module allows you to schedule notification messages that are shown in the iOS Notification Center. Scheduled notifications are delivered even when your script (or even the entire app) is no longer running.
|
| 4 |
+
|
| 5 |
+
It is also possible to attach a URL to a notification. The URL gets launched when the notification is activated (i.e. tapped in Notification Center or on the lock screen). Notifications can also contain multiple buttons that launch different URLs.
|
| 6 |
+
|
| 7 |
+
Typically, a notification is scheduled for a certain date/time in the future, but you can also schedule location-based notifications that get triggered when you enter or leave a specified geographic location (e.g. home/work).
|
| 8 |
+
|
| 9 |
+
All notifications you can schedule with this module are _local_ notifications. Remote (push) notifications are not supported.
|
| 10 |
+
|
| 11 |
+
## Functions[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#functions "Permalink to this heading")
|
| 12 |
+
|
| 13 |
+
notification.schedule(_message=None_, _delay=0_, _sound_name=None_, _action_url=None_, _title=None_, _subtitle=None_, _attachments=None_, _trigger=None_, _actions=None_, _identifier=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.schedule "Permalink to this definition")
|
| 14 |
+
|
| 15 |
+
Schedule a notification with the given options.
|
| 16 |
+
|
| 17 |
+
The return value is a string that can be used as an identifier to e.g. cancel the notification later.
|
| 18 |
+
|
| 19 |
+
Parameters:
|
| 20 |
+
|
| 21 |
+
- message: The main text of the notification
|
| 22 |
+
|
| 23 |
+
- delay: The time when the notification gets delivered, in seconds from now
|
| 24 |
+
|
| 25 |
+
- sound_name: The name of the built-in sound effect or sound file name that should be played when the notification is delivered. You can pass None (the default) for silent notifications or ‘default’ for the default notification sound.
|
| 26 |
+
|
| 27 |
+
- action_url: The URL that gets launched when the notification is tapped
|
| 28 |
+
|
| 29 |
+
- title: The title of the notification that gets displayed above the message
|
| 30 |
+
|
| 31 |
+
- subtitle: The subtitle of the notification
|
| 32 |
+
|
| 33 |
+
- attachments: A list of files that should be attached to the notification (e.g. images) – note that these files are copied immediately, so you cannot make changes to any attachments afterwards.
|
| 34 |
+
|
| 35 |
+
- trigger: A dictionary for more complex triggers than the simple delayparameter allows (see below)
|
| 36 |
+
|
| 37 |
+
- actions: Definitions for custom action buttons that are attached to the notification. Each action can launch a different URL or script. Notification actions get shown either when you drag down a notification banner from the top of the screen, by 3D Touch (on supported devices), or by tapping and holding the notification (on devices that don’t support 3D Touch). See below for details on how to define custom actions.
|
| 38 |
+
|
| 39 |
+
- identifier: An optional string that gets used as the notification’s identifier. If a notification with the same identifier is already scheduled, it gets replaced by the new notification.
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
**Date and location triggers:**
|
| 43 |
+
|
| 44 |
+
If you need more complex notification triggers than the simple delay parameter, you can pass a dict as the trigger parameter. This trigger can contain various options that define either a calendar- or location-based notification trigger. Supported keys for calendar-based notifications are: `'repeats', 'year', 'quarter', 'month','day', 'weekday', 'weekday_ordinal','week_of_month', 'week_of_year','hour', 'minute', 'second'` – you don’t have to specify all of these keys, just use the date/time components you need for your use case. Repeating notifications cannot repeat more often than once per minute.
|
| 45 |
+
|
| 46 |
+
Supported keys for location-based notification triggers are: `'latitude'`, `'longitude'`, `'radius'` (meters, default=100), `'entry'`, `'exit'`, `'repeats'`. The `'entry'` (notify when reaching the location) and `'exit'` (notify when leaving the location) options should be `True` or `False`. By default, both are true. Location-based notifications require that the app is authorized to access your location (you’ll be prompted automatically, and you can change it in the Settings app under Privacy).
|
| 47 |
+
|
| 48 |
+
**Custom notification actions:**
|
| 49 |
+
|
| 50 |
+
The `actions` parameter allows you to pass a list of actions that are shown as buttons when the notification is activated (e.g. by 3D Touch from the lock screen on supported devices). `actions` should be a list of `dict`objects that may contain the following keys:
|
| 51 |
+
|
| 52 |
+
- `'title'` – The title of the button
|
| 53 |
+
|
| 54 |
+
- `'url'` or `'action_url'` – The URL that gets launched when the button is tapped. If this is a pythonista:// URL that runs a script, the script runs in the background, unless the `'foreground'`key is set to True.
|
| 55 |
+
|
| 56 |
+
- `'foreground'` – See `` `'action_url' ``
|
| 57 |
+
|
| 58 |
+
- `'destructive'` – Changes the button’s appearance to indicate a destructive action (the text color becomes red)
|
| 59 |
+
|
| 60 |
+
- `'text_input'` – When set to True, this action causes a text field to appear within the notification interface. To use the entered text, put a `{text_input}`placeholder somewhere in this action’s URL (set via `'url'` key). If you use a pythonista:// URL to launch a script with this action, you can use the entered text as the URL’s args parameter, and access it in the script via `sys.argv`. Example: `pythonista3://MyScript.py?action=run&args={text_input}`.
|
| 61 |
+
|
| 62 |
+
- `'text_input_button_title'` – Specifies the title of the “OK” button when `'text_input'` is True
|
| 63 |
+
|
| 64 |
+
- `'text_input_placeholder'` – Specifies the placeholder text when `'text_input'` is True
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
notification.cancel(_identifier_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.cancel "Permalink to this definition")
|
| 68 |
+
|
| 69 |
+
Cancel a notification that was previously scheduled.
|
| 70 |
+
|
| 71 |
+
The notification_id parameter is a string that was either retrieved via [`get_scheduled()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.get_scheduled "notification.get_scheduled") or returned from the [`schedule()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.schedule "notification.schedule") function.
|
| 72 |
+
|
| 73 |
+
notification.cancel_all()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.cancel_all "Permalink to this definition")
|
| 74 |
+
|
| 75 |
+
Cancel all previously scheduled notifications.
|
| 76 |
+
|
| 77 |
+
notification.get_scheduled()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.get_scheduled "Permalink to this definition")
|
| 78 |
+
|
| 79 |
+
Return a list of scheduled notification identifiers.
|
| 80 |
+
|
| 81 |
+
The entries in the list are UUID strings that can be used for the [`cancel()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.cancel "notification.cancel") function.
|
| 82 |
+
|
| 83 |
+
notification.remove_delivered(_identifier_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.remove_delivered "Permalink to this definition")
|
| 84 |
+
|
| 85 |
+
Remove a specific notification that was already delivered from Notification Center. Note: This is done automatically when the user activates a notification.
|
| 86 |
+
|
| 87 |
+
notification.remove_all_delivered()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/notification.html#notification.remove_all_delivered "Permalink to this definition")
|
| 88 |
+
|
| 89 |
+
Remove all notifications that were already delivered from Notification Center. Note: This only affects the notifications of this app.
|
ObjectiveC.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") — Utilities for bridging Objective-C APIs[](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "Permalink to this headline")
|
| 2 |
+
|
| 3 |
+
The [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") module provides a “bridge” for using Objective-C APIs from Python.
|
| 4 |
+
|
| 5 |
+
Based on [`ctypes`](http://omz-software.com/pythonista/docs/library/ctypes.html#module-ctypes "ctypes: A foreign function library for Python.") and the Objective-C runtime library, [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") allows you to “wrap” existing Objective-C classes in a way that automatically converts Python method calls to corresponding Objective-C messages. As a simple example, this Objective-C code:
|
| 6 |
+
|
| 7 |
+
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]
|
| 8 |
+
[pasteboard setString:@"Hello Objective-C"];
|
| 9 |
+
|
| 10 |
+
can be translated to the following Python code:
|
| 11 |
+
|
| 12 |
+
from objc_util import *
|
| 13 |
+
UIPasteboard = ObjCClass('UIPasteboard')
|
| 14 |
+
|
| 15 |
+
pasteboard = UIPasteboard.generalPasteboard()
|
| 16 |
+
pasteboard.setString_('Hello Objective-C')
|
| 17 |
+
|
| 18 |
+
You can see that calling Objective-C APIs from Python doesn’t require significantly more code than you would need if you were writing native Objective-C code.
|
| 19 |
+
|
| 20 |
+
Behind the scenes, [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") generates appropriate calls to `objc_msgSend()` etc. for translating the Python calls to Objective-C messages. Common Python types (e.g. strings in the example above, but also lists and dicts) are converted to their equivalent Foundation types automatically (`NSString`, `NSMutableArray`, `NSMutableDictionary` etc.) when calling a method.
|
| 21 |
+
|
| 22 |
+
The conversion from an Objective-C selector to a Python method name is pretty straight-forward. You basically just have to replace colons (‘:’) with underscores (‘_’). For example, the selector `doFoo:withBar:` becomes the method `doFoo_withBar_` (note the trailing underscore!).
|
| 23 |
+
|
| 24 |
+
In most cases, you can also use a slightly more “pythonic” syntax that uses keyword arguments as part of the ObjC selector name, e.g.:
|
| 25 |
+
|
| 26 |
+
# From: UIColor *color = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]
|
| 27 |
+
# ...to:
|
| 28 |
+
UIColor = ObjCClass('UIColor')
|
| 29 |
+
color = UIColor.colorWithRed(1.0, green=0.0, blue=0.0, alpha=1.0)
|
| 30 |
+
# or even:
|
| 31 |
+
color = UIColor.color(red=1.0, green=0.0, blue=0.0, alpha=1.0)
|
| 32 |
+
|
| 33 |
+
This (more natural) syntax should work in most common cases, but there may be situations in which a given combination of method name and keyword arguments cannot be translated unambiguously to an ObjC method call. In these cases, simply use the call variant described above (replace colons with underscores, and don’t use keyword arguments).
|
| 34 |
+
|
| 35 |
+
Note
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
As with [`ctypes`](http://omz-software.com/pythonista/docs/library/ctypes.html#module-ctypes "ctypes: A foreign function library for Python."), there are lots of ways to crash Python using this module. When you call Objective-C methods, you have to be very careful to provide the correct parameter types.
|
| 40 |
+
|
| 41 |
+
## Example 1 – Setting the screen brightness[](http://omz-software.com/pythonista/docs/ios/objc_util.html#example-1-setting-the-screen-brightness "Permalink to this headline")
|
| 42 |
+
|
| 43 |
+
This simple example sets the screen brightness of your device:
|
| 44 |
+
|
| 45 |
+
from objc_util import *
|
| 46 |
+
|
| 47 |
+
# 'Import' an Objective-C class (generate a proxy for the class):
|
| 48 |
+
UIScreen = ObjCClass('UIScreen')
|
| 49 |
+
|
| 50 |
+
# Call a class method, this is equivalent to `[UIScreen mainScreen]` in Objective-C:
|
| 51 |
+
screen = UIScreen.mainScreen()
|
| 52 |
+
|
| 53 |
+
# `screen` is now an ObjCInstance that wraps an Objective-C object, and forwards messages to it.
|
| 54 |
+
|
| 55 |
+
# The following call is equivalent to `[screen setBrightness:0.6]`:
|
| 56 |
+
screen.setBrightness(0.6)
|
| 57 |
+
|
| 58 |
+
## Example 2 – Accessing the current song in Music/iPod app[](http://omz-software.com/pythonista/docs/ios/objc_util.html#example-2-accessing-the-current-song-in-music-ipod-app "Permalink to this headline")
|
| 59 |
+
|
| 60 |
+
This code snippet prints the currently-playing song in the console (note that this only works for the built-in Music app, not for third-party audio players):
|
| 61 |
+
|
| 62 |
+
from objc_util import *
|
| 63 |
+
|
| 64 |
+
MPMusicPlayerController = ObjCClass('MPMusicPlayerController')
|
| 65 |
+
player = MPMusicPlayerController.systemMusicPlayer()
|
| 66 |
+
now_playing = player.nowPlayingItem()
|
| 67 |
+
if now_playing:
|
| 68 |
+
artist = now_playing.valueForProperty_('artist')
|
| 69 |
+
title = now_playing.valueForProperty_('title')
|
| 70 |
+
print('Now playing: %s -- %s' % (artist, title))
|
| 71 |
+
else:
|
| 72 |
+
print('No music playing')
|
| 73 |
+
|
| 74 |
+
### Creating New Objective-C Classes[](http://omz-software.com/pythonista/docs/ios/objc_util.html#creating-new-objective-c-classes "Permalink to this headline")
|
| 75 |
+
|
| 76 |
+
For more advanced uses of Objective-C APIs, you sometimes need to create your own Objective-C classes at runtime. The main two scenarios when you’d want to do this are:
|
| 77 |
+
|
| 78 |
+
- Implementing the commonly-used delegate pattern, i.e. providing a callback interface for a built-in Objective-C class.
|
| 79 |
+
- Subclassing Objective-C classes that are intended to be subclassed for customization. One example would be subclassing `UIView` in order to override `-drawRect:`.
|
| 80 |
+
|
| 81 |
+
To accomplish this, the [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") module provides the [`create_objc_class()`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.create_objc_class "objc_util.create_objc_class") function, which uses the Objective-C runtime to allocate and register a new class, and then wraps the class in an [`ObjCClass`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCClass "objc_util.ObjCClass") object that you can use just like a built-in class in the examples above.
|
| 82 |
+
|
| 83 |
+
To create an Objective-C class using [`create_objc_class()`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.create_objc_class "objc_util.create_objc_class"), you need the following things:
|
| 84 |
+
|
| 85 |
+
**name** – the name of the class to create, as a string. This should only consist of letters, numbers, and underscore characters. It may not begin with a number. Please note that the name of the class that actually gets created may be different from this because a class with the name may already exist. If that’s the case, a new name is chosen automatically, if the debug parameter is True (the default). If debug is False, the existing class will be returned, and all other parameters are ignored.
|
| 86 |
+
|
| 87 |
+
**superclass** – An ObjCClass object that determines the Objective-C class from which the new class inherits.
|
| 88 |
+
|
| 89 |
+
**methods** – A list of functions that are used to create the instance methods of the new class. To create an Objective-C method from a Python function, the Objective-C runtime needs additional metadata: the selector name, the type of the return value, and types for any arguments. As much as possible, [`create_objc_class()`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.create_objc_class "objc_util.create_objc_class") will try to derive this metadata automatically, please see the the discussion under [`create_objc_class()`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.create_objc_class "objc_util.create_objc_class") for details. Every Objective-C method needs at least two parameters that are hidden when calling it from Objective-C: `_self` is a pointer to the Objective-C object itself (note that this is not wrapped in an [`ObjCInstance`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "objc_util.ObjCInstance") object, so you have to do this manually if needed), and `_cmd`, a pointer to the selector (usually not needed). The names of these two “hidden” parameters don’t matter. Note that parameters are passed to Objective-C methods as “raw” pointers, not ObjCInstance objects, but you can convert object parameters easily by wrapping them manually, e.g. `obj = ObjCInstance(_self)`.
|
| 90 |
+
|
| 91 |
+
**classmethods** (optional) – same as methods, but for class methods (rarely needed).
|
| 92 |
+
|
| 93 |
+
**protocols** (optional) – a list of strings that is used for hinting type encodings for methods. If you implement a delegate (or other) protocol, you should include the protocol’s name (e.g. `'UITableViewDataSource'`) to make sure that the return and argument types for any methods can be inferred correctly.
|
| 94 |
+
|
| 95 |
+
Here is an example of creating a simple class that acts as the delegate for an `MFMailComposeViewController` (which is used to show the standard iOS Mail sheet). A delegate is required to use this class because it is otherwise impossible to get rid of the Mail sheet (the delegate is notified when the sheet has finished, and it’s responsible for dismissing it).:
|
| 96 |
+
|
| 97 |
+
# - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
|
| 98 |
+
def mailComposeController_didFinishWithResult_error_(_self, _cmd, controller, result, error):
|
| 99 |
+
print('Mail composer finished')
|
| 100 |
+
# Wrap the controller parameter in an `ObjCInstance`, so we can send messages:
|
| 101 |
+
mail_vc = ObjCInstance(controller)
|
| 102 |
+
# Set delegate to nil, and release its memory:
|
| 103 |
+
mail_vc.setMailComposeDelegate_(None)
|
| 104 |
+
ObjCInstance(_self).release()
|
| 105 |
+
# Dismiss the sheet:
|
| 106 |
+
mail_vc.dismissViewControllerAnimated_completion_(True, None)
|
| 107 |
+
|
| 108 |
+
methods = [mailComposeController_didFinishWithResult_error_]
|
| 109 |
+
protocols = ['MFMailComposeViewControllerDelegate']
|
| 110 |
+
MyMailComposeDelegate = create_objc_class('MyMailComposeDelegate', NSObject, methods=methods, protocols=protocols)
|
| 111 |
+
|
| 112 |
+
@on_main_thread
|
| 113 |
+
def show_mail_sheet():
|
| 114 |
+
MFMailComposeViewController = ObjCClass('MFMailComposeViewController')
|
| 115 |
+
mail_composer = MFMailComposeViewController.alloc().init().autorelease()
|
| 116 |
+
# Use our new delegate class:
|
| 117 |
+
delegate = MyMailComposeDelegate.alloc().init()
|
| 118 |
+
mail_composer.setMailComposeDelegate_(delegate)
|
| 119 |
+
# Present the mail sheet:
|
| 120 |
+
root_vc = UIApplication.sharedApplication().keyWindow().rootViewController()
|
| 121 |
+
root_vc.presentViewController_animated_completion_(mail_composer, True, None)
|
| 122 |
+
|
| 123 |
+
if __name__ == '__main__':
|
| 124 |
+
show_mail_sheet()
|
| 125 |
+
|
| 126 |
+
## API Reference[](http://omz-software.com/pythonista/docs/ios/objc_util.html#api-reference "Permalink to this headline")
|
| 127 |
+
|
| 128 |
+
### Classes[](http://omz-software.com/pythonista/docs/ios/objc_util.html#classes "Permalink to this headline")
|
| 129 |
+
|
| 130 |
+
_class_ `objc_util.``ObjCClass`(_name_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCClass "Permalink to this definition")
|
| 131 |
+
|
| 132 |
+
Wrapper for an Objective-C class with the given name; acts as a proxy for calling Objective-C class methods.
|
| 133 |
+
|
| 134 |
+
Method calls are converted to Objective-C messages on-the-fly – this is done by replacing underscores in the method name with colons in the selector name, and using the selector and arguments for a call to the low-level `objc_msgSend()` function in the Objective-C runtime.
|
| 135 |
+
|
| 136 |
+
For example, calling `NSDictionary.dictionaryWithObject_forKey_(obj, key)` (Python) is effectively translated to `[NSDictionary dictionaryWithObject:obj forKey:key]` (Objective-C). If a method call returns an Objective-C object, it is wrapped in an ObjCInstance, so calls can be chained ([`ObjCInstance`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "objc_util.ObjCInstance") uses an equivalent proxy mechanism).
|
| 137 |
+
|
| 138 |
+
Some commonly used classes are module members (see list at the bottom), for others, you simply “import” it using the class name, e.g.:
|
| 139 |
+
|
| 140 |
+
UIPasteboard = ObjCClass('UIPasteboard')
|
| 141 |
+
|
| 142 |
+
_class_ `objc_util.``ObjCInstance`(_ptr_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "Permalink to this definition")
|
| 143 |
+
|
| 144 |
+
Wrapper for a pointer to an Objective-C object; acts as a proxy for sending messages to the object.
|
| 145 |
+
|
| 146 |
+
Method calls are converted to Objective-C messages on-the-fly – this is done by replacing underscores in the method name with colons in the selector name, and using the selector and arguments for a call to the `objc_msgSend()` function in the Objective-C runtime. For example, calling `obj.setFoo_withBar_(foo, bar)` (Python) is effectively translated to `[obj setFoo:foo withBar:bar]` (Objective-C). If a method call returns an Objective-C object, it is also wrapped in an ObjCInstance, so calls can be chained.
|
| 147 |
+
|
| 148 |
+
[`ObjCInstance`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "objc_util.ObjCInstance") implements `__str__` and `__repr__` by calling the `NSObject` method `description`.
|
| 149 |
+
|
| 150 |
+
If an instance wraps a common Objective-C collection type (`NSArray`, `NSDictionary`, `NSSet`), it behaves similar to a native Python collection in many ways. It can be iterated (`for .. in`), you can access items by key/index, using square bracket notation (`some_dict['key']`, `some_array[3]`...), etc.
|
| 151 |
+
|
| 152 |
+
_class_ `objc_util.``ObjCBlock`(_func_, _restype=None_, _argtypes=None_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCBlock "Permalink to this definition")
|
| 153 |
+
|
| 154 |
+
Warning
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
Block support is experimental. If you have the alternative of using an API that doesn’t require blocks, it is strongly recommended that you do so.
|
| 159 |
+
|
| 160 |
+
[`ObjCBlock`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCBlock "objc_util.ObjCBlock") can be used to pass blocks (“closures”) to Objective-C methods. As mentioned above, this is experimental, and you should usually prefer to use APIs that don’t require blocks, if possible. Some APIs absolutely require the use of blocks though. For blocks that don’t have a return value and no arguments, you can pass a Python function, and it’ll be converted to an [`ObjCBlock`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCBlock "objc_util.ObjCBlock") automatically. In other cases, you need to specify the return and argumet types when creating the block explicitly.
|
| 161 |
+
|
| 162 |
+
Example of a block with arguments (used to sort an NSMutableArray with a custom comparison function):
|
| 163 |
+
|
| 164 |
+
from objc_util import *
|
| 165 |
+
cheeses = ns(['Camembert', 'Feta', 'Gorgonzola'])
|
| 166 |
+
print(cheeses)
|
| 167 |
+
|
| 168 |
+
def compare(_cmd, obj1_ptr, obj2_ptr):
|
| 169 |
+
obj1 = ObjCInstance(obj1_ptr)
|
| 170 |
+
obj2 = ObjCInstance(obj2_ptr)
|
| 171 |
+
# Sort the strings by length:
|
| 172 |
+
return cmp(obj1.length(), obj2.length())
|
| 173 |
+
|
| 174 |
+
# Note: The first (hidden) argument `_cmd` is the block itself, so there are three arguments instead of two.
|
| 175 |
+
compare_block = ObjCBlock(compare, restype=NSInteger, argtypes=[c_void_p, c_void_p, c_void_p])
|
| 176 |
+
|
| 177 |
+
sorted_cheeses = cheeses.sortedArrayUsingComparator_(compare_block)
|
| 178 |
+
print(sorted_cheeses)
|
| 179 |
+
|
| 180 |
+
### Functions[](http://omz-software.com/pythonista/docs/ios/objc_util.html#functions "Permalink to this headline")
|
| 181 |
+
|
| 182 |
+
`objc_util.``autoreleasepool`()[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.autoreleasepool "Permalink to this definition")
|
| 183 |
+
|
| 184 |
+
A context manager that acts as a wrapper for `NSAutoreleasePool` (similar to `@autoreleasepool{...}` in Objective-C).
|
| 185 |
+
|
| 186 |
+
Usage::
|
| 187 |
+
|
| 188 |
+
with objc_util.autoreleasepool():
|
| 189 |
+
|
| 190 |
+
# do stuff...
|
| 191 |
+
|
| 192 |
+
`objc_util.``create_objc_class`(_name_, _superclass=NSObject_, _methods=[]_, _classmethods=[]_, _protocols=[]_, _debug=True_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.create_objc_class "Permalink to this definition")
|
| 193 |
+
|
| 194 |
+
Create and return a new [`ObjCClass`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCClass "objc_util.ObjCClass") that implements the given methods.
|
| 195 |
+
|
| 196 |
+
- The selector name is derived from the name of the function. The function name can optionally be prefixed by the Objective-C class name. For example, these two functions result in an equivalent selector name:
|
| 197 |
+
|
| 198 |
+
def MyClass_doSomething_withObject_(_self, _cmd, foo, bar):
|
| 199 |
+
pass
|
| 200 |
+
|
| 201 |
+
def doSomething_withObject_(_self, _cmd, foo, bar):
|
| 202 |
+
pass
|
| 203 |
+
|
| 204 |
+
# The selector name for both of these functions would be 'doSomething:withObject:'.
|
| 205 |
+
|
| 206 |
+
- To determine the return type and argument types, [`create_objc_class()`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.create_objc_class "objc_util.create_objc_class") checks if the superclass has a method with the same selector. If that’s the case, the types are inherited from the superclass’s method. This strategy works for overriding a method in a subclass. If this fails, the protocols parameter is used. protocols is a list of strings, for example `['UIGestureRecognizerDelegate','UITableViewDataSource']` – these protocols are checked for methods with the same selector. This strategy works for example for implementing delegate protocols. Together, these strategies should determine the type information in most common cases. If they are not suitable in your case, you can set `restype`, `argtypes`, and `encoding` attributes on the function objects you pass.
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
Note
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
If you want to use an _existing_ Objective-C class, simply obtain a reference to it using `ObjCClass(name)`. This function is for creating _new_ classes, e.g. to subclass an Objective-C class or implement a delegate protocol.
|
| 214 |
+
|
| 215 |
+
`objc_util.``load_framework`(_name_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.load_framework "Permalink to this definition")
|
| 216 |
+
|
| 217 |
+
Load the system framework with the given name (e.g. `'SceneKit'`).
|
| 218 |
+
|
| 219 |
+
This is equivalent to the Objective-C code `[[NSBundle bundleWithPath:@"/System/Frameworks/<name>.framework"] load]`.
|
| 220 |
+
|
| 221 |
+
`objc_util.``ns`(_obj_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ns "Permalink to this definition")
|
| 222 |
+
|
| 223 |
+
Convert common Python objects to their ObjC equivalents, i.e. `str` => `NSString`, `int`/`float` => `NSNumber`, `list` => `NSMutableArray`, `dict` => `NSMutableDictionary`, `bytearray` => `NSData`, `set` => `NSMutableSet`. Nested structures (`list`/`dict`/`set`) are supported. If an object is already an instance of [`ObjCInstance`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "objc_util.ObjCInstance"), it is left untouched.
|
| 224 |
+
|
| 225 |
+
If an Objective-C method expects an object as a parameter, the Python object parameter is automatically converted using this function, so you can e.g. pass Python strings to Objective-C methods that expect an `NSString`.
|
| 226 |
+
|
| 227 |
+
`objc_util.``nsurl`(_url_or_path_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.nsurl "Permalink to this definition")
|
| 228 |
+
|
| 229 |
+
Convert a Python string to an `NSURL` object (wrapped in an [`ObjCInstance`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "objc_util.ObjCInstance")).
|
| 230 |
+
|
| 231 |
+
If the string contains a colon (‘:’), it is treated as a full URL and converted to an `NSURL` using `+URLWithString:`. Otherwise, a file URL is constructed using `+fileURLWithPath:`.
|
| 232 |
+
|
| 233 |
+
`objc_util.``nsdata_to_bytes`(_data_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.nsdata_to_bytes "Permalink to this definition")
|
| 234 |
+
|
| 235 |
+
Convert an `NSData` object (wrapped in an [`ObjCInstance`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "objc_util.ObjCInstance")) to a Python byte string.
|
| 236 |
+
|
| 237 |
+
`objc_util.``uiimage_to_png`(_img_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.uiimage_to_png "Permalink to this definition")
|
| 238 |
+
|
| 239 |
+
Convert a `UIImage` object (wrapped in an [`ObjCInstance`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.ObjCInstance "objc_util.ObjCInstance")) to a Python byte string that contains PNG data.
|
| 240 |
+
|
| 241 |
+
`objc_util.``on_main_thread`(_func_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.on_main_thread "Permalink to this definition")
|
| 242 |
+
|
| 243 |
+
Decorator function for calling another function on the UIKit main thread. A lot of Objective-C APIs (particularly in UIKit) require being called from the main thread. This is typically used to decorate another function, but it can also be used for dispatching a function call to the main thread ad-hoc, e.g. `on_main_thread(my_function)(param1, param2)`
|
| 244 |
+
|
| 245 |
+
Decorator example:
|
| 246 |
+
|
| 247 |
+
from objc_util import *
|
| 248 |
+
|
| 249 |
+
@on_main_thread
|
| 250 |
+
def post_notification(name):
|
| 251 |
+
NSNotificationCenter = ObjCClass('NSNotificationCenter')
|
| 252 |
+
center = NSNotificationCenter.defaultCenter()
|
| 253 |
+
center.postNotificationName_object_(name, None)
|
| 254 |
+
|
| 255 |
+
# Every call of post_notification(...) will automagically happen on the main thread.
|
| 256 |
+
|
| 257 |
+
`objc_util.``sel`(_name_)[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.sel "Permalink to this definition")
|
| 258 |
+
|
| 259 |
+
Convenience wrapper for `sel_registerName` (converts a Python string to an Objective-C selector).
|
| 260 |
+
|
| 261 |
+
### Objective-C Classes/Structs[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objective-c-classes-structs "Permalink to this headline")
|
| 262 |
+
|
| 263 |
+
For convenience, a few commonly-used Objective-C classes and structs are made available as module-level objects, so they don’t have to be wrapped explicitly. These are:
|
| 264 |
+
|
| 265 |
+
_class_ `objc_util.``CGPoint`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.CGPoint "Permalink to this definition")
|
| 266 |
+
|
| 267 |
+
_class_ `objc_util.``CGSize`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.CGSize "Permalink to this definition")
|
| 268 |
+
|
| 269 |
+
_class_ `objc_util.``CGVector`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.CGVector "Permalink to this definition")
|
| 270 |
+
|
| 271 |
+
_class_ `objc_util.``CGRect`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.CGRect "Permalink to this definition")
|
| 272 |
+
|
| 273 |
+
_class_ `objc_util.``CGAffineTransform`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.CGAffineTransform "Permalink to this definition")
|
| 274 |
+
|
| 275 |
+
_class_ `objc_util.``UIEdgeInsets`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.UIEdgeInsets "Permalink to this definition")
|
| 276 |
+
|
| 277 |
+
_class_ `objc_util.``NSRange`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSRange "Permalink to this definition")
|
| 278 |
+
|
| 279 |
+
_class_ `objc_util.``NSDictionary`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSDictionary "Permalink to this definition")
|
| 280 |
+
|
| 281 |
+
_class_ `objc_util.``NSMutableDictionary`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSMutableDictionary "Permalink to this definition")
|
| 282 |
+
|
| 283 |
+
_class_ `objc_util.``NSArray`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSArray "Permalink to this definition")
|
| 284 |
+
|
| 285 |
+
_class_ `objc_util.``NSMutableArray`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSMutableArray "Permalink to this definition")
|
| 286 |
+
|
| 287 |
+
_class_ `objc_util.``NSSet`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSSet "Permalink to this definition")
|
| 288 |
+
|
| 289 |
+
_class_ `objc_util.``NSMutableSet`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSMutableSet "Permalink to this definition")
|
| 290 |
+
|
| 291 |
+
_class_ `objc_util.``NSString`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSString "Permalink to this definition")
|
| 292 |
+
|
| 293 |
+
_class_ `objc_util.``NSMutableString`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSMutableString "Permalink to this definition")
|
| 294 |
+
|
| 295 |
+
_class_ `objc_util.``NSData`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSData "Permalink to this definition")
|
| 296 |
+
|
| 297 |
+
_class_ `objc_util.``NSMutableData`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSMutableData "Permalink to this definition")
|
| 298 |
+
|
| 299 |
+
_class_ `objc_util.``NSNumber`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSNumber "Permalink to this definition")
|
| 300 |
+
|
| 301 |
+
_class_ `objc_util.``NSURL`[](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.NSURL "Permalink to this definition")
|
| 302 |
+
|
| 303 |
+
_class_ `objc_util.``NSEnumerator`
|
Scene.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Shortcuts.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`shortcuts`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#module-shortcuts "shortcuts: Shortcuts Automation and URL Scheme Utilities") — Shortcuts Automation and URL Scheme Utilities[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#module-shortcuts "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
## Introduction[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#introduction "Permalink to this heading")
|
| 4 |
+
|
| 5 |
+
The [`shortcuts`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#module-shortcuts "shortcuts: Shortcuts Automation and URL Scheme Utilities") module provides functions for integrating with the built-in [Shortcuts](https://support.apple.com/guide/shortcuts/welcome/ios) app (and Siri) on iOS 13 and later, plus some utilities for URL scheme automation on any version of iOS.
|
| 6 |
+
|
| 7 |
+
The [Shortcuts](https://support.apple.com/guide/shortcuts/welcome/ios) app lets you build _shortcuts_(previously known as “workflows”) out of one or more _actions_. Building shortcuts is very much like programming, though you typically don’t write any code, and a shortcut’s _actions_ do a lot more at once than a typical function call in a programming language like Python. While this leads to much quicker results, there is sometimes a compromise between ease of use and flexibility. Fortunately, third-party apps like Pythonista can extend the _Shortcuts_ app with their own sets of actions that you can use to automate a growing list of apps through the use of Shortcuts, and increasingly complex use cases are possible.
|
| 8 |
+
|
| 9 |
+
Pythonista provides a couple of Shortcuts actions that automatically become available in the Shortcuts app when Pythonista is installed.
|
| 10 |
+
|
| 11 |
+
## Pythonista Actions in Shortcuts[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#pythonista-actions-in-shortcuts "Permalink to this heading")
|
| 12 |
+
|
| 13 |
+
### Run Pythonista Script[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#run-pythonista-script "Permalink to this heading")
|
| 14 |
+
|
| 15 |
+
[](blob:capacitor://localhost/fcfe56ce-7070-4e74-b8d9-e4e8c11c39e5)
|
| 16 |
+
|
| 17 |
+
This is the action that you’ll probably use most with Pythonista. It allows you to run a Python script, either by launching the Pythonista app (and optionally returning to _Shortcuts_afterwards), or by running the script directly in the Shortcuts app, passing the results to the next action and/or presenting them within the Shortcuts UI.
|
| 18 |
+
|
| 19 |
+
By default, you can choose a script from your Pythonista library to run when the action executes. By using the **“Inline Script”** option, however, you can also type in a snippet of Python code directly in the Shortcuts app.
|
| 20 |
+
|
| 21 |
+
Both library and inline scripts can run in the main Pythonista app or directly in Shortcuts (depending on whether the **“Run in Pythonista”**option is on). There are a couple of differences between these two run modes, and you might want to use one or the other, depending on the script you’re running. In general, scripts running in Shortcuts have much more limited memory resources and cannot show a user interface, apart from presenting results after the script has run. On the plus side though, they don’t launch the Pythonista app at all, and they can pass their output directly to the next action in the shortcut, so you might often prefer this way of running scripts for shortcuts consisting of many actions.
|
| 22 |
+
|
| 23 |
+
When “Run in Pythonista” is on, an additional **“Auto-Return to Shortcuts”** option appears. When this is on, Pythonista will automatically return to the Shortcuts app when the script has finished running. You might want to disable it if your script handles returning to Shortcuts itself (e.g. by calling `shortcuts.open_shortcuts_app()` at some point).
|
| 24 |
+
|
| 25 |
+
The **“Show When Run”** option determines whether the action’s output will be shown in the Shortcuts app after the script has run. This only has an effect when “Run in Pythonista” is _off_. When you turn this off, the action will still pass output to the next action in the workflow, but no UI will be shown.
|
| 26 |
+
|
| 27 |
+
**Arguments and Input Files**
|
| 28 |
+
|
| 29 |
+
There are two ways of passing input from other shortcut actions to your script. Both **Arguments**and **Input Files** are added to `sys.argv`, just like command-line arguments. The difference is that _Arguments_ are converted to plain text (i.e. a string) and _Input Files_ are written to a temporary disk location and passed as an absolute file path.
|
| 30 |
+
|
| 31 |
+
**Output**
|
| 32 |
+
|
| 33 |
+
First off, only scripts that run within Shortcuts (“Run in Pythonista” _off_) will directly produce output that other actions in the shortcut can use. You can work around this by writing output to a file, and using an additional “Get Pythonista File” action.
|
| 34 |
+
|
| 35 |
+
By default, the action’s output will be anything that would normally be printed to the console, i.e. you can simply use `print()` calls to pass text to other actions in the shortcut. Of course, you’re not limited to working with text, so you can use various functions in this module to generate output of other data types, like [`set_output_image()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.set_output_image "shortcuts.set_output_image"), [`set_output_data()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.set_output_data "shortcuts.set_output_data"), and [`set_output_files()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.set_output_files "shortcuts.set_output_files").
|
| 36 |
+
|
| 37 |
+
If “Show When Run” in on, the action will also present a “result sheet” to the user after the script has run. By default, this also shows console output, but you can customize this completely, using HTML/CSS.
|
| 38 |
+
|
| 39 |
+
### Add File to Pythonista[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#add-file-to-pythonista "Permalink to this heading")
|
| 40 |
+
|
| 41 |
+
This action copies a file (produced by another action) to Pythonista’s script library, optionally overwriting an existing file with the same name.
|
| 42 |
+
|
| 43 |
+
### Get Pythonista File[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#get-pythonista-file "Permalink to this heading")
|
| 44 |
+
|
| 45 |
+
This action reads a file from Pythonista’s script library, and passes its contents to the next action. The file name can include folders (e.g. “MyFolder/MyScript.py”). To reference files in Pythonista’s iCloud folder, prefix the path with “icloud/”, e.g. “icloud/MyScript.py”.
|
| 46 |
+
|
| 47 |
+
### Run Script / Edit Script (deprecated)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#run-script-edit-script-deprecated "Permalink to this heading")
|
| 48 |
+
|
| 49 |
+
You might see these two actions for Pythonista in the Shortcuts app as well. While at the time of writing, they still work, it is not recommended that you use them for new shortcuts. These actions have been built into the Shortcuts app back from the days when it was called “Workflows” (and wasn’t part of Apple). Since it’s now possible for third-party apps like Pythonista to provide their own Shortcuts support, it is likely that these actions will disappear from the Shortcuts app at some point in the future.
|
| 50 |
+
|
| 51 |
+
## Functions[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#functions "Permalink to this heading")
|
| 52 |
+
|
| 53 |
+
shortcuts.is_running_shortcut()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.is_running_shortcut "Permalink to this definition")
|
| 54 |
+
|
| 55 |
+
Return True if the current script is running as a _background_ shortcut, False otherwise (when running in the main app, or a different kind of app extension).
|
| 56 |
+
|
| 57 |
+
shortcuts.open_shortcuts_app(_name=None_, _shortcut_input=''_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.open_shortcuts_app "Permalink to this definition")
|
| 58 |
+
|
| 59 |
+
Open the Apple Shortcuts app and optionally run a named shortcut. Equivalent to `shortcuts.open_url('shortcuts://run-shortcut?name=[name]&input=shortcut_input')`.
|
| 60 |
+
|
| 61 |
+
shortcuts.open_url(_url_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.open_url "Permalink to this definition")
|
| 62 |
+
|
| 63 |
+
Open a given URL using the system’s default app for the URL’s scheme. This is mostly equivalent to [`webbrowser.open()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/webbrowser.html#webbrowser.open "webbrowser.open"). Note that you cannot open URLs in a script that is running as a background shortcut.
|
| 64 |
+
|
| 65 |
+
shortcuts.set_output_data(_data_, _filename_, _uti=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.set_output_data "Permalink to this definition")
|
| 66 |
+
|
| 67 |
+
Set the output of the current shortcut action script. `data` should be a byte string, the data type is inferred from the `filename`argument, or given explicitly as a UTI.
|
| 68 |
+
|
| 69 |
+
shortcuts.set_output_image(_image_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.set_output_image "Permalink to this definition")
|
| 70 |
+
|
| 71 |
+
Set the output of the current shortcut action script as an image (either a path to an image file as a string, a [`PIL.Image.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/pillow/reference/Image.html#PIL.Image.Image "(in Pillow (PIL Fork) v9.0.0)"), or a [`ui.Image`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.Image "ui.Image") object).
|
| 72 |
+
|
| 73 |
+
shortcuts.set_output_files(_file_infos_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.set_output_files "Permalink to this definition")
|
| 74 |
+
|
| 75 |
+
Set the output of the current shortcut action script from a list of files.
|
| 76 |
+
|
| 77 |
+
`file_infos` should be [`list`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/stdtypes.html#list "list") of [`dict`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/stdtypes.html#dict "dict")objects with the following keys:
|
| 78 |
+
|
| 79 |
+
- `'path'` – An absolute path to an existing file.
|
| 80 |
+
|
| 81 |
+
- `'data'` – The contents of the file as a [`bytes`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/stdtypes.html#bytes "bytes") object (for in-memory files)
|
| 82 |
+
|
| 83 |
+
- `'filename'` – The file’s name (for in-memory files without a path)
|
| 84 |
+
|
| 85 |
+
- `'uti'` – The file’s [`Uniform Type Identifier <>`_](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#id2) (optional)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
shortcuts.set_result_html(_html_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.set_result_html "Permalink to this definition")
|
| 89 |
+
|
| 90 |
+
Set HTML-formatted text to be shown as the result when running a background shortcut script in Siri or the Shortcuts app. The given html is inserted in a template that contains the document structure and some default formatting, so it can just be a snippet of markup.
|
| 91 |
+
|
| 92 |
+
The result is only shown when the “Show When Run” option is activated in the Shortcuts app.
|
| 93 |
+
|
| 94 |
+
If you just want to show some text or image in the result view, you can also just use `print()` or [`ui.Image.show()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/ui.html#ui.Image.show "ui.Image.show") etc.
|
| 95 |
+
|
| 96 |
+
shortcuts.pythonista_url(_path=''_, _action='run'_, _args=None_, _argv=None_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#shortcuts.pythonista_url "Permalink to this definition")
|
| 97 |
+
|
| 98 |
+
Generates a `pythonista3://...` URL from a file name/path, an action, and optional arguments.
|
| 99 |
+
|
| 100 |
+
Possible values for action are:
|
| 101 |
+
|
| 102 |
+
- `'run'` – Opening the URL will run the script without further prompt.
|
| 103 |
+
|
| 104 |
+
- `'open'` – Opening the URL will open the script for editing.
|
| 105 |
+
|
| 106 |
+
- `'exec'` – The script will be embedded as source code in the URL, and opening the URL will show it in Pythonista. The user can then decide to run it (embedded scripts are not run automatically for security reasons).
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
The path should either be relative to the root “on this device” directory, or have an ‘iCloud/’ prefix, and be relative to the iCloud container directory of Pythonista.
|
| 110 |
+
|
| 111 |
+
args can be a string that contains arguments that are passed to the script as `sys.argv`. Alternatively, you can use the argv parameter to pass the arguments as a list.
|
Sound.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# [`sound`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#module-sound "sound: Sound effects and music playback") — Sound effects and music playback[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#module-sound "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
The [`sound`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#module-sound "sound: Sound effects and music playback") module contains functions for playing sound effects and audio files on iOS.
|
| 4 |
+
|
| 5 |
+
It also enables recording audio files from the microphone using the [`Recorder`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder "sound.Recorder") class.
|
| 6 |
+
|
| 7 |
+
Note
|
| 8 |
+
|
| 9 |
+
In order to use the [`Recorder`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder "sound.Recorder") class, you have to allow access to the microphone. A system-provided dialog is shown automatically when you use the [`Recorder.record()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.record "sound.Recorder.record") method for the first time. If you do not authorize access to the microphone then, you can also enable it in the Privacy section of the Settings app.
|
| 10 |
+
|
| 11 |
+
## Functions[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#functions "Permalink to this heading")
|
| 12 |
+
|
| 13 |
+
sound.play_effect(_name_[, _volume_, _pitch=1.0_, _pan=0.0_, _looping=False_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.play_effect "Permalink to this definition")
|
| 14 |
+
|
| 15 |
+
Play the sound effect with the given name. You can access a list of built-in sound effect names using the asset picker ([+] button in the toolbar), but name can also be a file path if you want to use your own sound effects.
|
| 16 |
+
|
| 17 |
+
Playback is asynchronous, i.e. the function returns before the sound has finished playing.
|
| 18 |
+
|
| 19 |
+
The return value is a [`sound.Effect`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect "sound.Effect") object that can be used to adjust playback settings later, or to stop the sound effect before it has finished playing.
|
| 20 |
+
|
| 21 |
+
If too many sound effects are already playing (the limit is usually about 32), None may be returned.
|
| 22 |
+
|
| 23 |
+
sound.stop_all_effects()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.stop_all_effects "Permalink to this definition")
|
| 24 |
+
|
| 25 |
+
Stop all sound effects that are currently playing (via [`play_effect()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.play_effect "sound.play_effect")).
|
| 26 |
+
|
| 27 |
+
sound.stop_effect(_effect_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.stop_effect "Permalink to this definition")
|
| 28 |
+
|
| 29 |
+
Stop playback of the given sound effect. effect should be a return value of [`play_effect()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.play_effect "sound.play_effect").
|
| 30 |
+
|
| 31 |
+
sound.set_volume(_vol_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.set_volume "Permalink to this definition")
|
| 32 |
+
|
| 33 |
+
Sets the default volume for all sound effects (between 0.0 and 1.0, the default is 0.5). This has no effect on sound effects that are already playing.
|
| 34 |
+
|
| 35 |
+
sound.set_honors_silent_switch(_flag_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.set_honors_silent_switch "Permalink to this definition")
|
| 36 |
+
|
| 37 |
+
Determines whether the silent (mute) switch is honored when playing sounds (True by default).
|
| 38 |
+
|
| 39 |
+
## Effect Class[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#effect-class "Permalink to this heading")
|
| 40 |
+
|
| 41 |
+
_class_ sound.Effect[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect "Permalink to this definition")
|
| 42 |
+
|
| 43 |
+
The [`Effect`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect "sound.Effect") class represents sound effects that are currently playing. You cannot create [`Effect`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect "sound.Effect") objects directly, but they are returned from the [`play_effect()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.play_effect "sound.play_effect") function. For simple one-off effects, you can ignore the return value of [`play_effect()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.play_effect "sound.play_effect"), but it can be useful for adjusting playback attributes like volume or pitch while the effect is playing, or to stop a looping effect.
|
| 44 |
+
|
| 45 |
+
### Effect Methods[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#effect-methods "Permalink to this heading")
|
| 46 |
+
|
| 47 |
+
Effect.stop()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect.stop "Permalink to this definition")
|
| 48 |
+
|
| 49 |
+
Stop playback of the sound effect.
|
| 50 |
+
|
| 51 |
+
### Effect Attributes[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#effect-attributes "Permalink to this heading")
|
| 52 |
+
|
| 53 |
+
Effect.looping[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect.looping "Permalink to this definition")
|
| 54 |
+
|
| 55 |
+
When set to True, the sound effect loops indefinitely, until playback is stopped with the [`Effect.stop()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect.stop "sound.Effect.stop") method.
|
| 56 |
+
|
| 57 |
+
Effect.pan[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect.pan "Permalink to this definition")
|
| 58 |
+
|
| 59 |
+
The stereo position of the sound effect (-1 = left, +1 = right, 0 = center).
|
| 60 |
+
|
| 61 |
+
Effect.pitch[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect.pitch "Permalink to this definition")
|
| 62 |
+
|
| 63 |
+
The pitch (playback speed) of the sound effect. The default is 1.0.
|
| 64 |
+
|
| 65 |
+
Effect.position[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect.position "Permalink to this definition")
|
| 66 |
+
|
| 67 |
+
The spatial (3D) position of the sound effect. The value is a 3-tuple (x, y, z). Note that this overrides the (stereo) `Sound.pan` attribute.
|
| 68 |
+
|
| 69 |
+
Effect.volume[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Effect.volume "Permalink to this definition")
|
| 70 |
+
|
| 71 |
+
The current volume of the sound effect.
|
| 72 |
+
|
| 73 |
+
## Player Class[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#player-class "Permalink to this heading")
|
| 74 |
+
|
| 75 |
+
_class_ sound.Player(_file_path_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player "Permalink to this definition")
|
| 76 |
+
|
| 77 |
+
The [`Player`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player "sound.Player") class provides an easy-to-use interface for playing audio files from disk. Using this class is recommended for music and other audio that doesn’t require very low latency. For sound effects in games, [`play_effect()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.play_effect "sound.play_effect") is more suitable.
|
| 78 |
+
|
| 79 |
+
### Player Methods[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#player-methods "Permalink to this heading")
|
| 80 |
+
|
| 81 |
+
Player.play()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.play "Permalink to this definition")
|
| 82 |
+
|
| 83 |
+
Start playing audio.
|
| 84 |
+
|
| 85 |
+
Player.stop()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.stop "Permalink to this definition")
|
| 86 |
+
|
| 87 |
+
Stop playing audio and reset the playback position.
|
| 88 |
+
|
| 89 |
+
Player.pause()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.pause "Permalink to this definition")
|
| 90 |
+
|
| 91 |
+
Stop playing audio, but keep the current playback position.
|
| 92 |
+
|
| 93 |
+
### Player Attributes[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#player-attributes "Permalink to this heading")
|
| 94 |
+
|
| 95 |
+
Player.current_time[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.current_time "Permalink to this definition")
|
| 96 |
+
|
| 97 |
+
The current playback position in seconds.
|
| 98 |
+
|
| 99 |
+
Player.duration[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.duration "Permalink to this definition")
|
| 100 |
+
|
| 101 |
+
The duration of the audio track (read-only).
|
| 102 |
+
|
| 103 |
+
Player.finished_handler[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.finished_handler "Permalink to this definition")
|
| 104 |
+
|
| 105 |
+
A function/callable that gets called without arguments when the player finishes playing.
|
| 106 |
+
|
| 107 |
+
Player.number_of_loops[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.number_of_loops "Permalink to this definition")
|
| 108 |
+
|
| 109 |
+
The number of times the audio track should be repeated. Set to -1 to repeat forever.
|
| 110 |
+
|
| 111 |
+
Player.playing[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.playing "Permalink to this definition")
|
| 112 |
+
|
| 113 |
+
A Boolean value that indicates whether the audio player is playing (True) or not (False).
|
| 114 |
+
|
| 115 |
+
Player.pan[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Player.pan "Permalink to this definition")
|
| 116 |
+
|
| 117 |
+
The stereo positioning of the played sound (-1 = left, +1 = right, 0 = centered).
|
| 118 |
+
|
| 119 |
+
## Recorder Class[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#recorder-class "Permalink to this heading")
|
| 120 |
+
|
| 121 |
+
_class_ sound.Recorder(_file_path_)[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder "Permalink to this definition")
|
| 122 |
+
|
| 123 |
+
The [`Recorder`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder "sound.Recorder") class provides high-level methods for recording audio files from the device’s microphone.
|
| 124 |
+
|
| 125 |
+
The file_path argument specifies the audio file that is created on disk. The audio file format is determined automatically from the file extension. It should be either .m4a(MPEG4 AAC) or .wav (Linear PCM). MPEG4 audio files are much smaller than Wav files, but you may want to use Wav if you intend to process raw audio data using the [`wave`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/wave.html#module-wave "wave: Provide an interface to the WAV sound format.")module.
|
| 126 |
+
|
| 127 |
+
### Recorder Methods[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#recorder-methods "Permalink to this heading")
|
| 128 |
+
|
| 129 |
+
Recorder.record([_duration_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.record "Permalink to this definition")
|
| 130 |
+
|
| 131 |
+
Start recording audio from the microphone. If the optional duration argument is provided, recording stops automatically after the specified number of seconds has elapsed. Otherwise, recording has to be stopped explicitly, using the [`Recorder.stop()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.stop "sound.Recorder.stop")method.
|
| 132 |
+
|
| 133 |
+
Recorder.stop()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.stop "Permalink to this definition")
|
| 134 |
+
|
| 135 |
+
Stop recording audio.
|
| 136 |
+
|
| 137 |
+
Recorder.pause()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.pause "Permalink to this definition")
|
| 138 |
+
|
| 139 |
+
Pause recording audio. Recording can be resumed using the [`Recorder.record()`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.record "sound.Recorder.record")method.
|
| 140 |
+
|
| 141 |
+
### Recorder Attributes[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#recorder-attributes "Permalink to this heading")
|
| 142 |
+
|
| 143 |
+
Recorder.current_time[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.current_time "Permalink to this definition")
|
| 144 |
+
|
| 145 |
+
The current duration of the active recording.
|
| 146 |
+
|
| 147 |
+
Recorder.recording[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.recording "Permalink to this definition")
|
| 148 |
+
|
| 149 |
+
Whether the recorder is currently recording (boolean).
|
| 150 |
+
|
| 151 |
+
Recorder.meters[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder.meters "Permalink to this definition")
|
| 152 |
+
|
| 153 |
+
The current average and peak power (read-only). Accessing this attribute automatically enables metering for this [`Recorder`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.Recorder "sound.Recorder")instance, which may consume additional processing recources. The value is a `dict`with `'average'` and `'peak'` keys, each containing a tuple of two numbers for the left and right channel. Example: `{'average':(-35.3, -30.1), 'peak': (-5.2, -8.2)}`.
|
| 154 |
+
|
| 155 |
+
## MIDIPlayer Class[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#midiplayer-class "Permalink to this heading")
|
| 156 |
+
|
| 157 |
+
_class_ sound.MIDIPlayer(_file_path_[, _sound_bank_path_])[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.MIDIPlayer "Permalink to this definition")
|
| 158 |
+
|
| 159 |
+
A [`MIDIPlayer`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.MIDIPlayer "sound.MIDIPlayer") provides simple playback functions for MIDI (.mid) files, using either the built-in “Merlin Silver” sound bank or one that you provide. If you provide a custom sound bank, it must be in sf2 format.
|
| 160 |
+
|
| 161 |
+
### MIDIPlayer Methods[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#midiplayer-methods "Permalink to this heading")
|
| 162 |
+
|
| 163 |
+
MIDIPlayer.play()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.MIDIPlayer.play "Permalink to this definition")
|
| 164 |
+
|
| 165 |
+
Start playback.
|
| 166 |
+
|
| 167 |
+
MIDIPlayer.stop()[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.MIDIPlayer.stop "Permalink to this definition")
|
| 168 |
+
|
| 169 |
+
Stop playback.
|
| 170 |
+
|
| 171 |
+
### MIDIPlayer Attributes[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#midiplayer-attributes "Permalink to this heading")
|
| 172 |
+
|
| 173 |
+
MIDIPlayer.current_time[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.MIDIPlayer.current_time "Permalink to this definition")
|
| 174 |
+
|
| 175 |
+
The current playback position.
|
| 176 |
+
|
| 177 |
+
MIDIPlayer.duration[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.MIDIPlayer.duration "Permalink to this definition")
|
| 178 |
+
|
| 179 |
+
The duration of the loaded MIDI file.
|
| 180 |
+
|
| 181 |
+
MIDIPlayer.rate[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/sound.html#sound.MIDIPlayer.rate "Permalink to this definition")
|
| 182 |
+
|
| 183 |
+
The playback rate (1.0 for normal speed).
|
URLScheme.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The Pythonista URL Scheme[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/urlscheme.html#the-pythonista-url-scheme "Permalink to this heading")
|
| 2 |
+
|
| 3 |
+
Pythonista can be launched from other applications with the custom `pythonista://`URL scheme.
|
| 4 |
+
|
| 5 |
+
Tip
|
| 6 |
+
|
| 7 |
+
You can generate `pythonista3://` URLs easily using the integrated URL and QR code generator. Tap on the “wrench” icon while editing a script, and select “Shortcuts” to get started. See also: [App Extensions and Shortcuts](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/pythonista_shortcuts.html#pythonista-shortcuts).
|
| 8 |
+
|
| 9 |
+
## Basics[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/urlscheme.html#basics "Permalink to this heading")
|
| 10 |
+
|
| 11 |
+
- **Open the app:**
|
| 12 |
+
|
| 13 |
+
Use `pythonista://` without any additional parameters to open the app without doing anything else.
|
| 14 |
+
|
| 15 |
+
- **Open a script for editing:**
|
| 16 |
+
|
| 17 |
+
Use `pythonista://MyScript.py` for opening one of your scripts in the editor. By default, the script path is relative to Pythonista’s local documents folder. Add `?root=icloud` or use a path like `iCloud/MyScript.py` to make the path relative to Pythonista’s iCloud folder instead.
|
| 18 |
+
|
| 19 |
+
- **Run a script from your library:**
|
| 20 |
+
|
| 21 |
+
Use `pythonista://MyScript.py?action=run`for running a script that is in your library. By default, the script path is relative to Pythonista’s local documents folder. Add `?root=icloud` to make the path relative to Pythonista’s iCloud folder instead.
|
| 22 |
+
|
| 23 |
+
- **Execute a snippet of Python code:**
|
| 24 |
+
|
| 25 |
+
Use `pythonista://?exec=<your code>` to run code that is embedded directly in the URL. Note that the code is _always_ shown to the user for confirmation before actually executing it.
|
| 26 |
+
|
| 27 |
+
In Pythonista 3.x, you can specify whether the code should be run with Python 3 or Python 2.7 by including a “shebang” as the first line (e.g. `#! python2` or `#! python3`).
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Note
|
| 31 |
+
|
| 32 |
+
In Pythonista 3.x, you can use `pythonista3://` instead of `pythonista://`. In Pythonista 2 (starting with 2.1), you can use `pythonista2://`. Use these schemes if you want to target a specific version of the app. In case both apps are installed, it is undefined which one of them handles a `pythonista://`URL.
|
| 33 |
+
|
| 34 |
+
## Command-line Arguments[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/urlscheme.html#command-line-arguments "Permalink to this heading")
|
| 35 |
+
|
| 36 |
+
When using the `action=run` parameter (see above), you can pass command-line arguments to the script in two ways:
|
| 37 |
+
|
| 38 |
+
- **Method 1: One args parameter**
|
| 39 |
+
|
| 40 |
+
Example: `pythonista://MyScript?action=run&args=foo%20bar`
|
| 41 |
+
|
| 42 |
+
When you pass a single string with the argsURL parameter, the string is split by spaces (the space is encoded as `%20` here) and [`sys.argv`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/sys.html#sys.argv "sys.argv") would be `[<script_path>,'foo', 'bar']` in this example.
|
| 43 |
+
|
| 44 |
+
If you want to pass arguments that contain spaces, you have to enclose them in double quotes (as you would in a classic shell).
|
| 45 |
+
|
| 46 |
+
This is basically the same as running a script by long-pressing the run button.
|
| 47 |
+
|
| 48 |
+
- **Method 2: Multiple argv parameters**
|
| 49 |
+
|
| 50 |
+
Example: `pythonista://MyScript?action=run&argv=foo&argv=bar`
|
| 51 |
+
|
| 52 |
+
Using multiple arguments that are all named argv, you don’t have to worry about quoting arguments that contain spaces. Each of the parameters corresponds to one element in [`sys.argv`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/sys.html#sys.argv "sys.argv").
|
| 53 |
+
|
| 54 |
+
If the URL contains at least one argvparameter, args is ignored.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
## Launching Other Apps[](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/urlscheme.html#launching-other-apps "Permalink to this heading")
|
| 58 |
+
|
| 59 |
+
If you want to go in the opposite direction, and open an app from Pythonista, you can do this with the [`webbrowser`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for web browsers.") or the [`shortcuts`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#module-shortcuts "shortcuts: Shortcuts Automation and URL Scheme Utilities") module.
|
| 60 |
+
|
| 61 |
+
For example, to open the Twitter app, you could use the following code:
|
| 62 |
+
|
| 63 |
+
import webbrowser
|
| 64 |
+
webbrowser.open('twitter://')
|
| 65 |
+
|
| 66 |
+
or:
|
| 67 |
+
|
| 68 |
+
import shortcuts
|
| 69 |
+
shortcuts.open_url('twitter://')
|
Ui.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
WhatsNew.md
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# What’s New in Pythonista[](http://omz-software.com/pythonista/docs/ios/new.html#what-s-new-in-pythonista "Permalink to this headline")
|
| 2 |
+
|
| 3 |
+
This page contains detailed information about changes in new versions of the Pythonista app.
|
| 4 |
+
|
| 5 |
+
## Version 3.4[#](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/new.html#version-3-4 "Permalink to this heading")
|
| 6 |
+
|
| 7 |
+
- Pythonista now supports [Python 3.10](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/whatsnew/3.10.html), so you can use structural pattern matching, assignment expressions (added in 3.8), and many other new language features and improvements in the standard library. See [What’s New in Python 3.10](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/whatsnew/3.10.html) for details.
|
| 8 |
+
|
| 9 |
+
- Shortcuts integration: You can now use Pythonista scripts as actions in Apple’s Shortcuts app, without launching the app. You’ll find more information in the [`shortcuts`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/shortcuts.html#module-shortcuts "shortcuts: Shortcuts Automation and URL Scheme Utilities") module documentation and on the [App Extensions and Shortcuts](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/pythonista_shortcuts.html#pythonista-shortcuts) page.
|
| 10 |
+
|
| 11 |
+
- Improved documentation with modernized theme, dark mode support, and additional content about third-party libraries.
|
| 12 |
+
|
| 13 |
+
- Improved support for the Magic Trackpad (and other pointer devices) on iPadOS.
|
| 14 |
+
|
| 15 |
+
- New text selection gestures in the editor for iOS 13+ (closer to system text gestures).
|
| 16 |
+
|
| 17 |
+
- Added [`pandas`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html#module-pandas "pandas"), [`openai`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html#module-openai "openai"), and various other [third-party modules](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/ios/third-party-modules.html). A lot of previously-included third-party libraries also have been updated to more recent versions.
|
| 18 |
+
|
| 19 |
+
- The in-app browser for the [`webbrowser`](zip:///private/var/containers/Bundle/Application/B2DF3891-0FBC-4BD4-8F1D-0A58DEB19B17/Pythonista3.app/Documentation.zip/py3/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for web browsers.")module now uses WKWebView and has a new “Open in Safari” button.
|
| 20 |
+
|
| 21 |
+
- Added “Black” ([psf/black](https://pypi.org/project/black/)) as an option in “Reformat Code”.
|
| 22 |
+
|
| 23 |
+
- Added a script using the ChatGPT API (with your own API key) to Examples/Keyboard.
|
| 24 |
+
|
| 25 |
+
- Python 2.7 is no longer included. Official support from the PSF has ended in 2020, so this has been coming for a long time. In case you still have Python 2.7 code, the 2to3 tool is still available from the wrench menu.
|
| 26 |
+
|
| 27 |
+
- Pythonista now requires iOS 12 or later.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
**Bug fixes:**
|
| 31 |
+
|
| 32 |
+
- Fixed an annoying issue with the up/down arrow keys not working correctly in the editor.
|
| 33 |
+
|
| 34 |
+
- Fixed an issue with the “dock console panel” button disappearing sometimes.
|
| 35 |
+
|
| 36 |
+
## Version 3.3[](http://omz-software.com/pythonista/docs/ios/new.html#version-3-3 "Permalink to this headline")
|
| 37 |
+
|
| 38 |
+
If you’ve been using the beta, you may notice that the “Siri Shortcuts” feature is missing from this release. It’s still planned, but the beta implementation was based on already-outdated iOS 12 APIs, and I want to take a little more time for a version that makes use of new iOS 13 features like custom parameters. Thanks for your patience! There’s still a lot of new stuff to discover in this update.
|
| 39 |
+
|
| 40 |
+
### New Features[](http://omz-software.com/pythonista/docs/ios/new.html#new-features "Permalink to this headline")
|
| 41 |
+
|
| 42 |
+
- Support for dark mode on iOS 13 – you can now select separate themes for light/dark mode, and Pythonista will switch automatically between them. Switching between themes is also a bit faster now.
|
| 43 |
+
- New scriptable keyboard extension and associated [`keyboard`](http://omz-software.com/pythonista/docs/ios/keyboard.html#module-keyboard "keyboard: Utilities for the Pythonista Keyboard") module:
|
| 44 |
+
|
| 45 |
+
- First off, this is _not_ intended to replace the system keyboard or your preferred third-party keyboard for most of your typing. It’s much more like the emoji picker, i.e. you’d typically switch to it just for specific tasks. The keyboard does not support any kind of AutoCorrect or QuickType suggestions. Just switch to the system keyboard if you need those (hold the ‘globe’ key).
|
| 46 |
+
- You can enable the keyboard in the Settings app (General > Keyboard > Keyboards > Add New Keyboard). It already includes various script shortcuts from the examples folder that you can try right away. If you want to add your own scripts, use the new “Shortcuts...” option from the ‘wrench’ menu.
|
| 47 |
+
- You can use the keyboard for simple things, like quickly inserting the current date/time in your favorite format, or even show a custom UI, like a calculator, in the keyboard view (or above a standard QWERTY keyboard). Have a look at the included examples to get an idea of what’s possible.
|
| 48 |
+
- The [`keyboard`](http://omz-software.com/pythonista/docs/ios/keyboard.html#module-keyboard "keyboard: Utilities for the Pythonista Keyboard") module includes keyboard-specific functionality for inserting text, modifying the cursor position, showing user interfaces in the keyboard, and more.
|
| 49 |
+
- Generally, the Pythonista keyboard does not _require_ that you enable ‘Full Access’, but you can’t use some functionality in your scripts then (e.g. clipboard or network access).
|
| 50 |
+
- Note: If you have a hardware keyboard connected to your iPad, and the Pythonista keyboard does not show up on screen when you select it, please tap and hold the `˅` button in the bottom-right corner of the screen.
|
| 51 |
+
|
| 52 |
+
- Lastly, this feature is somewhat experimental, and not all modules are available within the keyboard. Have a look at the new [`Keyboard examples<pythonista3://Examples/Keyboard/?action=open`_](http://omz-software.com/pythonista/docs/ios/new.html#id28) to see what’s possible.
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
- Improved and unified UI for creating script shortcuts in the new Pythonista keyboard, the share sheet extension, editor actions, and home screen icons, all from one place: The new “Shortcuts...” option in the ‘wrench’ menu. This also contains a new Pythonista URL generator for creating various kinds of `pythonista3://...` URLs and QR codes more easily.
|
| 56 |
+
- Significantly improved support for external keyboards across the entire app:
|
| 57 |
+
|
| 58 |
+
- A lot of new keyboard shortcuts are available – on iPad, you can view a list of shortcuts by holding the Cmd key (as you probably know), so I won’t list them all here. Keep in mind that the shortcuts depend on the current context, i.e. you’ll see different shortcuts in the script library, editor, console, etc.
|
| 59 |
+
- Many parts of the app (e.g. the script library (`Cmd``+``O`), editor actions (`Cmd``+``U`), settings (`Cmd``+`,``) ...) now support selection using the up/down arrow keys on hardware keyboards (and return to select). Where arrow key navigation is available, you can also go to the parent folder/view with `Cmd``+``up-arrow`.
|
| 60 |
+
- The arrow keys can now be used for scrolling in the editor, when you’re not typing. You can scroll entire pages with space/shift+space, Cmd+up/down scrolls to the top/bottom.
|
| 61 |
+
- Cmd+W also closes most modal dialogs (in addition to tabs) now, including :class:[`](http://omz-software.com/pythonista/docs/ios/new.html#id1)ui.View`s of your own scripts.
|
| 62 |
+
- The keyboard shortcuts Cmd+Alt+[1-9] are automatically assigned to editor action scripts you’ve added.
|
| 63 |
+
- Improved behavior of Cmd+return shortcut: You can now use it to toggle (and not just begin) editing, and it also works in the console.
|
| 64 |
+
- Cmd+[1-9] switches tabs (Cmd+1 shows the first tab, Cmd+2 the second...)
|
| 65 |
+
|
| 66 |
+
- The outline (list of functions) in the editor can now be filtered – just start typing if the keyboard is already active, or drag down the list to reveal the filter text field. The filter supports fuzzy matching, and you can also enter a line number.
|
| 67 |
+
- Support for opening external folders using the system’s file picker.
|
| 68 |
+
- Support for iOS 13 “Full Page” screenshots in the editor.
|
| 69 |
+
- New sample code (tap the links to open in editor):
|
| 70 |
+
|
| 71 |
+
- [CoreML Image Recognition](pythonista3://Examples/ObjC/CoreML%20Image%20Recognition.py?action=open)
|
| 72 |
+
- [Notification Quiz](pythonista3://Examples/Misc/Notification%20Quiz.py?action=open)
|
| 73 |
+
- [Satellite Image](pythonista3://Examples/Misc/Satellite%20Image.py?action=open)
|
| 74 |
+
- [Reverse Clock](pythonista3://Examples/Animation/Reverse%20Clock.py?action=open)
|
| 75 |
+
- Various scripts in the [Examples/Keyboard](pythonista3://Examples/Keyboard/?action=open) folder
|
| 76 |
+
|
| 77 |
+
- Revamped [`notification`](http://omz-software.com/pythonista/docs/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS") module with support for custom actions (buttons), location-based and repeating notifications, and more. The module also works in Pythonista’s app extensions now (it was previously main app only).
|
| 78 |
+
- The console’s history is now persistent (i.e. saved when you quit the app). You can also delete the console history by tapping and holding the ‘^’ button now.
|
| 79 |
+
- The documentation supports multiple tabs now.
|
| 80 |
+
- Scripts stored in iCloud are now compatible with the built-in “Run Script” and “Edit Script” actions of the (Apple) Shortcuts app. Just prefix the script name/path with “iCloud/”, e.g. use “iCloud/MyScript.py” (without quotes). Note: This integration soon won’t be available anymore, but you can get equivalent functionality by using “Open URL” actions with the new Pythonista URL generator in the “Shortcuts” menu.
|
| 81 |
+
- The “Quick Help” menu option is also available in non-Python files now (e.g. Markdown-based documentation), and there’s a new button to jump to the full documentation from the quick help popover.
|
| 82 |
+
|
| 83 |
+
### Built-in Modules[](http://omz-software.com/pythonista/docs/ios/new.html#built-in-modules "Permalink to this headline")
|
| 84 |
+
|
| 85 |
+
- Added [`shortcuts`](http://omz-software.com/pythonista/docs/ios/shortcuts.html#module-shortcuts "shortcuts: Support for Pythonista URLs and related utilities") module (currently just for generating `pythonista://` URLs, but more is planned).
|
| 86 |
+
- Added [`location.render_map_snapshot()`](http://omz-software.com/pythonista/docs/ios/location.html#location.render_map_snapshot "location.render_map_snapshot") function to the [`location`](http://omz-software.com/pythonista/docs/ios/location.html#module-location "location: Provides geo-location services on iOS") module for generating map images (using Apple Maps data).
|
| 87 |
+
- Improved [`photos.capture_image()`](http://omz-software.com/pythonista/docs/ios/photos.html#photos.capture_image "photos.capture_image") function with the option to use the selfie camera by default.
|
| 88 |
+
- Added [`cb.Peripheral.manufacturer_data`](http://omz-software.com/pythonista/docs/ios/cb.html#cb.Peripheral.manufacturer_data "cb.Peripheral.manufacturer_data") in [`cb`](http://omz-software.com/pythonista/docs/ios/cb.html#module-cb "cb") (CoreBluetooth) module.
|
| 89 |
+
- Added [`ui.Label.scales_font`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.Label.scales_font "ui.Label.scales_font") and [`ui.Label.min_font_scale`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.Label.min_font_scale "ui.Label.min_font_scale") attributes to [`ui.Label`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.Label "ui.Label").
|
| 90 |
+
- Added support for defining keyboard shortcuts in custom views (see [`ui.View.get_key_commands()`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View.get_key_commands "ui.View.get_key_commands")).
|
| 91 |
+
- Added [`reminders.Reminder.priority`](http://omz-software.com/pythonista/docs/ios/reminders.html#reminders.Reminder.priority "reminders.Reminder.priority") and [`reminders.Reminder.url`](http://omz-software.com/pythonista/docs/ios/reminders.html#reminders.Reminder.url "reminders.Reminder.url") attributes in the [`reminders`](http://omz-software.com/pythonista/docs/ios/reminders.html#module-reminders "reminders") module.
|
| 92 |
+
- Changed the default file type for [`dialogs.pick_document()`](http://omz-software.com/pythonista/docs/ios/dialogs.html#dialogs.pick_document "dialogs.pick_document") to ‘public.item’ (instead of ‘public.data’, this works better for unknown file types).
|
| 93 |
+
- Added (third-party) `emoji` module.
|
| 94 |
+
- Added documentation for [`ui.TextField.begin_editing()`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.TextField.begin_editing "ui.TextField.begin_editing"), [`ui.TextField.end_editing()`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.TextField.end_editing "ui.TextField.end_editing"), and [`ui.TextField.secure`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.TextField.secure "ui.TextField.secure").
|
| 95 |
+
|
| 96 |
+
### Bugfixes[](http://omz-software.com/pythonista/docs/ios/new.html#bugfixes "Permalink to this headline")
|
| 97 |
+
|
| 98 |
+
- Fixed a crash when saving images from the console when access to the photo library has not been granted yet.
|
| 99 |
+
- Fixed an issue with the extra key row hiding console input on 2018 iPad Pros.
|
| 100 |
+
- Fixed a crash when using arrow keys on an external keyboard while the on-screen keyboard is visible.
|
| 101 |
+
- Fixed problems with using iCloud scripts in the share sheet extension.
|
| 102 |
+
- Fixed triple-quoted byte strings and f-strings not being syntax-highlighted correctly.
|
| 103 |
+
- Fixed ‘wrench’ actions not being saved when invoked from the script library.
|
| 104 |
+
- Fixed broken [`turtle.pen()`](http://omz-software.com/pythonista/docs/library/turtle.html#turtle.pen "turtle.pen") function.
|
| 105 |
+
|
| 106 |
+
### Miscellaneous[](http://omz-software.com/pythonista/docs/ios/new.html#miscellaneous "Permalink to this headline")
|
| 107 |
+
|
| 108 |
+
- Selecting Python 2.7 as the default interpreter shows an “end of life” warning now (Python 2.7 will cease to be officially supported by the Python Software Foundation in 2020).
|
| 109 |
+
|
| 110 |
+
## Version 3.2[](http://omz-software.com/pythonista/docs/ios/new.html#version-3-2 "Permalink to this headline")
|
| 111 |
+
|
| 112 |
+
### Main New Features[](http://omz-software.com/pythonista/docs/ios/new.html#main-new-features "Permalink to this headline")
|
| 113 |
+
|
| 114 |
+
- Pythonista now uses Python 3.6.1 instead of 3.5. Among other things, this release brings support for f-strings, which make string formatting _much_ easier and more intuitive. In the code editor, embedded expressions in an f-string (enclosed in curly braces) get a slightly different background color, and code completion is available within those expressions.
|
| 115 |
+
- Scripts can be stored in iCloud now.
|
| 116 |
+
- Added support for opening external files (from other apps) in-place, using the document picker.
|
| 117 |
+
- Added “Open in…” menu support for opening Python scripts from other apps. If the sending app supports it, files are opened in-place (otherwise they’re imported to Pythonista’s script library).
|
| 118 |
+
- Added support for importing files from other apps using drag’n’drop (iOS 11 only).
|
| 119 |
+
- Files can be moved within the script library via drag’n’drop (iOS 11 only).
|
| 120 |
+
- Improved search in the script library (also searches subfolders now).
|
| 121 |
+
- New “Favorites” section to bookmark files and folders for quick access (e.g. when you have a deep folder hierarchy). On iOS 11, files in the script library can be marked as favorites with a right swipe action.
|
| 122 |
+
- Improved support for iPhone X.
|
| 123 |
+
- Removed the “thumbnail style” tab UI on iPhone. The tab bar UI is now essentially the same as on iPad, with some minor layout changes to make it work well on narrow screens.
|
| 124 |
+
|
| 125 |
+
### Console[](http://omz-software.com/pythonista/docs/ios/new.html#console "Permalink to this headline")
|
| 126 |
+
|
| 127 |
+
- Tapping the console’s title now shows the interpreter version selection and an option to copy all text output.
|
| 128 |
+
- Improved UI for [`turtle`](http://omz-software.com/pythonista/docs/library/turtle.html#module-turtle "turtle: An educational framework for simple graphics applications") and [`canvas`](http://omz-software.com/pythonista/docs/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") graphics output (it’s now part of the console and not shown in a separate tab).
|
| 129 |
+
|
| 130 |
+
### Documentation[](http://omz-software.com/pythonista/docs/ios/new.html#documentation "Permalink to this headline")
|
| 131 |
+
|
| 132 |
+
- The documentation now contains at least brief descriptions of almost every module that’s included. Previously, a lot of modules (e.g. [`pygments`](http://omz-software.com/pythonista/docs/ios/undocumented/pygments.html#module-pygments "pygments"), [`reportlab`](http://omz-software.com/pythonista/docs/ios/undocumented/reportlab.html#module-reportlab "reportlab"), [`yaml`](http://omz-software.com/pythonista/docs/ios/undocumented/yaml.html#module-yaml "yaml")...) weren’t mentioned anywhere, even though they’ve been part of Pythonista for a long time).
|
| 133 |
+
- Documentation search uses “fuzzy matching” now.
|
| 134 |
+
|
| 135 |
+
### Code Editor[](http://omz-software.com/pythonista/docs/ios/new.html#code-editor "Permalink to this headline")
|
| 136 |
+
|
| 137 |
+
- When creating a plain text, HTML, or Markdown file, you can now enter a custom file extension (the default extension won’t be appended).
|
| 138 |
+
- “Convert Tabs” is now “Reformat Code”, and supports applying coding style guides in addition to .
|
| 139 |
+
- Read-only files (e.g. standard library) are now marked with a lock icon in the editor.
|
| 140 |
+
- “Marker” comments (#todo/#fixme etc.) show up in the outline popup now.
|
| 141 |
+
- The “insert asset” button is now shown above the keyboard (while editing) instead of in the main toolbar.
|
| 142 |
+
|
| 143 |
+
### URL Scheme[](http://omz-software.com/pythonista/docs/ios/new.html#url-scheme "Permalink to this headline")
|
| 144 |
+
|
| 145 |
+
- The URL scheme supports a new `?exec=...` parameter that allows creating URLs that contain encoded Python source code. It is also possible to create an “exec” URL directly from a script in the editor (“Wrench” -> Share -> Create Executable URL).
|
| 146 |
+
- Fixed: Scripts that are launched via URL scheme (or homescreen shortcut) when the app isn’t running yet could have an incorrect working directory in some cases.
|
| 147 |
+
- When a script is launched via URL scheme, but the interpreter is busy, the script is now queued for execution instead of simply failing to run.
|
| 148 |
+
- The `pythonista3://` URL scheme has an additional “root=[icloud|local]” parameter opening/running scripts in iCloud.
|
| 149 |
+
|
| 150 |
+
### Changes in Built-in Modules[](http://omz-software.com/pythonista/docs/ios/new.html#changes-in-built-in-modules "Permalink to this headline")
|
| 151 |
+
|
| 152 |
+
- Added [`arrow`](http://omz-software.com/pythonista/docs/ios/undocumented/arrow.html#module-arrow "arrow") module (easy-to-use date/time manipulation).
|
| 153 |
+
|
| 154 |
+
- Added [`openpyxl`](http://omz-software.com/pythonista/docs/ios/undocumented/openpyxl.html#module-openpyxl "openpyxl") module (reading/writing Excel documents).
|
| 155 |
+
|
| 156 |
+
- [`appex`](http://omz-software.com/pythonista/docs/ios/appex.html#module-appex "appex: Utilities for Pythonista's App Extensions"):
|
| 157 |
+
|
| 158 |
+
> - New [`appex.get_web_page_info()`](http://omz-software.com/pythonista/docs/ios/appex.html#appex.get_web_page_info "appex.get_web_page_info") function for accessing information about the current web page when invoking the share sheet extension from Safari. This includes the page’s HTML code (constructed from the current DOM), selected text, cookies, and some other things that couldn’t be inferred from the URL alone.
|
| 159 |
+
> - [`appex.finish()`](http://omz-software.com/pythonista/docs/ios/appex.html#appex.finish "appex.finish") is now documented. This closes the share sheet extension, and optionally executes a snippet of JavaScript when the share sheet was invoked from Safari.
|
| 160 |
+
> - Fixed a potential crash when using [`appex.get_text()`](http://omz-software.com/pythonista/docs/ios/appex.html#appex.get_text "appex.get_text") from the Notes app.
|
| 161 |
+
|
| 162 |
+
- [`console`](http://omz-software.com/pythonista/docs/ios/console.html#module-console "console: Utilities for Console Output and Various System Services"):
|
| 163 |
+
|
| 164 |
+
> - Fixed crash in [`console.quicklook()`](http://omz-software.com/pythonista/docs/ios/console.html#console.quicklook "console.quicklook") when passing multiple paths (Python 3).
|
| 165 |
+
|
| 166 |
+
- [`contacts`](http://omz-software.com/pythonista/docs/ios/contacts.html#module-contacts "contacts: Access the iOS Contacts Database"):
|
| 167 |
+
|
| 168 |
+
> - New [`contacts.Person.image_data`](http://omz-software.com/pythonista/docs/ios/contacts.html#contacts.Person.image_data "contacts.Person.image_data") property.
|
| 169 |
+
|
| 170 |
+
- [`dialogs`](http://omz-software.com/pythonista/docs/ios/dialogs.html#module-dialogs "dialogs"):
|
| 171 |
+
|
| 172 |
+
> - Added a [`dialogs.pick_document()`](http://omz-software.com/pythonista/docs/ios/dialogs.html#dialogs.pick_document "dialogs.pick_document") function for importing files using the system document picker.
|
| 173 |
+
|
| 174 |
+
- [`notification`](http://omz-software.com/pythonista/docs/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS"):
|
| 175 |
+
|
| 176 |
+
> - The `sound_name` argument for notification.schedule supports all bundled sound effects now.
|
| 177 |
+
|
| 178 |
+
- [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python"):
|
| 179 |
+
|
| 180 |
+
> - [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") now supports `NSAutoreleasePool` and there’s a new [`objc_util.autoreleasepool()`](http://omz-software.com/pythonista/docs/ios/objc_util.html#objc_util.autoreleasepool "objc_util.autoreleasepool") context manager to make it a bit more pythonic to use (you should rarely need it though).
|
| 181 |
+
|
| 182 |
+
- [`photos`](http://omz-software.com/pythonista/docs/ios/photos.html#module-photos "photos: Provides access to the photo library on iOS"):
|
| 183 |
+
|
| 184 |
+
> - Fixed [`photos.AssetCollection.subtype`](http://omz-software.com/pythonista/docs/ios/photos.html#photos.AssetCollection.subtype "photos.AssetCollection.subtype") (always returned None previously).
|
| 185 |
+
> - Fixed [`photos.Asset.get_image()`](http://omz-software.com/pythonista/docs/ios/photos.html#photos.Asset.get_image "photos.Asset.get_image") for images in HEIC format (it’s also possible to open .heic files using Pillow now).
|
| 186 |
+
|
| 187 |
+
- [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS"):
|
| 188 |
+
|
| 189 |
+
> - New [`scene.Action.repeat_forever()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Action.repeat_forever "scene.Action.repeat_forever") factory method (it has the same effect as passing 0 for the repeat count to [`scene.Action.repeat()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Action.repeat "scene.Action.repeat"), but this is more intuitive).
|
| 190 |
+
> - Fixed incorrect value of [`scene.FILTERING_LINEAR`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.FILTERING_LINEAR "scene.FILTERING_LINEAR")
|
| 191 |
+
> - Fixed a crash in `scene.unload_image()`.
|
| 192 |
+
|
| 193 |
+
- [`sound`](http://omz-software.com/pythonista/docs/ios/sound.html#module-sound "sound: Sound effects and music playback"):
|
| 194 |
+
|
| 195 |
+
> - [`sound.Player`](http://omz-software.com/pythonista/docs/ios/sound.html#sound.Player "sound.Player") has a new `playing` property. The `finished_handler` property isn’t new, but was previously undocumented.
|
| 196 |
+
|
| 197 |
+
- [`ui`](http://omz-software.com/pythonista/docs/ios/ui.html#module-ui "ui: Native GUI for iOS"):
|
| 198 |
+
|
| 199 |
+
> - [`ui.View.present()`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View.present "ui.View.present") has a new `hide_close_button` parameter (use with caution, you may end up with a UI that you can’t close without force-quitting the app).
|
| 200 |
+
> - New [`ui.dump_view()`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.dump_view "ui.dump_view") function that produces pyui JSON from a [`ui.View`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View "ui.View") object.
|
| 201 |
+
> - Added ‘action’ field in UI editor for [`ui.TextField`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.TextField "ui.TextField") and :class`ui.SegmentedControl`.
|
| 202 |
+
> - In custom [`ui.View`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View "ui.View") subclasses, you can now implement an `update()` method (no arguments, except for self) that gets called automatically by an internal timer. To make this work, you also have to set the new [`ui.View.update_interval`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View.update_interval "ui.View.update_interval") attribute. It specifies how often the timer fires (e.g. set to 1.0, the timer fires every second). It defaults to 0.0 (disable update timer) because otherwise this new feature might break existing code that happens to implement a method called update.
|
| 203 |
+
> - Added an `objc_instance` property to [`ui.View`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View "ui.View"), [`ui.Image`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.Image "ui.Image") etc. This is just syntactic sugar for `objc_util.ObjCInstance(obj)`, but you don’t have to import the [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") module.
|
| 204 |
+
|
| 205 |
+
- [`webbrowser`](http://omz-software.com/pythonista/docs/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for Web browsers."):
|
| 206 |
+
|
| 207 |
+
> - The [`webbrowser`](http://omz-software.com/pythonista/docs/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for Web browsers.") module is a lot more compatible with other platforms now, and it supports a couple of 3rd-party web browsers directly (example: `webbrowser.get('Chrome').open('http://google.com')`)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
### General Bugfixes[](http://omz-software.com/pythonista/docs/ios/new.html#general-bugfixes "Permalink to this headline")
|
| 211 |
+
|
| 212 |
+
- Fixed text rendering glitches in settings on iPhone.
|
| 213 |
+
- Fixed “Copy”/”Open in Editor” buttons (in documentation) on iOS 10.3
|
| 214 |
+
- The Python interpreter is now built with IPv6 support. This should fix connectivity issues people were experiencing on IPv6-only networks (e.g. T-Mobile U.S.)
|
| 215 |
+
|
| 216 |
+
### Misc[](http://omz-software.com/pythonista/docs/ios/new.html#misc "Permalink to this headline")
|
| 217 |
+
|
| 218 |
+
- You can select an alternative app icon in the theme settings.
|
| 219 |
+
- Opening a file that is already open in a different tab switches to that tab instead of opening the file twice.
|
| 220 |
+
- Improved file browser in the app extension, and when picking scripts for editor actions (essentially the same as the main library now).
|
| 221 |
+
- The “open in new tab” swipe action is accessible with a right swipe (iOS 11 only). Instead of tapping on the button, you can also just continue the swipe gesture.
|
| 222 |
+
- When restoring tabs from a previous session, the selected tab is restored as well now.
|
| 223 |
+
- Added hardware keyboard shortcuts for switching, adding, and closing tabs.
|
| 224 |
+
- Improved scrolling behavior when selecting a function from the outline.
|
| 225 |
+
- When a script has annotations (style checker warnings etc.), the number of annotations is now shown after the filename.
|
| 226 |
+
- Creating a new file from an empty tab uses the currently selected folder in the library now.
|
| 227 |
+
- Files that are opened from other apps via “Open in…” menu are now opened in new tabs.
|
| 228 |
+
- Added a “launch in safe mode” setting that is accessible from the Settings app. This disables running pythonista_startup and restoring tabs from the previous session. It’s meant for troubleshooting purposes, i.e. when the app fails to launch, and only applies to the next launch.
|
| 229 |
+
|
| 230 |
+
## Version 3.1[](http://omz-software.com/pythonista/docs/ios/new.html#version-3-1 "Permalink to this headline")
|
| 231 |
+
|
| 232 |
+
- The console contains a new object inspector panel that allows you to view a list of all global variables and their attributes/members. Tap the (i) button to show or hide it.
|
| 233 |
+
- The new Pythonista Today widget allows you to run a script in Notification Center (or on the home/lock screen). You can find more information in the [`appex`](http://omz-software.com/pythonista/docs/ios/appex.html#module-appex "appex: Utilities for Pythonista's App Extensions") module documentation, and various examples of widget scripts are available in the updated _Examples_ folder.
|
| 234 |
+
- The Python 2 mode now uses Python 2.7.12 instead of 2.7.5.
|
| 235 |
+
- When using the share sheet extension with a file input (e.g. sharing a Mail attachment), an additional “Import File” option is shown for non-Python files.
|
| 236 |
+
- The [`speech`](http://omz-software.com/pythonista/docs/ios/speech.html#module-speech "speech") module contains new functions for speech recognition, in addition to speech synthesis (iOS 10 only).
|
| 237 |
+
- The [`sound`](http://omz-software.com/pythonista/docs/ios/sound.html#module-sound "sound: Sound effects and music playback") module contains a new Recorder class for recording audio files from the microphone. [`sound.play_effect()`](http://omz-software.com/pythonista/docs/ios/sound.html#sound.play_effect "sound.play_effect") and [`sound.Player`](http://omz-software.com/pythonista/docs/ios/sound.html#sound.Player "sound.Player") have also been improved to support stereo panning.
|
| 238 |
+
- The “Analyze (pyflakes)” and “Check Style” commands are now accessible from the “wrench” menu instead of by tapping and holding the run button.
|
| 239 |
+
- Tapping and holding the run button offers a new “Run Unit Tests” option. This discovers and runs tests in the current script using [`pytest`](http://omz-software.com/pythonista/docs/ios/undocumented/pytest.html#module-pytest "pytest") and shows test results directly in the editor.
|
| 240 |
+
- “Wrench” menu actions have a new “Reset Environment” option. When this is enabled, running the action behaves like running the script from the editor, i.e. global variables, imported modules etc. are cleared.
|
| 241 |
+
|
| 242 |
+
## Version 3.0[](http://omz-software.com/pythonista/docs/ios/new.html#version-3-0 "Permalink to this headline")
|
| 243 |
+
|
| 244 |
+
### Highlights[](http://omz-software.com/pythonista/docs/ios/new.html#highlights "Permalink to this headline")
|
| 245 |
+
|
| 246 |
+
- Support for both Python 3.5 and 2.7
|
| 247 |
+
- Integrated debugger with support for breakpoints and visual stack frame inspection
|
| 248 |
+
- Split-screen support on iPad Air 2 and later
|
| 249 |
+
- Theme editor for custom UI and syntax highlighting themes
|
| 250 |
+
- Integrated doctest support
|
| 251 |
+
- Integrated PEP-8 style checker
|
| 252 |
+
- Improved code completion with fuzzy matching and user-defined snippets
|
| 253 |
+
- Completely revamped [`photos`](http://omz-software.com/pythonista/docs/ios/photos.html#module-photos "photos: Provides access to the photo library on iOS") module, including editable metadata, album creation, content editing, and more
|
| 254 |
+
|
| 255 |
+
### Python 3 Suppport[](http://omz-software.com/pythonista/docs/ios/new.html#python-3-suppport "Permalink to this headline")
|
| 256 |
+
|
| 257 |
+
- Pythonista now supports Python 3.5, in addition to 2.7. You can select the default interpreter in the settings. It’s also possible to override the default interpreter for individual scripts, using a “shebang” like `#!python3` or `#! python2` as the first line of a script. Alternatively, you can tap and hold the run button to test a script in the non-default Python version. To help you with migrating your scripts to Python 3, you can use the “Python 2 to 3” tool in the “wrench” menu.
|
| 258 |
+
- To learn more about the differences between Python 2.7 and 3.x, I recommend the following article (external link): [The key differences between Python 2.7.x and Python 3.x with examples](http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html).
|
| 259 |
+
- If you also have Pythonista 2 installed, you can access your existing files through the special “Pythonista 2” folder in the script library. It is possible to move files from Pythonista 2 to Pythonista 3, but not vice-versa.
|
| 260 |
+
- The interactive console uses the default interpreter version, but you can switch to the other interpreter by tapping the `[2.7]` or `[3.5]` button (depending on the current setting).
|
| 261 |
+
|
| 262 |
+
### General[](http://omz-software.com/pythonista/docs/ios/new.html#general "Permalink to this headline")
|
| 263 |
+
|
| 264 |
+
- When using the URL scheme to launch Pythonista, you can now use `pythonista3://` instead of `pythonista://`. The old scheme is still supported, but its behavior is undefined if both Pythonista 2.x and 3.x are installed.
|
| 265 |
+
- On iPad Air 2 or later (including iPad Pro and iPad mini 4), Pythonista now fully supports the system-wide split-screen feature, so you can run another app next to Pythonista. Unfortunately, this also means that the `orientations` argument for [`ui.View.present()`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View.present "ui.View.present") no longer works on devices that support split-screen, i.e. you can’t lock the orientation of a view to portrait or landscape. If auto-rotation isn’t disabled via Control Center, the app _always_ auto-rotates. It is currently not possible to change this due to iOS limitations.
|
| 266 |
+
- Script shortcuts can now be added to the home screen from the _editor actions_ (“wrench”) menu. This basically works by setting up a website that redirects to a pythonista3:// URL, so the actual shortcut is added from Safari. The _Convert to PDF_ action has moved into the _Share_ menu.
|
| 267 |
+
- Improved support for [`doctest`](http://omz-software.com/pythonista/docs/library/doctest.html#module-doctest "doctest: Test pieces of code within docstrings.") tests – a new file template allows you to create a doctest file in Markdown format. There’s more information about this in the template itself. Doctest results are shown as annotations directly in the editor.
|
| 268 |
+
- You can now add your own templates to the “New File” menu. Simply add files to the _Templates_ folder (in the _Modules & Templates_ group).
|
| 269 |
+
- The view options for the script library (thumbnails, sort order) are now accesible directly in the library view (”...” button).
|
| 270 |
+
- Script shortcuts of the sharing extension can now be edited in the main app’s settings as well.
|
| 271 |
+
- Added a _Sound Effects_ setting to disable keyboard clicks etc.
|
| 272 |
+
- Various “special” folders (standard library, site-packages) are now grouped under “Modules & Templates” in the script library. Note that this doesn’t change the location of these folders on disk, so the site-packages and Templates folders still appear directly under “Documents” in the “Move Files” dialog.
|
| 273 |
+
- There are now separate site-packages folders for the two interpreter versions. site-packages-2 is only used by Python 2.7, site-packages-3 only by 3.5. The old site-packages folder still exists as a fallback for both interpreters.
|
| 274 |
+
|
| 275 |
+
### Debugger[](http://omz-software.com/pythonista/docs/ios/new.html#debugger "Permalink to this headline")
|
| 276 |
+
|
| 277 |
+
- Pythonista now includes a real debugger with support for breakpoints and visual stackframe inspection. This also replaces the traceback navigator, and enables more advanced “post-mortem” debugging when an exception occurs.
|
| 278 |
+
- To start breakpoint debugging, you have to add at least one breakpoint to your script (from the copy/paste menu). If a script contains breakpoints, tapping the run button will automatically offer a “Debug” option. The debugger is also shown in “post-mortem” mode when an unhandled exceptions occurs.
|
| 279 |
+
- The debugger UI appears as an overlay “window” on top of everything else, so that it’s possible to use it e.g. while a full-screen UI is presented. You can drag the debugger around on the screen if it gets in the way.
|
| 280 |
+
- To get more information about variables and stack frames, you can expand the debugger UI. The _Variables_ tab shows you all local and global variables in the selected stack frame, and you can expand objects (using the triangle buttons) to show their attributes (or members, in case of sequences or dicts), which makes it possible to inspect nested data structures. Tapping on a variable name shows a string representation, similar to `repr(var)`. For certain types of objects, a preview image is shown instead – this currently works for `PIL.Image`, [`ui.Image`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.Image "ui.Image"), [`ui.View`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View "ui.View"), and [`ui.Path`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.Path "ui.Path"), and it’s indicated by an “eye” icon in the list.
|
| 281 |
+
|
| 282 |
+
### Editor[](http://omz-software.com/pythonista/docs/ios/new.html#editor "Permalink to this headline")
|
| 283 |
+
|
| 284 |
+
- You can now define _snippets_ in the settings to insert frequently-used pieces of (boilerplate) code more quickly. When you set an abbreviation for a snippet, it shows up in the code completion suggestions. You can also select from a list of snippets in the editor using the copy/paste menu (with an empty selection) or the Cmd+D keyboard shortcut. Note: Snippets are only supported in Python files.
|
| 285 |
+
- The _Convert Tabs_ action is now undoable, and the confirmation dialog has a new option to open the indentation settings.
|
| 286 |
+
- Code completions can now be suggested based on fuzzy matching, e.g. typing “rage” also suggests “range()” (fuzzy-matched completions are always shown after precise matches).
|
| 287 |
+
- When using an external (Bluetooth) keyboard, code completions can now be selected with the up/down arrow keys.
|
| 288 |
+
- A new Cmd+L (or Ctrl+6) keyboard shortcut shows the current file’s outline (while editing) – The up/down arrow keys and return can be used to navigate to a different function without touching the screen.
|
| 289 |
+
- New Cmd+Shift+B shortcut for adding/removing breakpoints.
|
| 290 |
+
- When text is selected, pressing the tab key will now indent the selected line(s) instead of replacing the selected text with a tab. Shift-tab can be used to unindent on an external keyboard. On the on-screen keyboard, you can tap and hold the tab key for an unindent option. Indentation options are no longer shown in the copy/paste menu by default, but you can re-enable them in the settings (under “Keyboard & Typing”).
|
| 291 |
+
- The color picker (in the UI editor and asset picker) now allows entering arbitrary hex values by tapping on the color swatch.
|
| 292 |
+
- Integrated PEP8 style checker: You can check a script by tapping and holding the ▷ (run) button. Various options for customizing the rules are available in the settings. Issues are highlighted directly in the editor.
|
| 293 |
+
- Integrated pyflakes static analyzer: Similar to the PEP8 style checker, you can invoke this by tapping and holding the ▷ (run) button. The analyzer can find unused imports, undefined variables, and similar issues, which are also highlighted directly in the editor.
|
| 294 |
+
- When running a script with arguments (by tapping and holding the run button), the arguments are now saved for each script individually. When the current script has any saved arguments, they are also used for running the script normally (i.e. by just tapping the run button). The icon of the run button changes slightly to indicate whether there are arguments for the current script.
|
| 295 |
+
- Line numbers can optionally be shown on iPhone as well (line numbers were previously iPad-only).
|
| 296 |
+
- On iPhone, the “show tabs” button is now at the bottom of the screen (or above the keyboard), so that the _editor actions_ (“wrench”) menu is more easily accessible in the main toolbar.
|
| 297 |
+
- The search bar in the editor now uses the same extra keyboard row as the editor itself.
|
| 298 |
+
- New “Line Length Warning” option (under _Indentation & Coding Style_). When enabled, the end of long lines is highlighted. The maximum line length can be customized (79 by default).
|
| 299 |
+
|
| 300 |
+
### Console[](http://omz-software.com/pythonista/docs/ios/new.html#id3 "Permalink to this headline")
|
| 301 |
+
|
| 302 |
+
- Improved console prompt: The text input area now expands automatically for multi-line statements (e.g. function definitions, loops). The code completion behavior is also more consistent between the editor and console now (e.g. the tab key inserts the first suggestion).
|
| 303 |
+
- Showing images in the console has been improved substantially. A single tap on an image now opens it in a zoomable full-screen view. The sizing of image containers also matches the aspect ratio of the shown images more closely, especially when the console is in the more compact “docked” mode.
|
| 304 |
+
|
| 305 |
+
### Modules[](http://omz-software.com/pythonista/docs/ios/new.html#modules "Permalink to this headline")
|
| 306 |
+
|
| 307 |
+
#### [`photos`](http://omz-software.com/pythonista/docs/ios/photos.html#module-photos "photos: Provides access to the photo library on iOS")[](http://omz-software.com/pythonista/docs/ios/new.html#photos "Permalink to this headline")
|
| 308 |
+
|
| 309 |
+
- The [`photos`](http://omz-software.com/pythonista/docs/ios/photos.html#module-photos "photos: Provides access to the photo library on iOS") module has been completely revamped, and allows far more advanced access to the iOS photo library, including editable metadata, album creation, and content editing. Please see the [`photos`](http://omz-software.com/pythonista/docs/ios/photos.html#module-photos "photos: Provides access to the photo library on iOS")module docs for details.
|
| 310 |
+
|
| 311 |
+
#### [`editor`](http://omz-software.com/pythonista/docs/ios/editor.html#module-editor "editor: Scripting Pythonista's text editor")[](http://omz-software.com/pythonista/docs/ios/new.html#id4 "Permalink to this headline")
|
| 312 |
+
|
| 313 |
+
- [`editor.open_file()`](http://omz-software.com/pythonista/docs/ios/editor.html#editor.open_file "editor.open_file") now accepts both relative and absolute paths (relative paths are always resolved against ~/Documents though, not the current working directory).
|
| 314 |
+
- New [`editor.annotate_line()`](http://omz-software.com/pythonista/docs/ios/editor.html#editor.annotate_line "editor.annotate_line") function to annotate lines of code in the editor, similar to the integrated style checker and static analyzer.
|
| 315 |
+
- New [`editor.apply_ui_theme()`](http://omz-software.com/pythonista/docs/ios/editor.html#editor.apply_ui_theme "editor.apply_ui_theme") and [`editor.present_themed()`](http://omz-software.com/pythonista/docs/ios/editor.html#editor.present_themed "editor.present_themed") functions for styling a [`ui.View`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View "ui.View") with a theme.
|
| 316 |
+
|
| 317 |
+
#### [`ui`](http://omz-software.com/pythonista/docs/ios/ui.html#module-ui "ui: Native GUI for iOS")[](http://omz-software.com/pythonista/docs/ios/new.html#ui "Permalink to this headline")
|
| 318 |
+
|
| 319 |
+
- Views that are presented in ‘panel’ style can be closed programmatically now (the [`ui.View.close()`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View.close "ui.View.close")method was previously ignored for this presentation style).
|
| 320 |
+
- The [`ui.TableView`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.TableView "ui.TableView") initializer supports keyword arguments now (same as other [`ui.View`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.View "ui.View") subclasses)
|
| 321 |
+
- [`ui.WebView`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.WebView "ui.WebView") can now load non-https pages in the app extension.
|
| 322 |
+
- [`ui.WebView.load_url`](http://omz-software.com/pythonista/docs/ios/ui.html#ui.WebView.load_url "ui.WebView.load_url") now treats absolute file paths like file URLs (so you don’t have to construct a `file://` URL for loading local files).
|
| 323 |
+
- [`copy.copy()`](http://omz-software.com/pythonista/docs/library/copy.html#copy.copy "copy.copy") now works correctly for geometry types (`ui.Point`, `ui.Size`, `ui.Rect`).
|
| 324 |
+
|
| 325 |
+
#### [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS")[](http://omz-software.com/pythonista/docs/ios/new.html#scene "Permalink to this headline")
|
| 326 |
+
|
| 327 |
+
- Added support for MFi game controllers (see the module docs for details).
|
| 328 |
+
- `anchor_point` can now be passed as a keyword argument to the `SpriteNode` initializer.
|
| 329 |
+
- [`scene.Texture`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Texture "scene.Texture") has a new [`scene.Texture.subtexture()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Texture.subtexture "scene.Texture.subtexture") method that can be used for sprite sheets etc.
|
| 330 |
+
- `LabelNode` rendering quality is improved.
|
| 331 |
+
- Initializing [`scene.ShapeNode`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.ShapeNode "scene.ShapeNode") with `path=None` no longer throws an exception.
|
| 332 |
+
- Initializing [`scene.SpriteNode`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.SpriteNode "scene.SpriteNode") with `texture=None` no longer throws an exception.
|
| 333 |
+
- [`copy.copy()`](http://omz-software.com/pythonista/docs/library/copy.html#copy.copy "copy.copy") now works correctly for geometry types ([`scene.Point`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Point "scene.Point"), [`scene.Size`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Size "scene.Size"), [`scene.Rect`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Rect "scene.Rect")).
|
| 334 |
+
|
| 335 |
+
### Misc[](http://omz-software.com/pythonista/docs/ios/new.html#id5 "Permalink to this headline")
|
| 336 |
+
|
| 337 |
+
- The behavior of [`sys.exit()`](http://omz-software.com/pythonista/docs/library/sys.html#sys.exit "sys.exit") has changed: Registered [`atexit`](http://omz-software.com/pythonista/docs/library/atexit.html#module-atexit "atexit: Register and execute cleanup functions.") handlers are called, but nothing else happens (previous versions printed the exit code to the console). If you _really_ want to exit the app, use [`os._exit()`](http://omz-software.com/pythonista/docs/library/os.html#os._exit "os._exit").
|
| 338 |
+
- The editor no longer strips trailing blank lines when saving.
|
| 339 |
+
- The console has (limited) support for the `\b` and `\r` control characters now. The most common use case would be simple progress displays that overwrite the last line that was printed. Note that (unlike in a real terminal) these control characters only have an effect within a single string. Printing should also be a bit faster, and a couple of issues with [`console.set_color()`](http://omz-software.com/pythonista/docs/ios/console.html#console.set_color "console.set_color") and [`console.write_link()`](http://omz-software.com/pythonista/docs/ios/console.html#console.write_link "console.write_link")are fixed.
|
| 340 |
+
- When a script is running in the background for longer than iOS allows (about 3-4 minutes), the app should usually be suspended now (previously, it was killed immediately).
|
| 341 |
+
- It’s now possible to open folders in the library using the URL scheme. The syntax is the same as for opening files (pythonista3://some/path?action=open).
|
| 342 |
+
|
| 343 |
+
## Version 2.0[](http://omz-software.com/pythonista/docs/ios/new.html#version-2-0 "Permalink to this headline")
|
| 344 |
+
|
| 345 |
+
### General[](http://omz-software.com/pythonista/docs/ios/new.html#id6 "Permalink to this headline")
|
| 346 |
+
|
| 347 |
+
- Pythonista is now compatible with all iOS screen sizes – from iPhone 4 to iPad Pro, and everything in-between.
|
| 348 |
+
- For larger projects, you can now use multiple editor tabs to switch between related files more quickly.
|
| 349 |
+
- The Pythonista app extension allows you to run Python scripts directly within other apps, using the standard iOS share sheet. Depending on the context, you can use the new appex module to access data that was passed to the share sheet, e.g. images in the Photos app, URLs in Safari, text in Notes, etc. The app extension also provides an interactive console and a basic code editor for small tweaks.
|
| 350 |
+
- New and refined color themes are available in the settings; selecting a different theme now changes the entire app’s UI instead of just syntax highlighting.
|
| 351 |
+
- The file browser and editor have much better support for non-Python files. HTML, CSS, JavaScript, and Markdown files are syntax-highlighted in the editor, Zip archives can be extracted, and a QuickLook preview is available for most common file types, e.g. images, PDFs, and audio/video.
|
| 352 |
+
- Additional templates are available in the improved “new file” menu. You can also import photos from your camera roll as image files there.
|
| 353 |
+
- The console’s interactive prompt is now syntax-highlighted, and provides better support for Bluetooth keyboards (you can use the up/down keys to navigate the command history).
|
| 354 |
+
- You can now read the (pure Python) source code of the included standard library (and third-party modules) directly in the app. Simply enable the “Show Standard Library” setting if you’re interested in looking “under the hood”.
|
| 355 |
+
- The UI editor contains a much improved inspector panel, undo/redo support, the possibility to set custom attributes, and a lot of other refinements.
|
| 356 |
+
|
| 357 |
+
### Code Editor[](http://omz-software.com/pythonista/docs/ios/new.html#id7 "Permalink to this headline")
|
| 358 |
+
|
| 359 |
+
- The new traceback navigator allows you to get a lot more information about errors in your programs. When an exception occurs, a brief summary is shown at the top of the screen, and the line where the exception occurred is highlighted in the editor. By tapping on the exception summary, you can navigate the entire traceback, even if the source of the exception is in a different file. You can also tap the `<...`marker in the editor to inspect variable values in the selected stack frame.
|
| 360 |
+
- The editor actions (“wrench”) menu has been improved significantly. You can now assign custom icons and colors to your script shortcuts. It’s also possible to invoke the standard iOS share sheet from the actions menu. If you have an iPhone 6s or 6s Plus (with 3D Touch), you can launch shortcuts directly from the homescreen by pressing the Pythonista icon.
|
| 361 |
+
- The improved asset picker (`[+]` button) contains more free image and sound effect collections that can be used with the [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS"), [`ui`](http://omz-software.com/pythonista/docs/ios/ui.html#module-ui "ui: Native GUI for iOS"), and [`sound`](http://omz-software.com/pythonista/docs/ios/sound.html#module-sound "sound: Sound effects and music playback") modules. The UI for opening the asset picker is also consistent between iPad and iPhone now.
|
| 362 |
+
- When the cursor is inside a color string (e.g. ‘#ff0000’ or ‘red’) or built-in image name, a preview overlay is shown automatically. You can also tap the preview overlay to select a different color or image.
|
| 363 |
+
- The new _Highlight All_ option in the copy/paste menu allows you to quickly find all occurrences of a word (e.g. variable name), without typing anything in the search bar.
|
| 364 |
+
- You can adjust the indentation of a selected block of code more easily with the new `⇥ Indent` menu items (in the copy/paste menu).
|
| 365 |
+
- iPad only: The extended keyboard has a more compact layout by default. If you prefer a larger keyboard with an additional number row, you can enable this in the settings.
|
| 366 |
+
|
| 367 |
+
### Python / Modules[](http://omz-software.com/pythonista/docs/ios/new.html#python-modules "Permalink to this headline")
|
| 368 |
+
|
| 369 |
+
- The completely revamped [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") module gives you a lot more possibilities for building 2D games and animations in Pythonista. You can even use custom OpenGL fragment shaders. Lots of new sample code and a tutorial for building a simple game are available in the included _Examples_ folder.
|
| 370 |
+
- The [`ctypes`](http://omz-software.com/pythonista/docs/library/ctypes.html#module-ctypes "ctypes: A foreign function library for Python.") module from the standard library is finally available in Pythonista, and the custom [`objc_util`](http://omz-software.com/pythonista/docs/ios/objc_util.html#module-objc_util "objc_util: Utility module for "bridging" a limited set of Objective-APIs to Python") module uses this as the foundation for an Objective-C bridge that makes it possible to call native APIs using familiar Python syntax. A few sample scripts are included in the _Examples_ folder.
|
| 371 |
+
- You can customize the startup process of the Python interpreter by creating a file named “pythonista_startup.py” in the site-packages folder. When the app is launched, the interpreter will execute this module, so that all variables/functions/classes in the script become available globally. A common use case might be `from math import *` (if you want to use the console as a calculator). Note: If Pythonista becomes unusable due to a misbehaving startup script, you can launch the app in a “clean” state by entering `pythonista://` in Safari’s address field.
|
| 372 |
+
|
| 373 |
+
## Version 1.5[](http://omz-software.com/pythonista/docs/ios/new.html#version-1-5 "Permalink to this headline")
|
| 374 |
+
|
| 375 |
+
### General[](http://omz-software.com/pythonista/docs/ios/new.html#id8 "Permalink to this headline")
|
| 376 |
+
|
| 377 |
+
- You can no longer use the “Open in...” menu from other apps to open files in Pythonista. This change was made in order to comply with Apple’s app review guidelines.
|
| 378 |
+
- Xcode export is currently not available from within the app. I’m working on a way to create Xcode projects from Pythonista scripts on a Mac instead; details will be available on the [Pythonista website](http://omz-software.com/pythonista)soon.
|
| 379 |
+
- Smarter code completion – in situations that the old completion system couldn’t handle, Pythonista is now using the [jedi](http://jedi.jedidjah.ch/) library. This applies to things like instance members, where the type of the object can be inferred. The extended code completion can be somewhat slow, depending on your device generation and the size of modules you’re working with. It should get faster over time, as caches are built, and the old completion system continues to work while you’re waiting for jedi results, but in case you find this impacting the overall performance of the app and your scripts, you can disable extended completion separately in the settings.
|
| 380 |
+
- The documentation is now shown in the same panel as the console (this also applies to the built-in web browser used by the [`webbrowser`](http://omz-software.com/pythonista/docs/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for Web browsers.") module).
|
| 381 |
+
- The keyboard shortcut for switching between editor and console is now Cmd+J instead of Cmd+<Space> (the previous shortcut conflicted with switching the keyboard language).
|
| 382 |
+
- The integrated documentation has a new look.
|
| 383 |
+
- User-created modules are now reloaded automatically when running a script.
|
| 384 |
+
- New site-packages folder that is included in the default `sys.path` (this is a good location for shared modules that you want to import in scripts across different folders). Please note that the aforementioned automatic reloading doesn’t apply to modules in this folder (in order to improve performance).
|
| 385 |
+
|
| 386 |
+
### Python / Modules[](http://omz-software.com/pythonista/docs/ios/new.html#id9 "Permalink to this headline")
|
| 387 |
+
|
| 388 |
+
- Integrated [numpy](http://omz-software.com/pythonista/docs/numpy/reference/index.html) and [matplotlib](http://omz-software.com/pythonista/docs/matplotlib/index.html).
|
| 389 |
+
- New [`ui`](http://omz-software.com/pythonista/docs/ios/ui.html#module-ui "ui: Native GUI for iOS") module for creating native user interfaces on iOS, including an integrated UI editor.
|
| 390 |
+
- New [`motion`](http://omz-software.com/pythonista/docs/ios/motion.html#module-motion "motion: Provides motion sensor data on iOS") module for accessing the device’s motion sensors (accelerometer, gyroscope, magnetometer).
|
| 391 |
+
- The [`notification`](http://omz-software.com/pythonista/docs/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS") module has a new `notification.set_badge()` method.
|
| 392 |
+
- Various improvements in the [`photos`](http://omz-software.com/pythonista/docs/ios/photos.html#module-photos "photos: Provides access to the photo library on iOS") module, especially the `photos.pick_image()` function (new keyword arguments for multiple selection, including metadata, and returning raw data instead of decoded images)
|
| 393 |
+
- Updated various modules to the latest PyPI versions ([`bottle`](http://omz-software.com/pythonista/docs/ios/bottle/index.html#module-bottle "bottle"): 0.11.4 → 0.12.5, `bs4`: 4.1.3 → 4.3.2, [`feedparser`](http://omz-software.com/pythonista/docs/ios/feedparser.html#module-feedparser "feedparser"): 5.1.2 → 5.1.3, [`html5lib`](http://omz-software.com/pythonista/docs/ios/undocumented/html5lib.html#module-html5lib "html5lib"): 0.95-dev → 0.999, [`markdown2`](http://omz-software.com/pythonista/docs/ios/markdown2.html#module-markdown2 "markdown2: A fast and complete implementation of Markdown in Python"): 2.1.0 → 2.2.1, [`paramiko`](http://omz-software.com/pythonista/docs/ios/paramiko.html#module-paramiko "paramiko"): 1.7.7.1 → 1.13.0, [`pygments`](http://omz-software.com/pythonista/docs/ios/undocumented/pygments.html#module-pygments "pygments"): 1.5 → 1.6, [`pyparsing`](http://omz-software.com/pythonista/docs/ios/undocumented/pyparsing.html#module-pyparsing "pyparsing"): 1.5.7 → 2.0.1, [`requests`](http://omz-software.com/pythonista/docs/ios/requests.html#module-requests "requests"): 1.2.2 → 2.2.1)
|
| 394 |
+
|
| 395 |
+
### Bug Fixes[](http://omz-software.com/pythonista/docs/ios/new.html#bug-fixes "Permalink to this headline")
|
| 396 |
+
|
| 397 |
+
- Fixed incorrect behavior of up/down arrow keys (on hardware keyboards) after changing the selection via tap.
|
| 398 |
+
- Fixed a bug that caused indentation errors to be silently ignored (the script failed to run, but no error message was shown).
|
| 399 |
+
- Fixed a potential crash with photos.get_metadata on Chinese iPhones.
|
| 400 |
+
- Fixed a potential crash when the recursion limit was exceeded.
|
| 401 |
+
- The [`contacts`](http://omz-software.com/pythonista/docs/ios/contacts.html#module-contacts "contacts: Access the iOS Contacts Database") module can now retrieve the birthday of a person if the year isn’t set (the year component will be in the distant past in this case); this previously raised an internal exception.
|
| 402 |
+
|
| 403 |
+
## Version 1.4[](http://omz-software.com/pythonista/docs/ios/new.html#version-1-4 "Permalink to this headline")
|
| 404 |
+
|
| 405 |
+
### General[](http://omz-software.com/pythonista/docs/ios/new.html#id10 "Permalink to this headline")
|
| 406 |
+
|
| 407 |
+
- Complete UI overhaul for iOS 7.
|
| 408 |
+
- The interpreter is now based on Python 2.7.5.
|
| 409 |
+
- There’s a new setting to use spaces (“soft tabs”) instead of tab characters for indentation. The new “Convert Indentation...” action can be used to change the indentation of an existing script to the current setting.
|
| 410 |
+
- The action menu is now directly editable, without having to open the settings. It is also possible to add scripts in folders as actions, and actions can have custom command-line arguments.
|
| 411 |
+
- Non-Python files are now visible in the script library. Plain text files can be edited, for other files, a QuickLook preview is shown.
|
| 412 |
+
- All scripts are now run in the same interpreter that is also used for the interactive prompt. This makes the console a lot more useful because you can now define functions, classes, etc. in a script and experiment with them directly, without having to use `execfile()`. It also makes starting scripts a lot faster in most cases because imports are cached. By default, all global variables are cleared before running a script, but there’s a new setting to control that behavior in the “Interpreter Options” section. If you want to completely reset the interpreter, you can do that by tapping and holding the “Clear” button in the console.
|
| 413 |
+
- There’s a new option to always clear the console before running a script (in the “Interpreter Options” section of the settings).
|
| 414 |
+
- Tapping and holding an auto-completion suggestion now shows a help popover (iPad only).
|
| 415 |
+
- Improved support for (external) keyboard shortcuts – Shortcuts now use the Command key instead of Option/Alt, and there’s a new shortcut to clear the console output (Command + K).
|
| 416 |
+
- Scripts are auto-saved more often.
|
| 417 |
+
|
| 418 |
+
### Bug Fixes[](http://omz-software.com/pythonista/docs/ios/new.html#id11 "Permalink to this headline")
|
| 419 |
+
|
| 420 |
+
- Fixed: Using an action URL with the [`notification`](http://omz-software.com/pythonista/docs/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS") module did not work correctly if Pythonista was not already running in the background when the notification was activated.
|
| 421 |
+
- Fixed: Certain types of syntax errors (e.g. “‘break’ outside loop”) weren’t shown.
|
| 422 |
+
- Fixed: Exporting the entire script library also exports subfolders now.
|
| 423 |
+
- Fixed: CJK string encodings should work properly now.
|
| 424 |
+
- Fixed: After using the [`canvas`](http://omz-software.com/pythonista/docs/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") module, the console sometimes showed up, even though there was no output.
|
| 425 |
+
|
| 426 |
+
### Python / Modules[](http://omz-software.com/pythonista/docs/ios/new.html#id12 "Permalink to this headline")
|
| 427 |
+
|
| 428 |
+
- New [`contacts`](http://omz-software.com/pythonista/docs/ios/contacts.html#module-contacts "contacts: Access the iOS Contacts Database") module to access the iOS address book database.
|
| 429 |
+
- New [`location`](http://omz-software.com/pythonista/docs/ios/location.html#module-location "location: Provides geo-location services on iOS") module (access to GPS data and geocoding services)
|
| 430 |
+
- New [`speech`](http://omz-software.com/pythonista/docs/ios/speech.html#module-speech "speech") module (text-to-speech synthesis).
|
| 431 |
+
- Most standard library modules have been updated as part of the transition to Python 2.7.5.
|
| 432 |
+
- The [`console`](http://omz-software.com/pythonista/docs/ios/console.html#module-console "console: Utilities for Console Output and Various System Services") module has a new [`console.quicklook()`](http://omz-software.com/pythonista/docs/ios/console.html#console.quicklook "console.quicklook") function for previewing many types of files (e.g. PDF and Office documents, but also images and media files).
|
| 433 |
+
- The [`sound.play_effect()`](http://omz-software.com/pythonista/docs/ios/sound.html#sound.play_effect "sound.play_effect") function now supports local files (in addition to the built-in effects). It also has two new optional parameters for volume and pitch, and it’s possible to stop individual sound effects with the [`sound.stop_effect()`](http://omz-software.com/pythonista/docs/ios/sound.html#sound.stop_effect "sound.stop_effect") function.
|
| 434 |
+
- New [`webbrowser.add_to_reading_list()`](http://omz-software.com/pythonista/docs/library/webbrowser.html#webbrowser.add_to_reading_list "webbrowser.add_to_reading_list") function to add URLs to Safari’s Reading List.
|
| 435 |
+
- The standard library is now included as compiled bytecode (.pyc), in addition to the source code. This should improve performance in a lot of cases.
|
| 436 |
+
- The [`requests`](http://omz-software.com/pythonista/docs/ios/requests.html#module-requests "requests") module has been updated to the latest version.
|
| 437 |
+
- There’s a new anti_alias option in the [`scene.run()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.run "scene.run") function (the equivalent setting is gone).
|
| 438 |
+
|
| 439 |
+
#### Added Modules from the Standard Library[](http://omz-software.com/pythonista/docs/ios/new.html#added-modules-from-the-standard-library "Permalink to this headline")
|
| 440 |
+
|
| 441 |
+
- [`compileall`](http://omz-software.com/pythonista/docs/library/compileall.html#module-compileall "compileall: Tools for byte-compiling all Python source files in a directory tree.")
|
| 442 |
+
- `compiler`
|
| 443 |
+
- `imputil`
|
| 444 |
+
- `MimeWriter`
|
| 445 |
+
- `mimify`
|
| 446 |
+
- [`modulefinder`](http://omz-software.com/pythonista/docs/library/modulefinder.html#module-modulefinder "modulefinder: Find modules used by a script.")
|
| 447 |
+
- [`py_compile`](http://omz-software.com/pythonista/docs/library/py_compile.html#module-py_compile "py_compile: Generate byte-code files from Python source files.")
|
| 448 |
+
- `sha`
|
| 449 |
+
- `SimpleXMLRPCServer`
|
| 450 |
+
|
| 451 |
+
#### Other New Modules[](http://omz-software.com/pythonista/docs/ios/new.html#other-new-modules "Permalink to this headline")
|
| 452 |
+
|
| 453 |
+
- [`evernote`](http://omz-software.com/pythonista/docs/ios/evernote.html#module-evernote "evernote: The Evernote Python SDK")
|
| 454 |
+
- [`xmltodict`](http://omz-software.com/pythonista/docs/ios/xmltodict.html#module-xmltodict "xmltodict: Makes working with XML feel like you are working with JSON")
|
| 455 |
+
|
| 456 |
+
## Version 1.3[](http://omz-software.com/pythonista/docs/ios/new.html#version-1-3 "Permalink to this headline")
|
| 457 |
+
|
| 458 |
+
### General[](http://omz-software.com/pythonista/docs/ios/new.html#id13 "Permalink to this headline")
|
| 459 |
+
|
| 460 |
+
- Redesigned library view.
|
| 461 |
+
- It’s now possible to organize your scripts in folders.
|
| 462 |
+
- Triple-quoted strings are now highlighted correctly in the editor.
|
| 463 |
+
- Wrapped lines are indented and marked with a triangle symbol in the editor.
|
| 464 |
+
- Scripts can now continue to run for up to 10 minutes in the background. This is particularly useful for things like local web servers because it’s now possible to access them from Safari. Please note that sound effects will not be played while the app is in the background (but you can use the new [`notification`](http://omz-software.com/pythonista/docs/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS") module for that).
|
| 465 |
+
- New sample code: Image Warp and Markdown Conversion
|
| 466 |
+
|
| 467 |
+
### Python / Modules[](http://omz-software.com/pythonista/docs/ios/new.html#id14 "Permalink to this headline")
|
| 468 |
+
|
| 469 |
+
#### New Modules[](http://omz-software.com/pythonista/docs/ios/new.html#new-modules "Permalink to this headline")
|
| 470 |
+
|
| 471 |
+
- The new [`photos`](http://omz-software.com/pythonista/docs/ios/photos.html#module-photos "photos: Provides access to the photo library on iOS") module allows you to access images in your camera roll and manipulate them using the [`PIL`](http://omz-software.com/pythonista/docs/ios/PIL.html#module-PIL "PIL") (Python Imaging Library) module.
|
| 472 |
+
- The new [`notification`](http://omz-software.com/pythonista/docs/ios/notification.html#module-notification "notification: Integration with Notification Center on iOS") module allows you to schedule notifications that are shown in Notification Center.
|
| 473 |
+
- [`markdown2`](http://omz-software.com/pythonista/docs/ios/markdown2.html#module-markdown2 "markdown2: A fast and complete implementation of Markdown in Python") provides an alternative to the [`markdown`](http://omz-software.com/pythonista/docs/ios/markdown.html#module-markdown "markdown") module that was added in 1.2.
|
| 474 |
+
- [`paramiko`](http://omz-software.com/pythonista/docs/ios/paramiko.html#module-paramiko "paramiko")
|
| 475 |
+
|
| 476 |
+
#### Changes in Existing Modules[](http://omz-software.com/pythonista/docs/ios/new.html#changes-in-existing-modules "Permalink to this headline")
|
| 477 |
+
|
| 478 |
+
- [`console`](http://omz-software.com/pythonista/docs/ios/console.html#module-console "console: Utilities for Console Output and Various System Services") module:
|
| 479 |
+
|
| 480 |
+
> - New [`console.write_link()`](http://omz-software.com/pythonista/docs/ios/console.html#console.write_link "console.write_link") function to create tappable links in the console output area.
|
| 481 |
+
|
| 482 |
+
- [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") module:
|
| 483 |
+
|
| 484 |
+
> - New `scene.unload_image()` function that can be used to remove dynamically generated images (loaded via `scene.load_pil_image()`) from the cache.
|
| 485 |
+
> - Additional parameters in the `scene.image()` function allow to draw partial images (e.g. for things like sliding puzzles).
|
| 486 |
+
> - New `image_quad()` function to draw quadrangular portions of an image. It is also possible to use this to distort images. See the new Image Warp sample script for an example.
|
| 487 |
+
|
| 488 |
+
- [`webbrowser`](http://omz-software.com/pythonista/docs/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for Web browsers.") module:
|
| 489 |
+
|
| 490 |
+
> - It’s now possible to use [`webbrowser.open()`](http://omz-software.com/pythonista/docs/library/webbrowser.html#webbrowser.open "webbrowser.open") to open `http` or `https` URLs in Safari instead of the built-in browser. Simply replace `http://` with `safari-http://` in the URL (`safari-https://` for `https` URLs).
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
#### Added Modules from the Standard Library[](http://omz-software.com/pythonista/docs/ios/new.html#id15 "Permalink to this headline")
|
| 494 |
+
|
| 495 |
+
- Added `pyexpat` (this also fixes issues with some other modules, like [`plistlib`](http://omz-software.com/pythonista/docs/library/plistlib.html#module-plistlib "plistlib: Generate and parse Mac OS X plist files."))
|
| 496 |
+
- Added `xmlrpclib`
|
| 497 |
+
|
| 498 |
+
### Bug Fixes[](http://omz-software.com/pythonista/docs/ios/new.html#id16 "Permalink to this headline")
|
| 499 |
+
|
| 500 |
+
- Fixed issues in the [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") module with auto-rotation on iOS 6.
|
| 501 |
+
|
| 502 |
+
## Version 1.2[](http://omz-software.com/pythonista/docs/ios/new.html#version-1-2 "Permalink to this headline")
|
| 503 |
+
|
| 504 |
+
### General / UI[](http://omz-software.com/pythonista/docs/ios/new.html#general-ui "Permalink to this headline")
|
| 505 |
+
|
| 506 |
+
- Support for the larger screen of the iPhone 5.
|
| 507 |
+
- We now have a community forum, [come say hello](http://omz-software.com/pythonista/forums)!
|
| 508 |
+
- There is a new line spacing setting for the editor.
|
| 509 |
+
- iPad: Some keys on the extended keyboard can be used to enter different characters by touching and holding them. These keys are marked with a gray corner. You can also swipe up on such a key to enter the first alternate key (e.g. swipe up on the forward-slash key to insert a backslash).
|
| 510 |
+
- You can now run scripts with command-line arguments. Just touch and hold the run button.
|
| 511 |
+
- Pythonista now has a URL scheme for opening and running scripts that are in your library. See [The Pythonista URL Scheme](http://omz-software.com/pythonista/docs/ios/urlscheme.html#pythonista-urlscheme) for details.
|
| 512 |
+
- The prompt history no longer adds the same command multiple times if you repeat it.
|
| 513 |
+
- Added a new image collection of test images from the [USC-SIPI Image Database](http://sipi.usc.edu/database).
|
| 514 |
+
- New font option for the editor: Adobe Source Code Pro
|
| 515 |
+
- The “High Resolution” setting for retina screens is gone (it is now always enabled).
|
| 516 |
+
- The color picker now has an option to insert HTML-style colors. This is primarily meant for the new [`PIL`](http://omz-software.com/pythonista/docs/ios/PIL.html#module-PIL "PIL")module, but it has other uses as well.
|
| 517 |
+
- The gesture recognition on the extended keyboard is a bit less sensitive, so that it doesn’t interpret very small movements as gestures (which could sometimes interfere with tapping keys).
|
| 518 |
+
- Error markers in the editor now include the type of the exception.
|
| 519 |
+
- Some additional shortcuts are available to use with external hardware keyboards (see [External Keyboards](http://omz-software.com/pythonista/docs/ios/pythonista.html#using-external-keyboards) for details)
|
| 520 |
+
|
| 521 |
+
### Python / Modules[](http://omz-software.com/pythonista/docs/ios/new.html#id17 "Permalink to this headline")
|
| 522 |
+
|
| 523 |
+
#### New Modules[](http://omz-software.com/pythonista/docs/ios/new.html#id18 "Permalink to this headline")
|
| 524 |
+
|
| 525 |
+
- `bs4` (BeautifulSoup 4)
|
| 526 |
+
- [`dropbox`](http://omz-software.com/pythonista/docs/ios/dropbox.html#module-dropbox "dropbox")
|
| 527 |
+
- [`feedparser`](http://omz-software.com/pythonista/docs/ios/feedparser.html#module-feedparser "feedparser")
|
| 528 |
+
- [`markdown`](http://omz-software.com/pythonista/docs/ios/markdown.html#module-markdown "markdown")
|
| 529 |
+
- [`PIL`](http://omz-software.com/pythonista/docs/ios/PIL.html#module-PIL "PIL") (Python Imaging Library) – Have a look at the new “Image Effects” sample code to see how [`PIL`](http://omz-software.com/pythonista/docs/ios/PIL.html#module-PIL "PIL") is integrated with Pythonista.
|
| 530 |
+
|
| 531 |
+
#### Changes in Existing Modules[](http://omz-software.com/pythonista/docs/ios/new.html#id19 "Permalink to this headline")
|
| 532 |
+
|
| 533 |
+
- [`console`](http://omz-software.com/pythonista/docs/ios/console.html#module-console "console: Utilities for Console Output and Various System Services") module
|
| 534 |
+
|
| 535 |
+
- There is a new [`console.show_image()`](http://omz-software.com/pythonista/docs/ios/console.html#console.show_image "console.show_image") function to display images in the text output area. This is used internally by the `Image.show()` method in the [`PIL`](http://omz-software.com/pythonista/docs/ios/PIL.html#module-PIL "PIL") (Python Imaging Library) module that was also added in this release.
|
| 536 |
+
- There are two new functions for controlling the network activity indicator (“spinner”) in the status bar – [`console.show_activity()`](http://omz-software.com/pythonista/docs/ios/console.html#console.show_activity "console.show_activity") and [`console.hide_activity()`](http://omz-software.com/pythonista/docs/ios/console.html#console.hide_activity "console.hide_activity").
|
| 537 |
+
|
| 538 |
+
- [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") module
|
| 539 |
+
|
| 540 |
+
- You can now load images from regular image files with the `scene.load_image_file()` function. It’s also possible to load images created with [`PIL`](http://omz-software.com/pythonista/docs/ios/PIL.html#module-PIL "PIL") (Python Imaging Library), using the`scene.load_pil_image()` function.
|
| 541 |
+
- You can now get at the underlying image files of built-in images using the [`scene.get_image_path()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.get_image_path "scene.get_image_path") function.
|
| 542 |
+
- The new `scene.line()` function can be used to draw simple lines between two points.
|
| 543 |
+
- The new [`scene.get_screen_scale()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.get_screen_scale "scene.get_screen_scale") function allows you to detect programmatically if your script is running on a device with a retina screen.
|
| 544 |
+
|
| 545 |
+
- [`webbrowser`](http://omz-software.com/pythonista/docs/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for Web browsers.") module
|
| 546 |
+
|
| 547 |
+
- The [`webbrowser.open()`](http://omz-software.com/pythonista/docs/library/webbrowser.html#webbrowser.open "webbrowser.open") function has a new, optional modal parameter that blocks the script until the Done button is tapped in the browser. Additionally, there is an optional stop_when_doneparameter that can be used to stop a script automatically when the Done button is tapped in the browser.
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
#### Added Modules from the Standard Library[](http://omz-software.com/pythonista/docs/ios/new.html#id20 "Permalink to this headline")
|
| 551 |
+
|
| 552 |
+
- [`argparse`](http://omz-software.com/pythonista/docs/library/argparse.html#module-argparse "argparse: Command-line option and argument parsing library.")
|
| 553 |
+
- [`profile`](http://omz-software.com/pythonista/docs/library/profile.html#module-profile "profile: Python source profiler.")
|
| 554 |
+
- [`runpy`](http://omz-software.com/pythonista/docs/library/runpy.html#module-runpy "runpy: Locate and run Python modules without importing them first.")
|
| 555 |
+
|
| 556 |
+
### Documentation[](http://omz-software.com/pythonista/docs/ios/new.html#id21 "Permalink to this headline")
|
| 557 |
+
|
| 558 |
+
- On the iPad you can now view the current documentation page’s table of contents to make navigating in long documents easier.
|
| 559 |
+
- The documentation now uses DejaVuSansMono instead of Courier for code.
|
| 560 |
+
- Basic documentation for the [`requests`](http://omz-software.com/pythonista/docs/ios/requests.html#module-requests "requests") module is now included. The module itself was already available in version 1.1, but there was no documentation.
|
| 561 |
+
|
| 562 |
+
### Bug Fixes[](http://omz-software.com/pythonista/docs/ios/new.html#id22 "Permalink to this headline")
|
| 563 |
+
|
| 564 |
+
- Fixed an issue with big numbers not automatically being converted to long integers (something like `2** 100` should now work correctly without having to append `L` explicitly).
|
| 565 |
+
- The `__file__` variable is now correctly set when you run a script.
|
| 566 |
+
- Fixed issues with pasted text that contains unicode space characters.
|
| 567 |
+
- Fixed a bug in [`console.password_alert()`](http://omz-software.com/pythonista/docs/ios/console.html#console.password_alert "console.password_alert") that caused it to always return `None`.
|
| 568 |
+
- Some images in the Typicons library weren’t centered properly, this has been fixed.
|
| 569 |
+
- Fixed an issue on iOS 6 that caused the documentation viewer to start with a blank page.
|
| 570 |
+
- The [`clipboard`](http://omz-software.com/pythonista/docs/ios/clipboard.html#module-clipboard "clipboard: Provides copy and paste integration on iOS") module can handle unicode now.
|
| 571 |
+
- [`time.strptime()`](http://omz-software.com/pythonista/docs/library/time.html#time.strptime "time.strptime") works correctly now.
|
| 572 |
+
- [`editor.make_new_file()`](http://omz-software.com/pythonista/docs/ios/editor.html#editor.make_new_file "editor.make_new_file") no longer appends a numeric suffix when it’s not needed (i.e. when no file with the given name exists).
|
| 573 |
+
- Fixed a crash that occurred when canceling the console’s “Copy Text Output” dialog.
|
| 574 |
+
|
| 575 |
+
## Version 1.1[](http://omz-software.com/pythonista/docs/ios/new.html#version-1-1 "Permalink to this headline")
|
| 576 |
+
|
| 577 |
+
### General / UI[](http://omz-software.com/pythonista/docs/ios/new.html#id23 "Permalink to this headline")
|
| 578 |
+
|
| 579 |
+
- Pythonista is now a universal app that runs on all iOS devices!
|
| 580 |
+
- The editor has a new search feature.
|
| 581 |
+
- The editor itself is now scriptable (via the new [`editor`](http://omz-software.com/pythonista/docs/ios/editor.html#module-editor "editor: Scripting Pythonista's text editor") module) and custom scripts can be added to the new actions menu for quick access.
|
| 582 |
+
- Scripts can now be exported from the editor, optionally as Xcode projects that build standalone iOS apps (please note that in order to run standalone apps on an actual device you need to be a paying member of Apple’s iOS developer program).
|
| 583 |
+
- The script library has a new list mode (in the iPhone version, the thumbnail view is not present and this is the only view mode).
|
| 584 |
+
- The script library can be sorted by date instead of by name.
|
| 585 |
+
- The top toolbar that was shown for scenes created with the [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") module is gone, so that there is more room for drawing. Instead, there is only a small overlay button in the top-right corner to close a scene.
|
| 586 |
+
- The [Typicons](http://www.typicons.com/) set of monochrome icons is now available to use in the [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") and [`canvas`](http://omz-software.com/pythonista/docs/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") modules.
|
| 587 |
+
|
| 588 |
+
### Python / Modules[](http://omz-software.com/pythonista/docs/ios/new.html#id24 "Permalink to this headline")
|
| 589 |
+
|
| 590 |
+
- The [`scene.Scene`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Scene "scene.Scene") class has additional callbacks for when the home button is pressed ([`scene.Scene.pause()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Scene.pause "scene.Scene.pause")) or the app resumes from the background ([`scene.Scene.resume()`](http://omz-software.com/pythonista/docs/ios/scene.html#scene.Scene.resume "scene.Scene.resume")).
|
| 591 |
+
- Scenes can now optionally auto-rotate to different device orientations (see `scene.Scene.should_rotate()` for more information).
|
| 592 |
+
- The [`console`](http://omz-software.com/pythonista/docs/ios/console.html#module-console "console: Utilities for Console Output and Various System Services") module provides some new functions:
|
| 593 |
+
|
| 594 |
+
- [`console.secure_input()`](http://omz-software.com/pythonista/docs/ios/console.html#console.secure_input "console.secure_input") – A drop-in replacement for the built-in raw_input that is suitable for entering passwords (the text being entered is hidden).
|
| 595 |
+
- [`console.alert()`](http://omz-software.com/pythonista/docs/ios/console.html#console.alert "console.alert") – Allows you to show simple message boxes with up to three custom buttons, e.g. to ask the user for confirmation without requiring keyboard input.
|
| 596 |
+
- There are several other alert types that allow you to present alerts with text and/or password fields.
|
| 597 |
+
|
| 598 |
+
- The new [`keychain`](http://omz-software.com/pythonista/docs/ios/keychain.html#module-keychain "keychain: Persistent storage for passwords and other sensitive information") module provides simple functions for securely storing passwords.
|
| 599 |
+
- The new [`editor`](http://omz-software.com/pythonista/docs/ios/editor.html#module-editor "editor: Scripting Pythonista's text editor") module allows you to script Pythonista’s text editor itself, have a look at its documentation for some interesting examples.
|
| 600 |
+
- More modules from the Standard Library are included:
|
| 601 |
+
|
| 602 |
+
- [`gzip`](http://omz-software.com/pythonista/docs/library/gzip.html#module-gzip "gzip: Interfaces for gzip compression and decompression using file objects."), [`zipfile`](http://omz-software.com/pythonista/docs/library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.")
|
| 603 |
+
- [`ssl`](http://omz-software.com/pythonista/docs/library/ssl.html#module-ssl "ssl: TLS/SSL wrapper for socket objects")
|
| 604 |
+
- [`sqlite3`](http://omz-software.com/pythonista/docs/library/sqlite3.html#module-sqlite3 "sqlite3: A DB-API 2.0 implementation using SQLite 3.x.")
|
| 605 |
+
- [`email`](http://omz-software.com/pythonista/docs/library/email.html#module-email "email: Package supporting the parsing, manipulating, and generating email messages."), [`smtplib`](http://omz-software.com/pythonista/docs/library/smtplib.html#module-smtplib "smtplib: SMTP protocol client (requires sockets)."), [`imaplib`](http://omz-software.com/pythonista/docs/library/imaplib.html#module-imaplib "imaplib: IMAP4 protocol client (requires sockets)."), [`poplib`](http://omz-software.com/pythonista/docs/library/poplib.html#module-poplib "poplib: POP3 protocol client (requires sockets).")
|
| 606 |
+
- [`unicodedata`](http://omz-software.com/pythonista/docs/library/unicodedata.html#module-unicodedata "unicodedata: Access the Unicode Database.")
|
| 607 |
+
- A custom version of [`getpass`](http://omz-software.com/pythonista/docs/library/getpass.html#module-getpass "getpass: Portable reading of passwords and retrieval of the userid.") that uses the new [`console.secure_input()`](http://omz-software.com/pythonista/docs/ios/console.html#console.secure_input "console.secure_input") function.
|
| 608 |
+
|
| 609 |
+
- The Documents directory (where scripts are stored) is now the default directory in the interactive prompt, so that it’s easier to write files without giving an absolute path.
|
| 610 |
+
- The console output and text drawing functions in the [`scene`](http://omz-software.com/pythonista/docs/ios/scene.html#module-scene "scene: 2D graphics and animation on iOS") module support unicode now.
|
| 611 |
+
- The [`webbrowser`](http://omz-software.com/pythonista/docs/library/webbrowser.html#module-webbrowser "webbrowser: Easy-to-use controller for Web browsers.") now opens web pages in an in-app browser view instead of Safari.
|
| 612 |
+
- The [`canvas`](http://omz-software.com/pythonista/docs/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") module has new functions for drawing text.
|
| 613 |
+
|
| 614 |
+
### Documentation[](http://omz-software.com/pythonista/docs/ios/new.html#id25 "Permalink to this headline")
|
| 615 |
+
|
| 616 |
+
- All code samples now have “Copy” and “Open in Editor” buttons attached to them for quickly trying out things you read about.
|
| 617 |
+
- There is a new “Using Pythonista” page that provides an illustrated overview of the UI.
|
| 618 |
+
- Text in the documentation is now hyphenated for better readability, especially on the iPhone.
|
| 619 |
+
- The [`canvas`](http://omz-software.com/pythonista/docs/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") documentation contains more details and examples.
|
| 620 |
+
- The search suggestions in the documentation now show modules first.
|
| 621 |
+
- The chapter “Using the Python Interpreter” in the Python language tutorial is no longer included. Most of it only applies to other platforms and it seems to have caused some confusion. If you’re interested in this chapter, you can read it [here](http://docs.python.org/tutorial/interpreter.html). The same applies to “Interactive Input Editing and History Substitution” which can be found [here](http://docs.python.org/tutorial/interactive.html).
|
| 622 |
+
|
| 623 |
+
### Bug Fixes[](http://omz-software.com/pythonista/docs/ios/new.html#id27 "Permalink to this headline")
|
| 624 |
+
|
| 625 |
+
- A crash that could occur when holding down the backspace key has been fixed.
|
| 626 |
+
- Switching from the quick help popover to the full documentation should be more reliable.
|
| 627 |
+
- `os.getcwd()` should now work correctly.
|
| 628 |
+
- Entering a blank line when using `raw_input` no longer raises an `EOFError`.
|
| 629 |
+
- Drawing images with the [`canvas`](http://omz-software.com/pythonista/docs/ios/canvas.html#module-canvas "canvas: Provides drawing functions on iOS") module now works correctly if no other drawing functions were used before.
|
| 630 |
+
|
| 631 |
+
## Version 1.0[](http://omz-software.com/pythonista/docs/ios/new.html#version-1-0 "Permalink to this headline")
|
| 632 |
+
|
| 633 |
+
This is the initial release of Pythonista on the App Store.
|