Python Forum

Full Version: Not listen for multi clicks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have Kivy app that sometimes making some heavy stuff.
It makes the user to sometimes click/touch two/three times, but I wish to ignore this click.
Right now, the clicks "saves" and will be executed after the first click.

My goal is to ignore them. Is it possible?

example.kv
<Upload>
    name:"upload"
    BoxLayout:
        orientation: 'vertical'
        Label:
            id: nr_label
            size_hint: (1, 1)
            font_size:24
            text: "0"
        Button:
            size_hint: (1, 1)
            text: "Increase"
            on_release: root.increase()
class Upload(Screen):
    nr = 0

    def increase(self):
        self.nr += 1
        sleep(1)  # Do some heavy stuff
        self.ids.nr_label.text = str(self.nr)
If I run this example the app lock the button in one second, and after that I don't want anything to happen, even if I have click multi times on the button.
change
Quote: def increase(self):
self.nr += 1
sleep(1) # Do some heavy stuff
self.ids.nr_label.text = str(self.nr)
to

 if self.nr == 0:
        self.nr = 1
        self.ids.nr_label.text = str(self.nr)
    else: return()
You seem to be thinking that the sleep will allow something else to be going on but it won't.
(Nov-18-2021, 02:02 PM)Barrowman Wrote: [ -> ]change
Quote: def increase(self):
self.nr += 1
sleep(1) # Do some heavy stuff
self.ids.nr_label.text = str(self.nr)
to

 if self.nr == 0:
        self.nr = 1
        self.ids.nr_label.text = str(self.nr)
    else: return()
You seem to be thinking that the sleep will allow something else to be going on but it won't.

The row:
sleep(1) # Do some heavy stuff
is for simulate some slow processes, in my case it's a bluetooth communication that some time takes 1-2 second