Python console in the Today widget
dgelessus last edited by dgelessus
The Today widget is no longer included in the release version of Pythonista! You cannot run this script in the notification center anymore!
If you still want to try it, you can download and run it normally in Pythonista. The UI will appear as a normal sheet view instead. This script is not very useful outside of the notification center though.
It had to be done. Not very useful and not very polished, but a fun exercise. The keyboard is just a bunch of
ui.Buttons, and the "text field" is a
ui.Label. There is a cursor, but it needs to be moved with arrow "keys".
To use this script meaningfully, you need to have Pythonista 3 and need to set this script as the Today Widget script. It is possible to run this script normally from the editor, but this meant for debugging - doing so is not very useful on its own and probably breaks the interactive console (until you restart the app).
(Warning: Very likely to crash if another app or too many widgets are running. Works best on the home screen.)
@dgelessus , thanks for sharing. Very nice. I didn't have any crashes. Was hard for me to use. I am using some dark theme in the today screen. Can't remember how I set it 😱
But was great to get a demo to see how it's done. Just hadn't tried it. Looking fwd to thinking of something that could be useful for me. I have one I dea. Just using it to quickly set notifications. Not sure if I can use it for that or not, but will look into it
@Phuket2 I'm not sure what dark theme you mean... The notification center is always dark, and the output text is provided by Pythonista and is always white. So I hardcoded the input line to be white and made the keyboard look like the dark onscreen keyboard.
is this Pythonista 3 only? im not on the beta yet and got a Non-ASCII character error when running within Pythonista.
The notification center widget is only available in the Pythonista 3 beta, and widget scripts are always run using Python 3. You can run the script normally from the editor, but that just pops the keyboard up as a normal view, which isn't very useful. (It also breaks
sys.stdinif you run it normally instead of setting it as a widget script.)
@dgelessus , all you say is right. But what I can't see is the editor window. I can see something...but it's like alpha .03 or something like that. I have a very dark custom theme set in Pythonista. I did change it to the very white default theme. I forced quit Pythonista and removed and re added Pythonista today widget. Same result. The only thing I didn't do, was to do was reboot my ipad
JonB last edited by
is the widget only an ios9 thing? 64 bit thing? I cannot seem to even see an option for enabling the widget(i both betas installed)
@JonB I accidentally set a deployment target of 9.3 for the widget (Xcode's default), so in the current beta, it won't show up on iOS 8 (or even older versions of iOS 9), will be fixed in the next build.
@dgelessus Thanks for clarifying. i just got Pythonista 3 and tried it out.
Unfortunately for me, it seems to show up for a brief second and disappear. After a few times of auto-reloading it says unable to load.
Seems to sound like the limits on memory @omz mentioned in the release notes. i have a decent number of libraries in my site-packages that might be causing the issue, I assume the entire site-packages is loaded in the today widget.
@khilnani No, the
site-packagesmodules are only loaded when you
If you have a
pythonista_startupfile, you may want to add an
appex.is_widget()check and make it not run in the today widget. Also you should try going to the home screen and then open the notification center - then you don't have any other app in the background taking up RAM.
The widget should actually skip
It turned out my problem with not seeing the text clearly was to do with the accessibility setting: Reduce Transparency, does not work so well in the today view
@dgelessus i'm not using pythonista_startup. i restarted the phone and tried it before launching any apps- entered my passcode for the home screen and pulled down. I see the same - the keyboard slides down and then disappears leaving a unable to load message.
i'm using 9.3.1 on an iPhone 6 Plus. let me know if there is anything i can help with if you'd more info. the script works within from within Pythonista.
Do you have many other widgets added? That's the only other possible issue I could think of. I'm on an iPad mini 1, which is a few years old, so I wouldn't expect you to have many issues on an iPhone 6...
Good point. I had Battery, Launcher, Dataman, and Darksky Next hour. Removed them all and only kept Pythonista, seems better still disappears after a second or two (vs half a second before)
JonB last edited by
pythonista_startup does seem to run in the today widget. Is there a way to check if the interpreter is being run in the today widget? I'd like to modify my startup to bypass if inside the today widget
@JonB The widget never runs the startup script.
JonB last edited by JonB
I am using @dgelessus's pythonista_startup, which is a folder called pythonsta_startup in site-packages with an init. My widget is just doing
import appex,ui v=ui.View(bg_color='red',frame=(0,0,200,200)) appex.set_widget_view(v)
but pythonista startup seems to be running ( until i get s could not load)
@JonB Okay, that's a bug then. For now, you might want to check
appex.is_widget()in your startup script.
@JonB I found the bug, the "preflight" script (for clearing globals etc.) was importing
pythonista_startupas a side effect.