@omz feature suggestion - text resizing in the documentation viewer - especially useful in conjunction with the newish console/docs sidebar-pinning.
Bonus points: keyboard commands to resize (command +, command - ???)
@omz Suggestion: simple built in sqlite3 viewer. When you go to a SQLite 3 db file in the Pythonista file browser, it would be great if instead of just showing a large icon and open in, it showed the contents. Would be useful as a quick reference while developing...remove friction for just quickly checking a result.
@omz one more suggestion regarding line numbers on different device sizes. What if you had line numbers be an optional toggle on all devices, with sane defaults in place. In fact, I'd love to be able to turn it off temporarily on an iPad Pro. And besides that way maybe you'd be recycling code anyways?
But the idea of a runtime app is something I've actually been thinking about and I think there's value there.
@omz is there anyway to use the shared "app group" functionality of iOS as Pythonista2 and Pythonista3 do to allow either the template, or an ancillary app made by you to act as a dedicated testing app - no editing abilities, just a container to run the app. Perhaps you could specify which script to run in the global iOS settings, or from within Pythonista2/3. You could really quickly make edits in the main apps, and test in the ancillary app to get a close idea of how quickly your app launches without all the editor cruft etc, so it would be built from the template. You could even charge money for it, and it would (i assume) be a minimal amount of work for you to implement since most of it is already done in the form of the template!
And looking to the future - once the issues with split-screen multitasking are remedied by Apple, imagine being able to have pythonista2/3 on one half of the screen and the testing app on another - it would be like a real development workflow!!
Food for thought.
I don't know if it has already been mentioned somewhere but it would be nice if the app shows that it's running a script via url "api".
If the app starts up and is not returning from a suspended state it just shows the initial screen and I am not sure if the script is running
The small indicator with the script name would be nice for the first start up
This is a wonderful idea. Also would be cool if when you tried to run a script while the other script is running, instead of just a modal dialog with one continue button if there was a button for "stop other script and run this one"
Or better yet ( I Don't have any idea of the technical feasibility of this) what if you could have multiple scripts running at the same time on entirely different threads with some sort of overhauled UI to make it clear how many and which scripts are running?
UPDATE: streamlined the code a little bit by making there be discreet "active" and "inactive" players, with a currentActivePlayer.otherPlayer attribute pointing to the other player to get rid of some unnecessary conditionals.
import ui,time import bz2 from base64 import b64decode #versions oldest - newest #https://gist.github.com/c61951cc318e7beaf378f6c292f94883 #https://gist.github.com/b8e6f213d19e9d4668a7f28bbd1efe9f #https://gist.github.com/712b62011ad0b76409f8faf77a3add8c class clockster(object): def __init__(self): #_______PACKAGED UI ______ compressedui = '''\ QlpoOTFBWSZTWeGcOhAAAz3fgFUQUGd/9T+E3Yq/r976QAL82kAisQyQ0mJhNRlT01DQPU e1T0mE0AAbUCJRqVP0U09pTygAPUaAPUAMh6TeqYHMAmmATIYAAmCYAAAIpTU9IT9JMm1A 9Q0AAAAABpSsGxSEROVLA/s9kiUJei8kAkksSaVEhIYQZzK1AQrUBuUGYwQQwLiohYHlmE GlLV+A/vRmcjTMwkHNmBgqD+wxhADgXkoDGvhvLCICx2jSuNSNdcDqff28dZk5ENgjuTXu TcU2KIxqiwl7wswixLUMsli7ULESKam7yePbJHSF0sl0hAOtEQMBGjSg19jAAvtVAsSRIF 6DhPl0Q93YzqpQL2wYnXvZj1HPablEQp+AhI0Gyo0QWOAf18kQMJIXEkTvCBCW2N3zUdkw aPDyJVBr3ODSrA1Duxob4YBHsjW+gxvdpGDJxIis9Ews2YGwVKBrp7UcXMEmBSICZjuq4x tYyWEE2CW5sZWDYCQyZVrJrsgeiwdV7lNmTAnGdIQjGVc0ybkHZNuHEggOP8K3OmNYIKwW W2j6Jhjm9Zd5wnlQDOlM52yze50sUc11IPut5YrOlQ1YXR0c68D9ZA6npDWn4HlyV5U+QH hx4kd7+76wDeO/hxFEfgNAYqZKUMAnBZzjG0U5nYNyksuOO0feXiaYSI9SX/XTErAqDkM1 jgBdy7Dm3eoDuLYdelsw8I6BTI6B553ByI5xPM4g5EW00BRhI8B/gXioeDpvLBA3YNnY2U J4GhrxPdTb0vE3HB0YgWc3SOo7bWVBiAtccjUoNGgN9SqY2RapMHCN8DImkpc/hkYhChkH QZNo4W6JkGU9TGEiBnWFg5akpaPSGBMtzA4AM7iSh8pCe5DBBiw0KX9aeyudSg3nyI8vNY nAn3kTrF3JFOFCQ4Zw6EA= ''' pyui = bz2.decompress(b64decode(compressedui)) v = ui.load_view_str(pyui.decode('utf-8')) self.v = v #_______END PACKAGED UI________ #self.v = ui.load_view() self.v.present('sheet') print(self.v["playerOne"]) self.startTime = time.time() self.gameBegun = False self.playerOne = self.v["playerOne"] self.playerTwo = self.v["playerTwo"] self.playerOne.timeLabel = self.v["playerOneTime"] self.playerTwo.timeLabel = self.v["playerTwoTime"] self.playerOne.totalTimeElapsed = 0 self.playerTwo.totalTimeElapsed = 0 self.playerOne.latestTurnElapsed = 0 self.playerTwo.latestTurnElapsed = 0 self.playerOne.otherPlayer = self.playerTwo self.playerTwo.otherPlayer = self.playerOne self.currentActivePlayer = "NOBODY" self.mainLoop() def togglePlayer(self,sender): print(sender) print(self.currentActivePlayer) if self.currentActivePlayer == sender: print("no change....") pass elif self.currentActivePlayer == "NOBODY": print("this means THE GAME HAS BEGUN!") self.gameBegun = True self.startTime = time.time() self.currentActivePlayer = sender self.currentInactivePlayer = self.currentActivePlayer.otherPlayer self.lastTimeToggled = time.time() print('...first move by: ',sender.name) else: print('currentActivePlayer changing....') #cleaning up old active plyayer self.currentActivePlayer.totalTimeElapsed = self.currentActivePlayer.totalTimeElapsed+self.currentActivePlayer.latestTurnElapsed #new active/inactive player self.currentActivePlayer = sender self.currentInactivePlayer = sender.otherPlayer self.lastTimeToggled = time.time() print("player toggled to",sender.name) def switchClockOnForSelectedPlayer(self): self.currentActivePlayer.latestTurnElapsed= time.time()-self.lastTimeToggled self.currentActivePlayer.timeToDisplay= self.currentActivePlayer.totalTimeElapsed + self.currentActivePlayer.latestTurnElapsed self.currentActivePlayer.timeLabel.text = str(round(self.currentActivePlayer.timeToDisplay)) self.totalElapsedTimeBySumming = self.currentActivePlayer.timeToDisplay + self.currentInactivePlayer.totalTimeElapsed @ui.in_background def mainLoop(self): while self.v.on_screen: if self.gameBegun is True: self.switchClockOnForSelectedPlayer() timeElapsed = round(time.time()-self.startTime,0) print(round(time.time()-self.startTime)) #self.v["totalTime"].text = str(timeElapsed) #CHANGED THE ABOVE TO BELOW SO TIMES ADD UP! self.v["totalTime"].text = str(round(self.totalElapsedTimeBySumming)) time.sleep(1) if __name__ == "__main__": a = clockster()
I hadn't used stash in a while as well, trying to launch it made this:
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/FC7E6E85-01F7-47E5-861F-A7ACA8D91116/Pythonista3/Documents/launch_stash.py", line 28, in <module> from stash import stash File "/private/var/mobile/Containers/Shared/AppGroup/FC7E6E85-01F7-47E5-861F-A7ACA8D91116/Pythonista3/Documents/site-packages/stash/stash.py", line 20, in <module> from system.shcommon import IN_PYTHONISTA, ON_IPAD File "/private/var/mobile/Containers/Shared/AppGroup/FC7E6E85-01F7-47E5-861F-A7ACA8D91116/Pythonista3/Documents/site-packages/stash/system/shcommon.py", line 29, in <module> 'Frameworks/PythonistaKit.framework/PythonistaKit') File "/var/containers/Bundle/Application/32DB935B-D704-4D48-BBE9-99A076A0D0AB/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/ctypes/__init__.py", line 364, in __init__ self._handle = _dlopen(self._name, mode) OSError: dlopen(/var/containers/Bundle/Application/32DB935B-D704-4D48-BBE9-99A076A0D0AB/Pythonista3.app/Frameworks/PythonistaKit.framework/PythonistaKit, 6): image not found
Pythonista 301012 beta.
@aronchi one more thing. You can add this script to your app extension for Pythonista. If you have a raw text file hosted via a server, if you go to it in safari and run this extension on it, it will ask you to name the file and then download that text. I think you might need to manually create a "Downloads" folder in documents.
# coding: utf-8 import requests import appex from console import alert, input_alert import os.path import os def main(): if not appex.is_running_extension(): alert("Error", "This script is intended to be run from the sharing extension.", "Exit", hide_cancel_button=True) return url = appex.get_url() if not url: alert("ERROR", "No input URL found. Execute this script from the sharing extension.", "Quit", hide_cancel_button=True) return root_path = "../../Documents/Downloads/" while True: filename = input_alert("Download File", "You have chosen to download file at URL:\n " + url + "\n\nEnter filename to save locally. Press Cancel to abort.") filename = root_path+filename if os.path.exists(filename): if os.path.isfile(filename): confirm = alert("Warning", "File %s exists. Overwrite?" % filename, "Overwrite", "Change Filename", hide_cancel_button=True) if confirm == 1: os.remove(filename) break else: alert("Critical Error.", "Path exists but is not a file. Exiting.", "Exit", hide_cancel_button=True) return else: break r = requests.get(url) if r.status_code != 200: alert("Invalid HTTP Response: %d, Exiting." %r.status_code, "Exit", hide_cancel_button=True) return confirm = alert("Confirm Download", "Text length: %d, Press OK to Save, Cancel to Quit" %len(r.text), "Save", "Cancel", hide_cancel_button=True) if confirm == 1: outfile = open(filename, "w") for line in r.text: outfile.write(line) outfile.close() alert("Success", "File Saved.", "Exit", hide_cancel_button=True) r.close() return if __name__ == '__main__': main()
Where are your 3 files stored?
Hi. There's a couple ways you can do this.
1.) Manually: Use Dropbox/some other tool to get the scripts on your iPad in any form. Copy the contents of each script, create a new script in Pythonista, name it as you'd like, and then paste the contents.
2.) DropBox sync: Use the dropboxsync.py script found elsewhere on this forum. You need to setup a Dropbox developer account and get a token. (I've been using the same version of that script that isn't perfect and has some problems with case, if anybody else knows what the latest greatest version of that script is please chime in)
3.) git / github : If you're familiar with using git/ github, you can create a repo in github. Then, install Stash (https://github.com/ywangd/stash), launch it, choose the directory and clone there using standard git commands.
Let us know if you have any questions.
At some point I started getting insecure platform warnings when requests was upgraded in Pythonista many many builds ago.
Something to note: running through the levels in 0.1 increments, it appears the only actual discrete levels are 1.0,0.9,0.8, and 0.4, unless there are finer increments between 0.4 and 1.0 ....
from objc_util import ObjCClass import time def toggle_flashlight(): AVCaptureDevice = ObjCClass('AVCaptureDevice') device = AVCaptureDevice.defaultDeviceWithMediaType_('vide') if not device.hasTorch(): raise RuntimeError('Device has no flashlight') mode = device.torchMode() device.lockForConfiguration_(None) if device.torchMode()>0: device.setTorchMode_((mode + 1) % 2) else: a =[1.0,0.9,0.8,0.7,0.6,0.5,0.4,0.3,0.2,0.1] for each in a: device.setTorchModeOnWithLevel_error_(each, None) print('level '+str(each)) time.sleep(.6) #device.setTorchModeOnWithLevel_error_(0.88, None) device.unlockForConfiguration() #device.setTorchModeOnWithLevel_error_(0.2, None) if __name__ == '__main__': toggle_flashlight()```