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.
Pythonista Webbrowser
-
I started making a webbrowser with the ui module. It's not much now, but it works.
https://github.com/SebastianJarsve/Pythonista-Webbrowser -
Lovely!
I'd suggest opening as a panel on ipad, and/or having some way to close it.
(Personally, I prefer panel, since it allows one to switch back and forth, with slight loss of real estate.). -
@JonB Thanks! That sounds like a great idea :) I'll look into that, and maybe in the future add some settings to control how the web browser should be presented.
To close the web browser now, you can slide down with two fingers, but that can probably sometimes interfere with zooming and other two-finger gestures.
-
Does anyone have any suggestions on how to implement tabs?
-
I don't have much experience with the UI module, but couldn't you just make another view for each tab?
-
Exactly, you can use an array of
ui.View
s with identical position for the tabs and callbring_to_front()
to switch to a tab.I'm not sure how the ui module (or UIKit, for that matter) works internally, but it may be more efficient to move the inactive views out of the screen to avoid them being drawn unnecessarily under the active tab.
-
Sorry if this has already been answered, but what are you guys using to download .pyui files?
-
github_download.py (Works for arbitray URLs as well.)
-
Or GitHubGet.py, Shellista or file_downloader. See for the discussion http://omz-forums.appspot.com/pythonista/post/5340168324120576
These are all slicker tools but often I still use a five-liner called
pyui_from_clipboard.py
to copy from GitHub and create a local .pyui file. -
Yeah, maybe I can just use multiple
ui.WebView
s and hide the ones that aren't showing.<br>
But I'm still wondering about <b>this</b> though. -
Were you asking about the menu that comes up with long press?
Seems like since your top level view is a custom view, you could override touch handling, no?
Though it might be hard to figure out what the user is clicking from the root view...maybe via javascript? -
Yes, I meant the little popup menu that comes up with a long press. <br>
I tried adding atouch_began
function in the custom view, but the function would only run if I touched something else than the webview, buttons or the textfield (i.e. if I touched nothing). It seems like the other views has its own way of recognizing touch gestures and then overrides the custom view's touch events or something. -
@Sebastian
It is very good.(^^
Since the change of 'Safari' and 'Pythonista' becomes unnecessary, it is convenient.I am also looking forward to future evolution.
Thanks! -
Hmm, yes, it seems like events are handled from bottom up. I don't see any way to register an event listener.
It is possible to create a transparent view that sits on top of your webview, which captures touch events before they go to the webview. .. But there is no way in python that I can tell to rethrow such events so the webview also gets a copy.
One option would be to simulate touch events using javascript after deciding whether you want to handle it or not. I have not tried this, also not sure if javascript and ui use same coordinate conventions, so some conversions /offsets might be required. The following javascript would dispatch a click. It probably would take a lot of thought about how to dispatch events such that they don't break sites that use javascript. For instance you might dispatch mousedown, mouseup, mousemove as you get them. Not sure if click gets generated automatically, or you'd have to dispatch your own on mouseup.
function click(x,y){ var ev = document.createEvent("MouseEvent"); var el = document.elementFromPoint(x,y); ev.initMouseEvent( "click", true /* bubble */, true /* cancelable */, window, null, x, y, 0, 0, /* coordinates */ false, false, false, false, /* modifier keys */ 0 /*left*/, null ); el.dispatchEvent(ev); }
Another option might be to not use an overlay, but inject some js event handling code after the page loads, and display the menu entirely in js. The javascript can interact with your python using a custom uri handling approach, to send back results. Probably similarly likely to clobber any existing js.
-
If you want to use the transparent top view maybe you can call
MyWebView.touch_began(touch)
once you decide that it should be sent to the WebView? -
Tried it. webview does not have touch_began, or the like, hence the javascript ideas.
-
It is explained how to use a custom contextual menu with a uiwebview <b>here</b>, but since we don't have a <b>
UiWindow
</b> we can't really catch the touch events before they are sent to the other views.Implementing tabs seems kinda pointless if you can't use 'open-in new tab'.