Last active
August 3, 2022 12:00
-
-
Save MaddoxRauch/c7ab4df15b5f4cbfd7fad831d31e3248 to your computer and use it in GitHub Desktop.
Kivy Multi-Expression Button (on_long_press, on_single_press, on_double_press events)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Code to demonstrate the different events that can be done with the multiexpressionbutton object. | |
""" | |
from kivy.app import App | |
from kivy.uix.gridlayout import GridLayout | |
import multiexpressionbutton as meb | |
__author__ = "Mark Rauch Richards" | |
class MainWindow(GridLayout): | |
def __init__(self, **kwargs): | |
super(MainWindow, self).__init__(**kwargs) | |
self.cols = 1 | |
self.rows = 1 | |
button = meb.MultiExpressionButton(text="Click ME") | |
button.bind(on_long_press=self.long_action) | |
button.bind(on_single_press=self.single_action) | |
button.bind(on_double_press=self.double_action) | |
self.add_widget(button) | |
@staticmethod | |
def long_action(instance): | |
print('long press') | |
@staticmethod | |
def single_action(instance): | |
print('single press') | |
@staticmethod | |
def double_action(instance): | |
print('double press') | |
class Test(App): | |
def build(self): | |
self.title = 'Test' | |
main = MainWindow() | |
return main | |
if __name__ == '__main__': | |
Test().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @stgpepper. I appreciate your comments. It's been a while since I wrote this, but here's my best guess. The
self.single_hit.cancel()
method is there for theClock.schedule_once()
instance. This clock is used to determine if the press is a long press or just a single press. Without it you might end up with several clock instances running at the same time (one for every time a button is pressed) and eating up resources. You can check this by addinggc.get_count()
method to the event handler and see how many objects reside in memory as you click the button.As far as the issue with the
Scrollview
goes, I appreciate your findings and reporting it to me. Unfortunately, I believe you are correct about pull requests on Gists, as they are not actually projects, just code snippets. You are more than welcome to modify the code and make your own Gist as you see fit.