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.


    WKWebView: how to know add_style is finished?

    Pythonista
    3
    8
    2459
    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.
    • cvp
      cvp last edited by

      @mikael I use your WKWebView module (thanks for this marvelous piece of code, as usual) to display an ePub book. In an ePub, each chapter is an html file.
      To perform aA-like process to change font-size, I use

      wv.add_style('body { column-width:' + w + 'px; min-width:' + w + 'px; column-gap: 9%; height:' + h + 'px; margin-left: 4% ; margin-right: 4% ; margin-top: 4%; margin-bottom: 4%;}')
      

      To know the number of pages of the chapter with this font-size, I need to compute webview.content_size.width divided by webview frame.width.

      But I have to be sure that the JavaScript executed by add_style is finished.

      My question is: how to be sure it is finished?

      Actually, I loop until webview.content_size.width does not change any more but that is not really professional 😀

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

        Can you check window.ready?

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

          I mean document.readyState...

          cvp 3 Replies Last reply Reply Quote 0
          • cvp
            cvp @JonB last edited by

            @JonB Thanks for the advice, I'll check tomorrow, already late for me.

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

              @JonB But if I understand, this is not a wait, it is also a check to insert in a while loop and sleep in the loop?

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

                @JonB I'be just tested. It is not ok, the state is ready but the load of the html (and its split in multi-columns) is not yet finished

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

                  @cvp, checked the docs. The method used to insert the script, addUserScript, is not documented as sync or async, and provides no additional parameters like completion callback. add_style adds the script to the end of the document, as (I seem to recall that) adding to the beginning did not really work for styles.

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

                    @mikael Ok, Thanks for the check. It is not so important as I can check each 0.1 second if the content_size width has changed. On my iPad mini 4, it takes 0.1 second for a chapter of 5 pages but 2 seconds for a chapter of 30 pages..
                    This automatic multi-columns functionality is really nice to have book-like pages

                    I think iBooks app performs something like that because if you change the font size, it takes some time before to show the total number of pages...

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