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.


    List of all built-in graphics via Python?

    Pythonista
    5
    7
    6782
    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.
    • Bortels
      Bortels last edited by

      I know I can hit "+" to get a drop down with the built-in images and sounds - but is there some built-in way to enumerate that list without me manually transcribing them? Ideally a built-in, but even a gist with the lists would be cool. (I want to present them in a menu for the user to choose).

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

        There was a file browser script I downloaded somewhere from here that lets you brows all files related to Pythonista, including the images. I was playing with it last night.

        Edit: Found it

        https://github.com/dgelessus/pythonista-scripts/blob/master/filenav.py

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

          Obscure oneliner incoming:

          import os
          
          builtin_images = [name for name in os.listdir(os.path.join(os.path.dirname(os.__file__), "../Textures")) if "@2x" not in name]
          

          All "built-in" images are stored in the Textures folder inside the Pythonista.app bundle. Due to recent changes in iOS 8 it is no longer possible to easily access that location, so we join the path of the os module source (which we need imported anyway) with a relative path to get the path to the Textures folder. Then we os.listdir the folder and use a list comprehension to remove any "retina" versions of already listed images from the list.

          As for sounds, those are stored in the root of the Pythonista.app. I think they are all in CAF format, so it would probably be possible to os.listdir the Pythonista.app folder and filter out everything that does not end with .caf.

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

            @TutorialDoctor, soon (when 1.6 is released) that will no longer be possible. The Pythonista.app bundle has been further "sandboxed away" from the Documents folder in iOS 8, but that change won't become obvious until the app is updated for iOS 8. (I know already, because I have access to the beta version of 1.6.) Maybe I'll add a few convenient buttons on the filenav window to change between the ~ and Pythonista.app folders.

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

              @dgelessus - awesome, exactly what I was looking for; explanation plus why I was having issues (I was only seeing my own stuff using regular old os.walk - now I know why).

              @TutorialDoctor - thank you as well, that looks like a handy utility, and it's useful to look at working code, even if Apple is a bit of a moving target!

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

                My trick is to download the xCode snapshot then use the UNIX find command to look for the builtin files. I have the snapshot anyway because I want to build apps I can run in parallel with Pythionista.

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

                  Heh, would be overkill for me - I was showing my daughters how if you write the code, you can modify the game to make it what you want, and suggested they could, for example, change the pictures in the "Cards.py" sample.

                  FWIW - I replaced the "images =" line with:

                  	# pick random images
                  	builtin_images = [name for name in os.listdir(os.path.join(os.path.dirname(os.__file__), "../Textures")) if "@2x" not in name]
                  	images = random.sample(builtin_images, 8)
                  	images = [os.path.splitext(x)[0] for x in images]
                  	images = images * 2
                  

                  And added "random" and "os" to the imports, and there was much rejoicing. :-)

                  (I'm not sure os.path.splitext was the best choice, but MEH it works)

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