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
-
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? -
I was able to get the following to work:
- Copy the workflow
Save to Python...
- Create a new workflow from the clipboard
- Edit the Python code in that workflow to change
both
instances of ".py" to ".pyui" - Save the workflow as "Save to Pyui..."
- Copy the text of a Pythonista .pyui file
- Paste that text into the Editorial editor
- 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())
- Copy the workflow
-
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?
-
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 putmy_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()))
-
Okay.
As I already have a pyui file - is there a way to convert a pyui into python commands? -
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 -
Thanks for your help.
I finally copied the text from the pyui file and create a __temp.pyui.