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.
Beginner Custom UI, how to get the python script?
-
"Behind the scenes, the controls of a Custom UI action correspond to Python objects from the ui module, so you can mix and match Python code with workflow-based UIs. When you have a custom UI and you want to get at the underlying view objects, you can do this with the workflow.get_view() method. This returns the root view of the currently-running Custom UI action, and you can use this to traverse the view hierarchy and make changes that wouldn’t be possible with workflow actions alone."
Got that... how do I get to the underlying script to play around with it?
import editor import console import os import workflow import ui view = workflow.get_view()``` #I tried print but I couldn't get that to give me anything but numbers... obviously not editable.
-
@ccc is this complicated to do? (Get the script behind the custom ui in editorial, as it says in documentation that I can theoretically do with workflow.get_view)
-
Custom UIs are not Python scripts - they are JSON data structures, and they contain everything that you can see and edit in the UI editor, but in a much less readable text form. There's not much use in reading or modifying the custom UIs in raw JSON form, and I'm not sure how hard it is to get that data out of a workflow. (In Pythonista, custom UIs are separate files, so you can just change the extension to see them in text form.)
If you want to modify the UI from the Python script, you can use
workflow.get_view()
to get the root view object, as you already found out. To see what exactly you can do with a view object, have a look at theui
module documentation, under "Scripting Editorial with Python" in the docs.View objects don't have a useful text form when you
print
them out. Instead you get the default text representation for Python objects, which only shows the type name and the memory address, which isn't always very useful. (The text form of view objects could be made more descriptive, but there's no way you could make a readable text form of a view that describes every aspect exactly.) -
@dgelessus thanks for the reply. This seems like it might be way over my head.
I have tried to look through all of that, before posting the question... But I don't know what to do with any of it... (The ui documentation, or even where to put it to have it work with the workflow custom ui)
I want to ask for an example, but I think I'm so python ignorant that it might not help. 😑
-
@NikkiSchwartzVB what are you trying to achieve? Do you need to change a ui to fit your data or what?
-
Initially, I was trying to use a text view box to get input out as a list. I needed two columns side by side. I wanted to use two text view boxes to in put a list of client's past diagnoses on one side and part treatments for each diagnosis on the other. I don't know how many each client will have, so I wanted to be able to vary it...
But... I can't seem to get text view to produce output to variables at all. Each time I've tried, I eventually ended up solving the problem a different way.
This time I set up 5x2 set of text fields instead and put that all into a markdown table. I'm going to find a way to rerun the workflow if I need additional lines, but I'll tackle that later.
(Side note... Can I make a markdown table have borders once I export it to pdf? It shows light grey borders in preview, but nothing in pdf)
-
http://www.editorial-workflows.com/workflow/5842935182524416/hz6uDvq6gGs
In the Add To List workflow, the following script is attached to textfield1. When you hit return in textfield1, it transfers the text from textfield1 to the end of tableview1 and then blanks out textfield1.
#coding: utf-8 import workflow user_text = workflow.get_input() view = workflow.get_view() ds = view['tableview1'].data_source ds.items = [x for x in ds.items if x] if user_text: ds.items += user_text view['textfield1'].text = '' workflow.set_variable('diags', '\n'.join(ds.items))
-
Thanks! That's beautiful!
-
This post is deleted! -
This post is deleted!