omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    21
    2651
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp @osamu last edited by

      @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

      1 Reply Last reply Reply Quote 0
      • cvp
        cvp @osamu last edited by cvp

        @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')
        
        osamu 1 Reply Last reply Reply Quote 0
        • osamu
          osamu @cvp last edited by

          @cvp said:

          objc.setMaximumDate_(nsDate)

          Thank you, I’m interested in the above attribute.

          1 Reply Last reply Reply Quote 0
          • osamu
            osamu @cvp last edited by

            @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.

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @osamu last edited by

              @osamu my error

              from   objc_util import *
              
              osamu 1 Reply Last reply Reply Quote 0
              • osamu
                osamu @cvp last edited by

                @cvp I got it. Thank you.

                1 Reply Last reply Reply Quote 0
                • osamu
                  osamu @cvp last edited by

                  @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?

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by

                    Have you tried reversing the list?

                    osamu 1 Reply Last reply Reply Quote 0
                    • osamu
                      osamu @JonB last edited by

                      @JonB That’s a good idea 👍

                      1 Reply Last reply Reply Quote 0
                      • osamu
                        osamu @cvp last edited by ccc

                        @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.

                        cvp 1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @osamu last edited by cvp

                          @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

                          osamu 1 Reply Last reply Reply Quote 0
                          • osamu
                            osamu @cvp last edited by

                            @cvp Yes, it works. Thanks!

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Powered by NodeBB Forums | Contributors