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.


    Use scene and ui in the same program

    Pythonista
    3
    16
    8619
    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.
    • pythonista21
      pythonista21 last edited by

      The date picker appeared first, it is much better. But the problem is that I did my calculations with years and not with months and days, that's why the date that is given by the date picker can't be used in my program I think, because it can't be converted into years. Do you think that I could only ask the user a year and remove the months and days ?

      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @pythonista21 last edited by

        @pythonista21 not very nice but I'm not an expert 😢

        import ui
        d = ui.DatePicker()
        d.name = 'Select a year'
        d.mode = ui.DATE_PICKER_MODE_DATE
        def date_action(sender):
        	print(str(sender.date)[:4])
        d.action = date_action
        l = ui.Button()
        l.frame = (0,0,d.width*2/3,d.height)
        l.background_color = 'white'
        d.background_color = 'white'
        d.add_subview(l)
        d.present('sheet')
        d.wait_modal()
        
        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @pythonista21 last edited by

          @pythonista21 or

          import ui
          d = ui.DatePicker()
          d.mode = ui.DATE_PICKER_MODE_DATE
          def date_action(sender):
          	print(str(sender.date)[:4])
          	sender.close()
          d.action = date_action
          l = ui.Button()
          l.title = 'Select year'
          l.font = ('<System-Bold>',32)
          l.frame = (0,0,d.width*2/3,d.height)
          l.background_color = 'white'
          d.background_color = 'white'
          d.add_subview(l)
          d.present('sheet',hide_title_bar=True)
          d.wait_modal()
          
          1 Reply Last reply Reply Quote 0
          • pythonista21
            pythonista21 last edited by

            It is perfect, I can now choose a year. But there is a last problem, when I use "d" as my date in the program, pythonista tells me that there is an error. Am I not allowed to use d in the program? Is there something else I need to add?

            cvp Phuket2 2 Replies Last reply Reply Quote 0
            • cvp
              cvp @pythonista21 last edited by cvp

              @pythonista21 it's because my short code also uses d as a variable, use something else like dpicker for example.
              d here is an ui object, if you want the year it is str(d.date)[:4]

              Put after the wait_modal

              sel_year = str(d.date)[:4]
              

              And use sel_year as date variable

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

                I added this line and replaced all the "d" by "sel_year" in the program but it remains the same. The error is: "can't multiply sequence by non-int of type 'float' " when I try to multiply sel_year. Pythonista still doesn't consider sel_year as a variable. I can't use it as a number and multiply or divide it. I don't understand where the problem comes from 😓

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

                  @pythonista21 use int instead of str if your code needs a number. As I don't know your entire code, it was not possible to know how you used this year

                  sel_year = int(str(d.date)[:4])
                  
                  1 Reply Last reply Reply Quote 0
                  • pythonista21
                    pythonista21 last edited by

                    It works! Thanks a lot for your precious help!!

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

                      @pythonista21

                      1 Reply Last reply Reply Quote 0
                      • Phuket2
                        Phuket2 @pythonista21 last edited by

                        @pythonista21 , date has a day, month and year property you can access. So date.year, is an int.

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

                          @cvp I have one last problem that I discovered, when I wanted to chose the year 2018.
                          If I want to select a date I need to move my finger until I reach the date that I want. As soon as I'm removing my finger from the screen, the year that I selected is saved in the code and the solar system appears.
                          I can't choose 2018 because when I start the program, I'm directly on 2018 and even if I move to an other year and come back to 2018 nothing happens when I stay on 2018.
                          Is there a possibility to add an "OK" button that I can press when I choose the year that I wanted?

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

                            @pythonista21

                            import ui
                            d = ui.DatePicker()
                            d.mode = ui.DATE_PICKER_MODE_DATE
                            l = ui.Button()
                            l.title = '☀️'
                            l.font = ('<System-Bold>',128)
                            l.frame = (0,0,d.width*2/3,d.height)
                            l.background_color = 'white'
                            d.background_color = 'white'
                            d.add_subview(l)
                            ok = ui.ButtonItem()
                            ok.title = 'ok'
                            def ok_action(sender):
                            	d.close()
                            ok.action = ok_action
                            d.right_button_items = [ok]
                            d.name = 'Select year'
                            d.present('sheet')
                            d.wait_modal()
                            sel_year = d.date.year
                            print(sel_year)
                            
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Powered by NodeBB Forums | Contributors