I've finally managed to create a new Xcode template for Pythonista 2.x, and I've put it on GitHub:
Please see the included Readme file for setup instructions and configuration tips, and let me know if there are any questions or problems.
I've finally managed to create a new Xcode template for Pythonista 2.x, and I've put it on GitHub:
Please see the included Readme file for setup instructions and configuration tips, and let me know if there are any questions or problems.
Yay! Great job!
Thanks for this! The instructions are very thorough also. It is much appreciated.
@omz Has the 2 finger slide down gesture to close the Pythonista script been removed from the template? It doesn't appear to be working directly in Pythonista anymore. (This may have been addressed already, but I can't seem to find anything about it being removed).
I should hope it was. Otherwise, users could close your app window with no way to get it back besides relaunching the app.
@Webmaster4o I know this was an issue with previous versions of the template. If you look at the Pythonista-Tools github repo and download some of the apps in the apps store, you can close the app window.
Yes, it was. Why do you need this functionality?
@Webmaster4o Oh, I don't need/want it. I just wanted to make sure that it was removed and I don't have access to my mac at the moment to test it.
The gesture should still work for scripts running in Pythonista, but the Xcode template blocks this behavior, so a two-finger swipe gesture shouldn't do anything in a standalone app.
@ahenry91 Ah, I thought you were asking whether it had been removed because you had tried it and discovered that it had. My bad :)
Even works with the new Scene module.
Thanks so much.
Hey. I just wanted to stop by and say thank you for this. I consider it above and beyond, and the thorough instructions in the readme are very much appreciated. Time to go play with it.
@omz I'm adding my sincere thanks here as well. I've been making extensive use of the old one and chiming in about a desire for this here and there. This is seriously empowering stuff.
By the way, I listen to "Accidental Tech Podcast" (atp.fm) live, and there's a "tipster" from Apple that answers questions in their irc chat after the live shows - I mentioned pythonista and the fact that you can make iOS apps from iOS with it and asked if people were generally aware of it and how people inside apple felt about it. He said they were very aware, and highly impressed.
One question - is there a way to programmatically access the version number / build number from within python?
UPDATE: @omz thanks!!
@Tizzy
from objc_util import NSBundle
info = NSBundle.mainBundle().infoDictionary()
version = str(info['CFBundleVersion'])
short_version = str(info['CFBundleShortVersionString'])
Another question:
In the previous template I figured out that I could change the name of my main python file by searching for "main.py" and then changing it to whatever script I want to run.
in PAAppDelegate.m
NSString *mainScriptFile = [writableScriptDirectory stringByAppendingPathComponent:@"main.py"];
Is there any reason this would cause any problems or is not advisable?
UPDATE: thanks @omz
@Tizzy You can change that if you like.
Just tested it out and it almost works flawlessly, there were a few issues with indents, but nothing large. Being new to the world of programming, I was just wondering how exactly this work. Does the XcodeTemplate translate the Python language into Objective C, or does the Iphone actually support Python?
@Doglike-spike I think he basically rewrote parts of the Python language, in order for it to work on iOS. I'm not sure though.
Python (at least the main implementation, CPython) is written in C, and Objective-C is a superset of C, which means that C code should compile as Objective-C without modification. The iOS/Pythonista-specific modules like console, ui, location, etc. are custom extension modules written by omz, they are not available outside Pythonista.
@omz is it a shared codebase such that we can expect the template to always be up to date with the latest release version of pythonista?
@Tizzy Yes, the template is basically a subset of the main app. It would actually be possible to take the PythonistaKit framework out of the App Store version, and build your own template with it (I think @stroughtonsmith has actually done that).
Is there a way to access the 'normal' documents folder of the app from within (for accessing via iTunes file share after allowing in info.plist)? The 'normal' documents folder of Pythonista seems to be in an appgroup now.
os.path.expanduser('~/Documents') now results in '/private/var/mobile/Containers/Shared/AppGroup/E57F167E-F2F0-488A-A406-C6523F6F01DB/Documents' which is not accessable via iTunes fileshare.
No idea about iTunes, but what I use is a program called iExplorer. It allows you to read some files from a connected iOS device, but more importantly you can browse local backups, which also include the AppGroup folder.
@dgelessus IOS 8.3 (maybe 8.4, can't remember) made this a lot less useful. Now the app sandbox is not accessible through apps like iExplorer and iFunBox without jailbreak. This means no more going through apps and changing files, nor transferring files that represent game progress between devices.
@omz
I'm clearly a bit behind, but I got the template to work - thanks!
One thing - I used pickle to store config data in a .dat file. This seems to work while the app is running, but if the app is closed and restarted completely, the config data is reset rather than storing the previous state. Is there a way around this?
@chriswilson if you're talking about "running the app" and you mean running it in the Xcode simulator, there won't necessarily be persistent data between sessions because it creates a "virtual" directory where any file modifications in your code are executed, so when you close the simulator's virtual environment, your original files remain intact.
If that's not what you meant, ignore and wait for @omz or someone else to respond,
Thanks for your reply @Tizzy
I'm running it on my own phone rather than in the simulator, but as it's in development the same principle might apply I guess.
@chriswilson in that case, the data should stay persistent between runs of the same build, if you build and install it again, that's not the case. As far as I know you can't count on the data to persist between builds. For example -> build, create file, build, check if file has been created (returns FALSE - it won't exist).
@Tizzy
Unfortunately it's not saving and recalling the info even between runs of the same build.
@chriswilson When a template app is started, it basically copies everything from the "Script" folder (within the app bundle) to a writable directory. This will overwrite any changes you made to files that were also bundled with the app. The idea behind this is to handle changes you made in the Xcode project.
A relatively easy way around this would be to treat everything that you bundle with the app as read-only, and write to different files. E.g. if you bundle a default highscore list, you could call that "HighscoresDefault.dat" or something like that, and write the actual highscores to "Highscores.dat". If "Highscores.dat" doesn't exist yet, you could just copy "HighscoresDefault.dat"...
Is it possible to receive (and process) an Apple Push Notification using this template? Anybody get this working?
@sfederman no, apps can't watch or read notifications from other apps.
I think he means, if you deploy this as your own app, can you have push notifications.
I think youwould need to enable the appropriate entitlement. There are a few other links on that page as well, i think you have to create an ssl certificate, etc.
presumably your delegate needs to implement the appropriate delegate methods
and you need to registerForRemoteNotifications on the main app.
I have not tried this, but I have swizzled some of the other local notification handlers with the objc module, in theory this would work in a similar manner.
@JonB is correct. I'm not interested in intercepting a notification for another app, I'd like to set one up for a native deployed Pythonista app using this Xcode Template. I need to research & test a bit more, but I was curious if anyone else has already had success. Thank you for the tips...
@omz any chance of a update to the Xcode template anytime soon? Or at least make available the necessary binary libraries? I've a script that makes use of the Texture.subtexture() method, which does not seem to be available in this version. Many thanks!
Please tell me where I can get the template for Pythonista 3?
There is currently no Xcode template for Pythonista 3, but I'm working on something...