Forum Archive

Exporting

reefboy1

I currently have a export function for my application, named export()

import ui
import webbrowser

def export():
    url = 'www.youtube.com'
    webbrowser.open(url)




def screenshot_action(sender):
    v = sender.superview
    with ui.ImageContext(v.width, v.height) as c:
        v.draw_snapshot()
        c.get_image().show()

v = ui.load_view()
v.present('sheet')

I have a button to use the export function I made with UI, but when I click it it does not do anything. What do I do?

0942v8653

Your url needs to start with http:// or safari-http:// to get it to open.

You may also want to close the view first if you're using http:// (the built-in web browser).

reefboy1

Ok thanks

ccc

If you want to take a screenshot of a webpage, check out ScreenshotWebView.py which loads a webpage and then allows you to save a screenshot of the rendered webpage to the clipboard (NOT to a local file like ScreenshotView.py does.)

JonB

One other comment, export doesn't seem to ever get called. If you are trying to have export as a button action, it must have exactly one free input variable.

e.g

def export(sender):
   ...

for a non-instance method, or

def export(self, sender):
   ...

if this is inside a class.

Using just def export(), the button's action will try to call export(sender), which will generate a TypeError, which the ui code will silently suppress. I've made this mistake more than once, and it is confusing because no warning message is printed!