• uj_jonas

    Unfold the pink sheet and press "print traceback" then go into the console

    posted in Pythonista read more
  • uj_jonas

    @Cethric thanks. Didn't even think of that

    posted in Pythonista read more
  • uj_jonas

    @ccc said:

    import ui
    main = ui.ScrollView(frame=(0, 0, *ui.get_screen_size()))
    main.content_size = (1920, 1080)
    wv = ui.WebView(frame=(0, 0, *main.content_size))
    wv.load_url('http://www.example.com')
    main.add_subview(wv)
    main.present()

    Can I do this and still have the wv_container? I kinda need my webview inside a separate view :/

    posted in Pythonista read more
  • uj_jonas

    I have an iPad 4 with 720p resolution. When I run this code, the webview prevents me from scrolling to the right.

    import ui
    
    main = ui.View(frame=(0, 0, ui.get_screen_size()[0], ui.get_screen_size()[1]))
    wv_container = ui.View(frame=(0, 0, 1920, 1080))
    wv = ui.WebView(frame=wv_container.frame)
    wv.load_url('http://www.example.com')
    
    wv_container.add_subview(wv)
    main.add_subview(wv_container)
    main.present('fullscreen')
    

    posted in Pythonista read more
  • uj_jonas

    So I know the question has been answered, but I just wanted to share this. It's just another approach.

    import ui, appex
    class wvdelegate(object):
        def webview_did_finish_load(self, webview):
            html = webview.eval_js('document.documentElement.innerHTML')
            webview.load_html('<xmp>' + html + r'<\xmp>')
            webview.delegate = None
    wv = ui.WebView()
    wv.load_url(appex.get_url())
    wv.delegate = wvdelegate()
    wv.present()
    

    You could also do like this to copy the HTML

    import ui, appex, clipboard
    class wvdelegate(object):
        def webview_did_finish_load(self, webview):
            self.html = webview.eval_js('document.documentElement.innerHTML')
            webview.load_html('<xmp>' + self.html + r'<\xmp>')
            webview.delegate.webview_did_finish_load = None
            wv.right_button_items = [ui.ButtonItem(image=ui.Image('iob:clipboard_32'), action=lambda x: clipboard.set(wv.delegate.html))]
    wv = ui.WebView()
    wv.load_url(appex.get_url())
    wv.delegate = wvdelegate()
    wv.present()
    

    posted in Pythonista read more
  • uj_jonas

    Aww :/

    Well thanks for answering

    posted in Pythonista read more
  • uj_jonas

    I wanted to convert HTML to PDF and looked it on Google. I found the pdfkit docs, but when I tried using it

    import pdfkit
    
    pdfkit.from_url('https://google.com', sys.argv[0][:-7] + 'out.pdf')
    

    I got a PermissionError

    My guess is it's just iOS restricting me, but I'd like to know if I'm doing something wrong.

    posted in Pythonista read more
  • uj_jonas

    Awesome :D definitely going to be using this. I just made a few changes to it, so that it writes it in the editor directly instead of copying it to the clipboard.

    Also, I just have to know, what keyboard are you using?

    posted in Pythonista read more
  • uj_jonas

    @happy_variable
    I don't know why you get that error, but try appex.get_attachments()[0] instead of appex.get_image()
    That did it for me :/

    Oh, and remove the str() around img on the line you get the error

    posted in Pythonista read more
  • uj_jonas

    @NickAtNight Yes. In Python 3 print is a function.
    If you want to run your script to run in Python 2 you could add
    #! python2 at the top of your script like this:

    #! python2
    
    var = raw_input('using raw_input()')
    print 'python 2 print'
    

    You can also test your script in Python 2 by holding down the play button and choosing "Run with Python 2.7"

    posted in Pythonista read more
  • uj_jonas

    @Phuket2 I could have left that part out, but didn't since you're such a big part of the forum.

    There's not much code to run, if it can't run yours ;)

    posted in Pythonista read more
  • uj_jonas

    @omz yeah it probably would. I looked up ways to make scripts run other scripts, but none of them worked in pythonista. I just didn't come across runpy.

    posted in Pythonista read more
  • uj_jonas

    First of all please, excuse my bad English and code :)

    So I was browsing the forums, looking at all sorts of topics. I got tired of copy-pasting the scripts into a new file, every time I wanted to test a script someone wrote. So I (of course) thought it'd be nice if I could just run the script from the app extension, without leaving Safari.

    So I wrote this, which kinda works most of the time. (I tried to comment it as best as I could.)

    import clipboard
    import runpy
                     
    # Every line of the copied script
    cliplines = clipboard.get().split('\n')
    
    # Some scripts contain the 'if __name__ == "__main__":' statement
    # We can't have that since we need the script to run when it's imported
    try:
        cliplines[cliplines.index("if __name__ == '__main__':")] = "if __name__ != '__main__':"
    except ValueError:
        pass
    
        
    # @Phuket2 keeps importing editor without using it
    # Since editor is not supported in the app extension...
    # We try to remove it and see if it still works
    for i in range(len(cliplines)):
        cliplines[i] = (cliplines[i].replace('import editor', '').replace(', editor', '') + '\n').encode()
    
    # Writing the new script to the .py file
    with open('TheScript.py', 'wb') as f:
        f.writelines(cliplines)
    
    # Run the script
    runpy.run_path('TheScript.py')
    

    It works by writing the text in your clipboard to a .py file and then running it.

    I would appreciate I someone helped improve it

    (Here's some random code to test it on)

    from math import pi
    from ui import View, TextView
    
    
    # Just a pointless function
    def changeText(sender, text):
        sender.text = text
    
    v = View()
    v.bg_color = 'white'
    v.frame = (0, 0, 400, 100)
    
    l = TextView()
    l.alignment = 1
    l.editable = False
    l.frame = (0, 0, len(str(pi)) * 20, 96)
    l.font = ('CourierNewPSMT', 32)
    
    changeText(l, 'Pi\n' + str(pi))
    
    if __name__ == '__main__':
        v.present('sheet')
    
    l.x = v.width/2 - l.width/2
    l.y = v.height/2 - l.height/2
    v.add_subview(l)
    

    Edit: What @omz said

    posted in Pythonista read more
  • uj_jonas

    @lukaskollmer I got it all working again, except imgurpython.
    I removed it from site-packages and tried to reinstall it with pip, but it wouldn't let me.

    posted in Pythonista read more
  • uj_jonas

    @JonB is everything in site-packages what stash has installed?
    If so, wouldn't trashing it all fix the problem?

    posted in Pythonista read more
  • uj_jonas

    @JonB future is now gone.

    All I'm doing is
    import twitter
    It doesn't work in 3.5
    It works in 2.7

    From the console(2.7):

    >>> import twitter
    >>> twitter.__file__
    '/var/containers/Bundle/Application/05B93F09-B103-44A6-9622-55237A53AC5E/Pythonista3.app/Frameworks/PythonistaKit.framework/pylib/site-packages/twitter.py'
    

    posted in Pythonista read more
  • uj_jonas

    @JonB didn't quite work.
    I did remove the twitter folder, but now it's just back to the first error.
    And I'm still wondering why this affects other modules. The ImportError says I'm either running Python-future from the src folder or it's corrupted, it think it's corrupted

    posted in Pythonista read more
  • uj_jonas

    @ccc and now it raised a new error
    module "copyreq" has no attribute "pickle"

    Damn I wish there was a undo button in stash

    posted in Pythonista read more
  • uj_jonas

    But why does this affect other modules?

    posted in Pythonista read more
  • uj_jonas

    Yes, I thought it was something like that :/

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!