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.


    How to implement long button presses?

    Pythonista
    2
    2
    365
    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.
    • throwaway4
      throwaway4 last edited by

      I'm trying to implement a long button press and record the elapsed time. Similar to how you can implement the touch_began and touch_ended methods for a ui.View, is it possible to do this for buttons?
      I noticed that if I create a view with a button that is touch-enabled, I can tap the screen to record a touch for any location EXCEPT the button.

      Is there a simple way to do the same with buttons?

      My code so far:

      from datetime import datetime as dt
      import ui
      
      class Touch_Test(ui.View):
         def __init__(self):
            self.background_color = 'white'
            self.button = ui.Button(title='Button', frame=(100,100,100,30), action=self.get_touch)
            self.add_subview(self.button)
            self.present('fullscreen')
         
         def touch_began(self, touch):
            self.press_time = dt.now()
            print('Pressed {}'.format(touch.location))
      
         def touch_ended(self, touch):
            self.press_time_elapsed = dt.now() - self.press_time
            print('Time Elapsed: {}'.format(self.press_time_elapsed))
      
         def get_touch(self, sender):
            print('Pressed Button {}'.format(sender)
      
      if __name__ == '__main__':
         t = Touch_Test()
      
      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @throwaway4 last edited by

        @throwaway4 see gestures of @mikael

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