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.
Set date picker value
-
Is there a way to set an initial value to date picker in custom UI? I couldn't find anything in documentation.
-
It should be as easy as setting the
.date
attribute.from datetime import datetime my_date_picker.date = datetime(<year>,<month>,<day>,<hour>,<minute>,<second>)
-
DatePicker.date is the the way to go...
import datetime, ui date_picker = ui.DatePicker() date_picker.date = datetime.datetime.strptime('02/13/1970', '%m/%d/%Y') date_picker.background_color = 'white' date_picker.present()
-
Since this question is about Editorial, I think you'll need a bit more information...
Say you have a date picker in your custom UI. By default, it'll have a name of 'datepicker1' (you can see this in the inspector). You'll need this name to access it from Python code (there is currently no way to do this without a little bit of scripting).
Tap somewhere on the canvas in the UI editor to deselect everything. Then tap on the workflow icon in the toolbar to get the "startup" workflow that is run when the UI appears. Add a "Run Python Script" action, and enter something like the following code:
import workflow from datetime import datetime v = workflow.get_view() # Change this if your datepicker has a different name: datepicker = v['datepicker1'] # Set the initial date to Jan. 1, 2016 (as an example): datepicker.date = datetime(2016, 1, 1)
-
Thanks a lot! It would be nice if it could be done like with other types of UI elements.