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 easily view .pyui file as a text file

    Pythonista
    5
    9
    5281
    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.
    • ltddev
      ltddev last edited by

      I may have forgot but I checked through the forum posts and I don't see an answer to the following: What is the suggested way to view a .pyui file (without changing the default ui editor)as plain text rather than use the ui editor?

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

        Just rename the file to "something.json" or "something.txt".

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

          @omz, thanks, I thought of that workaround as well but wondered if there was anything a little more elegant such as "Open with" to choose the editor to use rather than try to trick it that the .pyui file is either a text file outright or one to be treated as a text file.

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

            @ltddev There isn't really another way, sorry.

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

              Very quick and dirty, a little script you have to define in the share sheet, and thus you can "edit and open with" a .pyui file (or, sorry if I didn't understand your request):

              import appex,ui
              f = appex.get_file_path()
              fil = open(f,'r',encoding='utf-8')
              t = ''
              for rec in fil:
              	t = t + rec
              fil.close()
              cover_image = ui.TextView()
              cover_image.text = t
              cover_image.present()
              
              1 Reply Last reply Reply Quote 1
              • ccc
                ccc last edited by

                Nice one @cvp

                import appex
                import ui
                filename = appex.get_file_path()
                assert filename, 'This appex script must be run from a share sheet.'
                with open(filename) as in_file:
                    text = in_file.read()
                ui.TextView(name=filename.split('/')[-1], text=text).present()
                
                cvp 1 Reply Last reply Reply Quote 0
                • omz
                  omz last edited by

                  @cvp Neat idea! Didn't think of that possibility (though I think renaming might be faster).

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

                    @ccc Instead of filename.split('/')[-1] you can use os.path.basename(filename).

                    1 Reply Last reply Reply Quote 1
                    • cvp
                      cvp @ccc last edited by

                      @ccc I initially splitted into records because my 1st intent was to use a TableView. As I said, it was a really dirty script 😏

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