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.
Built-in Modules and dialogs
-
I’ve been working on a ui project, and I’m trying to get a subview to show up similar to the console.alert(). Like how the alert pops-up and makes the main view darker but still visible. Anyhow, on my quest to achieving this, I figured I’d go see how the console actually does it, which led no where. My questions are: 1) Is there anyway to look at the code of the built-in modules, where are they stored or anything at all (other than the documentation)? And 2) How can I get a similar effect to console.alert()? Right now, the best I’ve gotten is a navigation view that pushes the alert, but the background becomes white and ruins the pop-up effect.
Thank you! -
-
@mcriley821 said:
look at the code of the built-in modules
For Python sources: Python Modules/Standard Library/site-packages
-
What you are looking for is a "shield" view. Depending on whether you want that to appear over top of the editor/console, or as part of a full screen presented view, the approach is a little different.
If you have an existing view, and just want to show a dialog over top of your view, see
https://forum.omz-software.com/topic/1563/shield-a-class-for-blocking-touch-eventsI believe the dialogs module source has a different implemention of a shield that is more general (it attaches to a UI.View in the pythonista view heirarchy, if memory serves) that lets you show dialogs over top of the editor ( actually, I might be wrong about that...)
In both cases, the shield view is just a solid color with alpha set to be semi transparent (dimming the background view), but that accepts touch events when tapping outside the dialog view to dismiss (if that's what you want). Then your dialog is a subview of the shield. The shield gets added as a subviee of the "root" view, and brought to the top -- if there is not a root view, you can either present a modal view controller using objc, or just find the right UIView and add a subview using objc.
For an easy way to get some of the important objc views that you can tack onto:
(From thisclass AppWindows(object): app=UIApplication.sharedApplication() @classmethod def root(cls): '''pythonista's root window. add here to be always present''' return cls.app.keyWindow() @classmethod def accessory(cls): '''accessory, a.k.a. console/panel. dragging does not work yet until gesture recognizer is added''' return cls.app.keyWindow().rootViewController().accessoryContainerView() @classmethod def detail(cls): '''detail, a.k.a. editor panel. dragging does not work yet until gesture recognizer is added''' return cls.app.keyWindow().rootViewController().detailContainerView()
-
@mcriley821 btw
https://github.com/jsbain/uicomponentsHad some very old attempts at making things like an improved input_alert (that plays nice with ui code), and a simple uidialog concept from before the dialogs module came around. These might give you some ideas -- these were intended to work cooperatively with an existing presented view, not the console or editor.
-
@cvp looking in the Standard Library doesn’t help here. Try looking for the console module that includes the alert definitions, or for the _ui module. I can’t find them there since they’re built-ins of the app I’m assuming.
@JonB that’s exactly what I’ve been trying to do! Thank you so much. Been stuck on this for a few days trying to get it perfect.
-
@mcriley821 ok, sorry, only Python code is available...