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.


    Import Pythonista files in Editorial workflow

    Editorial
    2
    7
    4539
    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.
    • charmaex
      charmaex last edited by

      Is there a way to import a Pythonista file into Editorial? A simple py file is easy but I want to import a py file with a pyui.
      Is there a way?

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

        I was able to get the following to work:

        1. Copy the workflow Save to Python...
        2. Create a new workflow from the clipboard
        3. Edit the Python code in that workflow to change both instances of ".py" to ".pyui"
        4. Save the workflow as "Save to Pyui..."
        5. Copy the text of a Pythonista .pyui file
        6. Paste that text into the Editorial editor
        7. Run the "Save to Pyui..." workflow

        Step 5 is easier in the Pythonista v1.6 beta (just rename the file from x.pyui to x.json) but you should be able to the following in all versions of Pythonista.

        with open('x.pyui') as in_file:
            print(in_file.read())
        
        1 Reply Last reply Reply Quote 0
        • charmaex
          charmaex last edited by

          Thank you for the help.

          I think I haven't explained it well.

          I have a python script with ui which I would like to run as an Editorial workflow.

          As far as I understand your solution it is to get a pyui file saved in Editorial?

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

            If you are building your user interface at runtime with Python commands (e.g. without a .pyui file) then it is much easier.

            Paste the following into an Editorial "Run Python Script":

            #coding: utf-8
            import ui, workflow
            
            action_in = workflow.get_input()
            
            #TODO: Generate the output...
            action_out = action_in
            
            def button_action(sender):
            	global action_out
            	action_out = sender.title
            	sender.close()
            
            button = ui.Button(title='Boom!')
            button.action = button_action
            button.width = 120
            button.height = 32
            button.present('sheet', hide_title_bar=True)
            button.wait_modal()
            
            workflow.set_output(action_out)
            

            Alternatively, you could use the workflow Save to Python... to put my_ui_script.py into place and then your "Run Python Script" would be:

            #coding: utf-8
            import my_ui_script, workflow
            workflow.set_output(my_ui_script.main(workflow.get_input()))
            
            1 Reply Last reply Reply Quote 0
            • charmaex
              charmaex last edited by

              Okay.
              As I already have a pyui file - is there a way to convert a pyui into python commands?

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

                If you already have a .pyui file then the first step is to do what I recommended in my first post above. This will get your .pyui file into Editorial. Then use Save to Python to move your Python file into Editorial. Finally, use the two line script above to import and run your Python file's main() function.

                Alternatively, there is a way to put a .pyui file's data into a Python variable. See: pyui_variable.py and https://omz-forums.appspot.com/pythonista/post/5254558653612032

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

                  Thanks for your help.
                  I finally copied the text from the pyui file and create a __temp.pyui.

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