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.


    Cyclic animations

    Pythonista
    3
    4
    3072
    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.
    • polymerchm
      polymerchm last edited by

      I'd like to build an interface like that in pythonista's UI builder to allow modification of the "flex" attribute. It will be a custom view, like my chordcalc interfaces for the "arrows". More, specifically, I want the same sort of visual queue as @OMZ has included (morphing from before shape/position to after and back again) as you change the settings.

      I guess use ui.animate() along with a ui.delay() to fire a set_needs_display() timed to come after the animation time. Other thoughts before I waste a lot of time going over well trodden paths are appreciated.

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

        animate has a completion argument, which gets called when the animation completes.
        This lets you string together animations. In that way, you don't need to call delay or set_needs_display.

        Here's an example updated from an old thread (before I knew about completion).

        import time
        import ui, console
        
        root=ui.View(frame=(0,0,500,500))
        somecontainer=ui.View(frame=(50,5,200,200),bg_color=(1,0,0))
        root.add_subview(somecontainer)
        b=ui.Button(bg_color=(0,1,0),frame=(50,50,100,100))
        somecontainer.add_subview(b)
        b.action=lambda sender:console.hud_alert('yes, i am a button')
        
        
        def demo(flex):
            #show the flex mode of b by resizing its parent view, first big, then small.
            b.flex=flex
            b.title="b.flex='{}'".format(b.flex)
            duration=1.0 #animation speed 
            def small():
                somecontainer.frame=(50,50,200,200)
            def big():
                somecontainer.frame=(50,50,400,400)
            def animation_small():
                #completion could call animation_big again, as long as you have a stopping condition!
                ui.animate(small, duration=duration)
            def animation_big():
                #animate to big size, then call animation_small
                ui.animate(big, duration=duration,completion=animation_small)
            animation_big()
        
        
        root.present('sheet')
        for x in ['','lrtb','l','t','w','h','wh','wl','ht']:
            demo(x)
            time.sleep(3.0)
        
        1 Reply Last reply Reply Quote 0
        • polymerchm
          polymerchm last edited by

          Marvelous. Where do you find these things!!? Are you secretly plying OMZ with Red Bull?

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

            Yes, this is cool. Just watching the animation if you are a newbie like me can really help get flex in your head. Ok, there is an animation in the ui designer, but this sends the message home somehow. Also can see the code of course. Thanks

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