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.


    Gestures() tracking rotate+4 swipe

    Pythonista
    3
    5
    3059
    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.
    • reticulated
      reticulated last edited by

      Hi there,

      I am using the Gestures library from mikaelho (github)

      I am trying to get the gesture recogizer to work to simulate turning a dial, but i can't seem to figure out how.

      You can see my attempts including commented:

      def tempo_knob(gest_data):
        #print(dir(gest_data))
        print(gest_data.recognizer)
        #print(gest_data.rotation)
        print('yeeep')
      
      # [Gestures.UP, Gestures.DOWN, Gestures.LEFT, Gestures.RIGHT]
      Gestures().add_swipe(knob1, tempo_knob, )
      
      
      g = Gestures()
      
      #g.recognize_simultaneously = lambda gr, other_gr: gr == Gestures.SWIPE and other_gr == Gestures.ROTATE
      
      #g.add_swipe(knob1, tempo_knob, [Gestures.UP, Gestures.DOWN, Gestures.LEFT, Gestures.RIGHT])
      

      Can anyone help how I may:

      Capture both swiping in any direction (and knowing what direction it was swiped), as well as rotating.

      I was able to get rotation when it was only g.add_rotate()

      Any help would be greatly appreciated

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

        are you thinking of a two finger gesture? standard rotate is a two finger gesture.
        for a circular knob, I think you just want regular drag type gesture, where you record the delta-angle (relative to center of knob), and add that to the current rotation value.

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

          Plese find below a very straight-forward translation of my understanding of what you are after.

          #coding: utf-8
          from ui import *
          from gestures import *
          
          v = View(background_color='white')
          v.present('sheet')
          
          b = Label(background_color='grey', text_color='white', alignment= ALIGN_CENTER, center=(v.center[0], v.bounds[3]/2-v.y))
          v.add_subview(b)
          
          current_rotation = 0
          
          def rotation_handler(data):
            global current_rotation
            if data.state == Gestures.CHANGED:
              b.transform = Transform.rotation(current_rotation + data.rotation)    
            if data.state == Gestures.ENDED:
              current_rotation += data.rotation
              
          def swipe_handler_up(data):
            b.text = 'UP'
            
          def swipe_handler_right(data):
            b.text = 'RIGHT'
          
          g = Gestures()
          g.add_rotation(v, rotation_handler)
          
          g.add_swipe(v, swipe_handler_up, Gestures.UP)
          g.add_swipe(v, swipe_handler_right, Gestures.RIGHT)
          # Etc. for down, left
          
          1 Reply Last reply Reply Quote 0
          • reticulated
            reticulated last edited by

            @JonB

            You are definitely right about the standard drag gesture, in the app I am making I wanted to make it optional with that I am fully aware of the rotation gesture being two fingers.

            I am helping a friend if mine learn Python, and with that Pythonista.

            He decided to take on a difficult project for a beginner - a metronome, that being said the drag is easier to deal with as an end user but then an accidental touch may cause an unwanted change in tempo, for instance.

            I am setting up the more advanced ui elements for him as he isn't ready for it yet, and using it as an excuse to learn gestures in general, never had a need before.

            @mikael,

            Yes that is exactly what I was looking for! Thank you!

            I assume if I wanted to implement the suggestion from @JonB - which I do now, I assume I would use the pan gesture? I am assuming this since I am able to read the velocity and calculate the direction, at least I think based on the data it reports.

            Ill try to work it out on my own either way but if I am on the wrong track it may save me some time :)

            Thank you again, this example REALLY helps clarify your lib.

            mikael 1 Reply Last reply Reply Quote 0
            • mikael
              mikael @reticulated last edited by

              @reticulated, yes, pan is your friend for dragging things.

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