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.
Pre-populate custom UI datepicker with selected date/time
-
Does anyone no how to pre-poplutate the datepicker UI with a provided date/time when the UI pops up. It defaults to today, but I want to provide a selected date to edit from. I can see how to do this from a python script but was looking for an easy way to set the date using the Custom UI workflow action. Workflow would be following:
- Select date/time in file
- If date/time selected, parse into appropriate format, else default to today
- Custom UI datepicker would pop up with selected date ready for editing
- Output new date for updating file
/ryan
-
It's currently not possible to do this without any Python. You can use Python in a Custom UI action though, e.g. something like:
import workflow view = workflow.get_view() datepicker = view['datepicker1'] datepicker.date = ...
-
That's what I was looking for, thanks! I didn't want to do the whole ui in Python, just inject some data like you suggested. I wasn't aware I could do this actions in the custom UI.
-
I guess I spoke too soon. I tried adding the following action in the datepicker as a run Python script but it does nothing.
import workflow from datetime import datetime input = workflow.get_variable('date') dt = datetime.strptime(input, '%Y-%m-%d') view = workflow.get_view() datepicker = view['datepicker1'] datepicker.date = dt
I have run the first part of the code in a python script at the workflow level to verify the datetime object is being created correctly and it appears to be.
Am I missing something?
-
Wehre exactly did you add the script? Is it run at all?
-
I added it as an action within the custom UI (attached to the datepicker object). Thought that was what you meant.?
It doesn't seem to run at all.
This Change Date workflow does what I want for populating the selected date but I couldn't figure out how it was doing it anywhere in the workflow. My workflow is different but this piece is what I need.
-
@ryanlaner I think you should add this to the action of the main view. When you select nothing in the UI editor, the embedded workflow editor is for "view appeared". An action added to a date picker would run when the date picker changes (by user action), and setting a different date from there probably doesn't work and isn't what you want anyway.
-
That was it. Thanks!