omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. throwaway4

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Best 0
    • Controversial 0
    • Groups 0

    throwaway4

    @throwaway4

    0
    Reputation
    259
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    throwaway4 Unfollow Follow

    Latest posts made by throwaway4

    • How to implement long button presses?

      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()
      
      posted in Pythonista
      throwaway4
      throwaway4