(fyi, you should wrap the code block with ```, to get proper syntax highlighting. reading the code w/out that is really difficult)
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Posts made by lukaskollmer
-
RE: [Share Code] Implemented x-callback-url
-
RE: [Share Code] Implemented x-callback-url
@eddo888 what do you mean?
did you swizzleopenPythonistaURL:
instead of swizzling -[UIApplicationDelegate application:openURL:options:]
? -
RE: Phone Call
Kinda. While there is no API to make a phone call, you can use the
webbrowser
module to open atel:PHONE_NUMBER
url. This will show a dialog, asking for confirmation to initiate the call. This should work for you since, when the call ends, you automatically return to Pythonista.For example, this code makes a call to Amazon Germany:
import webbrowser webbrowser.open('tel:+49-800-2629663')
-
RE: Include more custom fonts
Yes it is indeed possible to load a font from a
.otf
file at runtime (in fact, I implemented such a feature months ago using thectypes
module), but that's never as good as a proper first-party implementation. -
RE: objc_util wishlist
@scj643 it says that the type error is caused by the 3rd argument (which makes sense since 1 is
self
and 2 iscmd
).
And it can't say which type it wants because it doesn't know what to expect, it just knows that what it got was wrong -
RE: objc_util wishlist
@scj643 because it doesn't know. The objc runtime can only get the expected type encoding of an argument or a method's return value. The type encoding specifies which primitive type an argument should be (
float
/int
/char
/etc) or whether it is an object. But since ObjC classes are basically just glorifiedstruct
s, the runtime can't differentiate between different classes. (That's why objc has theid
type to represent "any objc-object") -
Include more custom fonts
It'd be nice if Pythonista offered Apple's
SF-Mono
font in addition to the existing fonts.Another font that'd be very well suited for Pythonista is
FiraCode
, which is a monospaced font with programming ligatures.
SinceUITextView
already supports ligatures, FiraCode would work fine in Pythonista.Example of FiraCode:
cc @omz
-
RE: objc_util wishlist
@scj643 said:
Currently objc_utils throws very cryptic errors when a type issue happens with an objc function
What exactly do you mean? I never found the
objc_util
errors to be cryptic at all. -
RE: Adding an image to my own album in Photos – how?
Pythonista already includes a "draw image and save to camera roll" script in the examples folder. You might be able to learn from that how to save the contents of your view to an image.
You can find the example script at
Documents -> Examples -> User Interface
-
RE: TableView Swipe Row for More Buttons
The built in
ui.TableView
supports only one action per row, but you can use theobjc_util
module to create a customUITableView
and implement the-[UITableViewDelegate tableView:editActionsForRowAtIndexPath:
method which returns an array of table view row actions.An other option for multiple actions per row would be to simply add an info accessory button to each row and show an alert w/ more options when the accessory button is pressed
-
App extension "Import File" feature
I noticed that the "Import file" feature of the app extension seems to be a bit inconsistent:
When I launch the extension from the share sheet in the Photos app, the import option is hidden, while it is available when I launch the extension from Pythonistas own share sheet or an app like Transmit.
The problem seems to be that the photos app only specifies the
public.png
key, while pythonista itself (and presumably Transmit as well) specify thepublic.file-url
key.I think Pythonista should offer the "Import" option in both cases.
The "Import File" option:
The items passed to the extension:
-
RE: Suppress print output at bottom of screen in Scene
If you're talking about the frames per second number in the bottom right corner, you can pass the
show_fps
parameter to the run function to suppress that debug output.Example:
run(MyScene(), show_fps=False)
-
RE: Use objc_util and NSURLConnection to make a GET request
NSURLConnection
was deprecated with iOS 9. However, you can use its replacement,NSURLSession
.This is a very basic example of how to use
NSURLSession
with parameters and how to get the response.
You can pass your parameters as a dictionary as second argument to thevalidate
method.
I think @omz advised against usingobjc_util.retain_global
, but it's necessary in this example to prevent the block from getting released before its getting called by the URL session.In a proper implementation, you probably want to create a Python class so that you can store the completion handler.
#!/usr/bin/env python3 import objc_util import urllib.parse from ctypes import c_void_p NSURLRequest = objc_util.ObjCClass("NSURLRequest") NSURLSession = objc_util.ObjCClass("NSURLSession") NSURLSessionConfiguration = objc_util.ObjCClass("NSURLSessionConfiguration") def validate(url, params, responseHandler): if params: params_encoded = urllib.parse.urlencode(params) else: params_encoded = "" url = objc_util.nsurl("{}?{}".format(url, params_encoded)) request = NSURLRequest.request(URL=url) configuration = NSURLSessionConfiguration.defaultSessionConfiguration() session = NSURLSession.session(Configuration=configuration) completionHandler = objc_util.ObjCBlock(responseHandler, restype=None, argtypes=[c_void_p, c_void_p, c_void_p, c_void_p]) objc_util.retain_global(completionHandler) dataTask = session.dataTask(Request=request, completionHandler=completionHandler) dataTask.resume() def responseHandlerBlock(_cmd, data, response, error): if error is not None: error = objc_util.ObjCInstance(error) print(error) return response = objc_util.ObjCInstance(response) data = objc_util.ObjCInstance(data) print(str(objc_util.nsdata_to_bytes(data))) url = "http://validate.jsontest.com" params = {"json" : {"first" : "lukas", "last" : "kollmer"}} validate(url, None, responseHandlerBlock)
-
RE: Preparation for Xcode ? Delete files in PythonistaAppTemplate?
@NoBetterName maximum app size shouldn't be a problem. iOS apps can be up to 4GB in size, and the app executable can be up to 60MB.
-
RE: [Feature request] ui.PageView
@dgelessus I know but that works fundamentally different from
UIPageViewController
. The page view controller pages between different independentUIViewController
s while the scroll view just displays its subviews next to each other. -
[Feature request] ui.PageView
It'd be awesome to have a
ui.PageView
component in theui
module.A
UIPageViewController
is a View Controller that lets you swipe between multiple child view controllers. It displays a line of dots at the bottom to indicate the current page.
You can also configure custom transitions for navigating between pages.SpringBoard (the iOS homescreen) is a good example of an
UIPageViewController
. -
RE: Need help about ui function
@omz doesn't iOS 10 require a
NSAppleMusicUsageDescription
entry in theInfo.plist
to access theMediaPlayer
framework? -
RE: Importing sound files
You could host the file on a web server and use
urllib.urlretrieve
to download the file.Example:
import urllib.request urllib.request.urlretrieve ("http://www.example.com/songs/mp3.mp3", "mp3.mp3")
-
RE: Delete Module
They still could use the
ui
module to build their own web browser.
It'd take only 3 lines.