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.


    Xcode + UI File Loading (POSSIBLE BUG IN PYTHONISTA)

    Pythonista
    5
    25
    15398
    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.
    • techteej
      techteej last edited by

      I'm having a weird issue, Im using v = ui.load_view('../PythonistaProject.app/Script.pyui') to load my UI File in Xcode. It works fine inside of Xcode and on the simulator, but when I put the App on My iPad (using TestFlight) it says it couldn't load the UI File

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

        Why not use the same method to identify the pyui location from the other thread?

        def findpyui():
            import os
            startingpath = os.path.expanduser('~')    
            # other things to try....
            #startingpath = '.'  
            #starting path = '..'  # i.e in pythonista, start above documents, to see into library,etc
            print startingpath
            for root, dirs, files in os.walk(startingpath):
                for name in files:
                    if name.endswith('pyui'):
                        print os.path.join(os.path.abspath(root),name)
        findpyui()
        
        1 Reply Last reply Reply Quote 0
        • techteej
          techteej last edited by

          This brings up the .pyui files in my project, exactly as I have them..Really confusing

          This had worked for me in another project, don't know why it isn't working now.

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

            Still does not work with the updated paths.

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

              I really need some help with this. I tried using all the file paths from the findpyui script and it still gives me the UI File Could Not Be Loaded.

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

                @techteej, I can't really try it out right now (Mac updating), but you could make something like this:

                ...
                ui_file = """
                {...}
                """
                # I am not very good with tempfile, but I think that's how it works
                import tempfile
                
                with tempfile.NamedTemporaryFile() as fp:
                    fp.write(ui_file)
                
                view = ui.load_view(fp.name)
                ...
                
                1 Reply Last reply Reply Quote 0
                • techteej
                  techteej last edited by

                  This still brings up the error.

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

                    @techteej, well, then I have no ideas... Maybe you can try to write a small script that will convert .pyui to Python code? Shouldn't be that hard I think.

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

                      @techteej, or maybe try this one:

                      ...
                      ui_file = """
                      {...}
                      """
                      import os
                      
                      full_path = os.path.join(os.getcwd(), "uifile.pyui")
                      with open(full_path, "w") as fp:
                          fp.write(ui_file)
                      
                      view = ui.load_view(full_path)
                      ...
                      
                      1 Reply Last reply Reply Quote 0
                      • techteej
                        techteej last edited by

                        This gives me the error invalid UI File.

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

                          Have you tried going back to basics and stripping everything out of your project, and having the simplest of ui, like a single button? Can you find a minimal example of a pyui and py file that so fails, yet works in pythonista?

                          Seems like that is the route you need to get help on this. If you can post a repeatable example, then omz or others may be able to help. You said this worked previously, so you need to figure out what changed, it is either your code, pyui file, or something in your particular project setup....

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

                            @techteej, okay, I am outta ideas... Ask omz, maybe it is some kind of bug in Pythonista or ui module?

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

                              @JonB Yep. :\

                              @ShadowSlayer Already tried this, only get no response. :(

                              Definitely quite frustrating!

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

                                Tech, what I mean is that you need to post reproducible code, not vague descriptions.
                                See if others can reproduce it, or not. Given that you, and others, have been able to make Xcode projects that load ui's, it sounds more like a problem with your configuration.

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

                                  @JonB See Cacti Killer on GitHub. This is what I'm having problems with.

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

                                    Any chance you're using the iOS 8 beta? The file system structure for apps and their data containers has changed there...

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

                                      Based on previous posts, I believe that he is running iOS 8 beta... Are there any workarounds for iOS 8 users?

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

                                        Okay, this isn't pretty, but it should work on both iOS 7 and 8:

                                        import scene
                                        import os
                                        
                                        def find_bundled_files(file_extension='.pyui', exclude_dirs=('pylib', 'pylib_ext', 'Documentation', 'Textures')):
                                        	found = []
                                        	# Use a built-in image's path as a starting point (use a different one if you've removed this from your project):
                                        	dummy_img_path = scene.get_image_path('Test_Lenna')
                                        	bundle_path = os.path.split(os.path.split(dummy_img_path)[0])[0]
                                        	for path, dirs, files in os.walk(bundle_path):
                                        		# Remove excluded directory names from the search (not required, but makes it faster):
                                        		for excluded in exclude_dirs:
                                        			try:
                                        				dirs.remove(excluded)
                                        			except:
                                        				pass
                                        		for filename in files:
                                        			ext = os.path.splitext(filename)[1]
                                        			if ext == file_extension:
                                        				full_path = os.path.join(path, filename)
                                        				found.append(full_path)
                                        	return found
                                        
                                        ui_files = find_bundled_files()
                                        print ui_files
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • techteej
                                          techteej last edited by

                                          @omz Thanks. I am using the iOS 8 beta, I'll try from a fresh download of the Project Template w/ this.

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

                                            @omz How would I load this?

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