omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    How to use script rolling the page down when using WebView

    Pythonista
    3
    10
    3600
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • louxingliang
      louxingliang last edited by

      Hi, I've read the document of WebView on this website, but still I haven't find the method to do this.
      If I open a website which is very long, how to use script to roll down the page ..?

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @louxingliang last edited by cvp

        @louxingliang very quick and dirty code

        import ui
        from objc_util import *
        w = ui.WebView()
        wo = ObjCInstance(w)
        sv = wo.subviews()[0].scrollView()
        w.load_url('http://omz-software.com/pythonista/')
        w.frame = (00,0,300,300)
        bu = ui.ButtonItem()
        bu.title = 'up'
        w.top = 0
        def scroll_up(sender):
        	w.top = w.top - 300
        	if w.top < 0:
        		w_top = 0
        	sv.setContentOffset_(CGPoint(0,w.top))
        bu.action = scroll_up
        bd = ui.ButtonItem()
        bd.title = 'down'
        def scroll_down(sender):
        	w.top = w.top + 300
        	sv.setContentOffset_(CGPoint(0,w.top))
        bd.action = scroll_down
        w.right_button_items = (bd,bu)
        w.present('sheet')
        

        Edit: little bug, was w_to = 0, sorry

        1 Reply Last reply Reply Quote 0
        • louxingliang
          louxingliang last edited by

          Thanks again! Ready to try it.
          You are really familiar with the python lib !

          cvp 2 Replies Last reply Reply Quote 0
          • cvp
            cvp @louxingliang last edited by cvp

            @louxingliang Not at all, but a very quick search with Google "Pythonista webview scroll" gives 😂

            1 Reply Last reply Reply Quote 0
            • cvp
              cvp @louxingliang last edited by

              @louxingliang and now without Objective-C by setting the webview as sub view of a scrollview

              import ui
              sv = ui.ScrollView()
              w = ui.WebView()
              w.load_url('http://omz-software.com/pythonista/')
              sv.frame = (00,0,300,300)
              w.frame = sv.frame
              sv.add_subview(w)
              bu = ui.ButtonItem()
              bu.title = 'up'
              w.top = 0
              def scroll_up(sender):
              	w.top = w.top - sv.height
              	if w.top < 0:
              		w_top = 0
              	w_height = w.height - sv.height
              	if w_height >= sv.height:
              		w.height = w_height
              		sv.content_size = (sv.width,w.height)
              		sv.content_offset =  (0,w.top)
              bu.action = scroll_up
              bd = ui.ButtonItem()
              bd.title = 'down'
              def scroll_down(sender):
              	w.top = w.top + sv.height
              	w.height = w.height + sv.height
              	sv.content_size = (sv.width,w.height)
              	sv.content_offset =  (0,w.top)
              bd.action = scroll_down
              sv.right_button_items = (bd,bu)
              sv.present('sheet')
              
              louxingliang 1 Reply Last reply Reply Quote 0
              • louxingliang
                louxingliang @cvp last edited by

                @cvp recently I met a new problem.
                I can not open the website with user-agent request head when using load_url.
                I tried this way, but it doesn’t work
                headers={
                'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4882.400 QQBrowser/9.7.13059.400'}
                w.loadRequest(url,request)

                Is there any way to solve this problem?

                cvp mikael 2 Replies Last reply Reply Quote 0
                • cvp
                  cvp @louxingliang last edited by

                  @louxingliang Oups, I Really can't help you, I'm not a specialist of web browser.
                  But I'm sure that this marvelous forum will provide somebody who will help you successfully

                  1 Reply Last reply Reply Quote 0
                  • mikael
                    mikael @louxingliang last edited by

                    @louxingliang, WKWebKit has a user_agent property that you can set before loading, see here.

                    1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp last edited by

                      I forgot that. Thanks for helping

                      1 Reply Last reply Reply Quote 0
                      • mikael
                        mikael last edited by

                        For completeness sake, one more way to scroll would be a Javascript one-liner, let me know if that would relevant for you.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors