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.
Date Picker w/ blank year
-
@cvp Thank you very much indeed for spending time 🙏
This picker is the one that shows up when you enter birthday and other dates when using contacts app. I’m going to try your code. -
@osamu In this case, the ---- can't be selected but only shows a maximum date.
I think that we can also set this maximum date without all the code I wrote -
@osamu try this little script. You will not see the wanted "----" but after the now-date, day/month/years are grayed and not selectable with automatic return to today picker. I'm sure I'm not clear, thus try it.
import ui v = ui.View() v.name = 'for @osamu' v.frame = (0,0,300,150) d = ui.DatePicker() d.frame = v.frame d.mode = ui.DATE_PICKER_MODE_DATE v.add_subview(d) objc = ObjCInstance(d) nsDate = ObjCClass('NSDate').alloc().init() # initialized with now-date #print(dir(nsDate)) objc.setMaximumDate_(nsDate) v.present('sheet')
-
-
@cvp I tried the first version but Pythonista claimed create_objc_class() is missing. There may be some more. I guess I need to sneak into your library and steal them.
-
@osamu my error
from objc_util import *
-
@cvp I got it. Thank you.
-
@cvp This script initializes the year as 2019. If I set;
years = [str(y) for y in range(1605,datetime.now().year+1)] + ['----']
the initial year is set to 1605 and we’re far away from —— and recent years. Can we control this initial value? -
Have you tried reversing the list?
-
@JonB That’s a good idea 👍
-
@cvp one last question.
Can I set the initial year?
The following does not work.class MyUIPickerView(ui.View): def __init__(self, data, horiz=False,myRowHeight=100, myDidSelectRow=None, **kwargs): super().__init__(**kwargs) UIPickerView = ObjCClass('UIPickerView') self._picker_view = UIPickerView.alloc().initWithFrame_(ObjCInstance(self).bounds()).autorelease() ObjCInstance(self).addSubview_(self._picker_view) ... self._picker_view.selectedRow = XXX
Thanks in advance.
-
@osamu selectedRow is not an attribute of UIPickerView but is an user attribute set in the pickerView_didSelectRow_inComponent_ delegate, thus you can't set it.
I think we would need to use kind of
. . . self._picker_view.horiz = horiz xxx = 1 self._picker_view.selectRow_inComponent_animated_(xxx,0,True)
Tested, ok
-
@cvp Yes, it works. Thanks!