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.


    Load Image from URL

    Pythonista
    2
    12
    7989
    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.
    • p_atrick
      p_atrick last edited by

      I am making a dumb little program to learn how to use Pythonista. I am trying to something that changes the text/image when you tap the forward or back buttons. I cannot get the image to view. Does anybody see what I am doing wrong? Thanks.

      import ui
      
      page_count = 1
      
      # text for each page
      page1_text = 'This app introduces the game of baseball.\nUse the navigtion arrows to change pages.'
      page2_text = 'Page 2'
      page3_text = 'Page 3'
      
      # images for each page
      page1_img = 'http://www.talmageboston.com/files/2016/04/Baseball-Grass.jpg'
      
      def update_page(page_text, page_img):
      	if page_count == 1:
      		page_text.text = page1_text
      		page_img.load_from_url(page1_img)
      	
      v = ui.load_view()
      page_text = v['textview1']
      page_img = v['imageview1']
      v.present('sheet')
      
      while True:
      	update_page(page_text, page_img)
      
      1 Reply Last reply Reply Quote 0
      • cvp
        cvp last edited by cvp

        Load_view assumes you have created an UI file with your ui.view but you need to define the path/file name of your file in load_view(file).

        Example: you have a file test.pyui, thus load_view('test')

        And If you comment/remove the "while true" line, you'll see your picture.

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

          The documentation said that by leaving it blank it will default to the same file name but with 'pyui'. The UI portion will load, and the text appears. However, the imageview is blank. I just took what worked with the text (page_text = v['textview1']) and tried it for the image. I assume the problem is there, but I am not sure what it is.

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

            You're right for the default name.
            I've tried without the "while true" and the picture is displayed

            The load_view is asynchronous and you infinite loop doesn't let enough time for loading the URL.

            Why do you put this while loop?

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

              Not sure. I commented out the line, but it still does not load for me.

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

                Strange, for me, it's ok
                Did you move the next line left?

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

                  Does the textview object not hide the imageview object?

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

                    see

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

                      Here is the UI file looks like:
                      UI
                      The imageview is above the textview.

                      Here is what my output looks like:
                      output

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

                        I just got the same problem, picture does not appear any more.
                        Remove Pythonista app from tasks list (4/5 fingers up, slide app up) and restart Pythonista

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

                          It works, thanks. Do you know why I needed to restart the app?

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

                            No, sorry but @omz is watching you 😅
                            You'll receive an explanation.
                            Perhaps, the site where you get your picture does not respond immediately if you make too much requests from an app, I have had this kind of problems on Google site.

                            In reality, when your picture is not displayed, the script seems locked because even the close button does not response.

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