This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
''' | |
NOTE: This requires the latest beta of Pythonista 1.6 (build 160022) | |
Demo of using Pythonista's own internals to implement an editor view with syntax highlighting (basically the exact same view Pythonista uses itself) | |
IMPORTANT: This is just for fun -- I was curious if it would work at all, but I don't recommend that you rely on this for anything important. The way Pythonista's internals work can change at any time, and this code is *very* likely to break in the future. | |
''' | |
import ui |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
''' | |
NOTE: This requires the latest beta of Pythonista 1.6 (build 160022) | |
Demo of a custom ui.View subclass that embeds a native map view using MapKit (via objc_util). Tap and hold the map to drop a pin. | |
The MapView class is designed to be reusable, but it doesn't implement *everything* you might need. I hope that the existing methods give you a basic idea of how to add new capabilities though. For reference, here's Apple's documentation about the underlying MKMapView class: http://developer.apple.com/library/ios/documentation/MapKit/reference/MKMapView_Class/index.html | |
If you make any changes to the OMMapViewDelegate class, you need to restart the app. Because this requires creating a new Objective-C class, the code can basically only run once per session (it's not safe to delete an Objective-C class at runtime as long as instances of the class potentially exist). | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print system proxy settings using CFNetwork | |
# NOTE: Requires Pythonista 1.6 (currently in beta) | |
from objc_util import * | |
CFNetworkCopySystemProxySettings = c.CFNetworkCopySystemProxySettings | |
CFNetworkCopySystemProxySettings.restype = c_void_p | |
CFNetworkCopySystemProxySettings.argtypes = [] | |
proxy_settings = ObjCInstance(CFNetworkCopySystemProxySettings()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Minimal example for ui.Image.clip_to_mask | |
# Note: Due to the changed image names, this requires Pythonista 1.6 (beta), but it could work in 1.5bwith different image names. | |
import ui | |
with ui.ImageContext(256, 256) as ctx: | |
mask_img = ui.Image.named('iow:beaker_256') | |
img = ui.Image.named('test:Peppers') | |
mask_img.clip_to_mask() | |
img.draw() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''FTP server for Pythonista (iOS) | |
You can use this to exchange files with a Mac/PC or a file management app on the same device (e.g. Transmit). | |
If you use a Mac, you can connect from the Finder, using the "Go -> Connect to Server..." menu item. | |
''' | |
import os | |
from socket import gethostname |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# Batch-upload script for how-old.net (Pythonista) | |
import photos | |
import requests | |
import json | |
import ui | |
from io import BytesIO | |
result_size = 320 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# Starting point for emailing a group of people via Dispatch... | |
# The people in the group are identified by a unique string in the Notes field. | |
# TODO: Support setting the group identifier with an argument when launching the script via URL scheme (LCP...) - subject, body etc. could also be passed as arguments. | |
# Change this: | |
group_note = 'Group1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
'''Creates a zip archive of your Pythonista files and serves them via HTTP in your local network.''' | |
import sys | |
if sys.version_info[0] >= 3: | |
from http.server import SimpleHTTPRequestHandler, HTTPServer | |
else: | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
from BaseHTTPServer import HTTPServer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ui | |
from random import randint | |
import console | |
import clipboard | |
# Generate some random hex colors: | |
colors = ['#%X%X%X' % (randint(0,255), randint(0,255), randint(0,255)) for i in xrange(25)] | |
def tapped(sender): | |
r, g, b, a = sender.background_color | |
hex_color = '#%X%X%X' % (int(r*255), int(g*255), int(b*255)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import c_void_p, c_char_p, c_double, c_float, c_int, cdll, util, c_bool | |
import os | |
import time | |
# Load Objective-C runtime: | |
objc = cdll.LoadLibrary(util.find_library('objc')) | |
objc.sel_getName.restype = c_char_p | |
objc.sel_getName.argtypes = [c_void_p] | |
objc.sel_registerName.restype = c_void_p | |
objc.sel_registerName.argtypes = [c_char_p] |