Main index > Python programming > while mousedown button capturing

By mbokil (Desklet Author), on Sun Dec 11 18:12:47 2005: while mousedown button capturing.

I was trying to figure out the best way to capture a button event over time such as a user continuously holding down a button in a desklet. Is there an established way to do this? Would I have to use a timer or a thread to check back to determine if the user is still pressing the button?

Code:

  
def button_press(self, delayed, x, y, button):
        if button==1:
             # volume decrease
             if x >=137 and x <=147:
                 volume = self.get_volume() - 5
                 self.set_volume(volume)
                 self.drawVolumeTxt(volume)
             return

By syfou (Core Developer & Desklet Author), on Sun Dec 11 18:59:04 2005.

You have at your disposal a ButtonRelease event, and related machinery (look here).

You could resort to timers or threading -- nothing wrong there, it's clean programming. Just keeping around a couple of state variables and possibly rewriting the pause() method would also work just fine: Yours,

By mbokil (Desklet Author), on Sun Dec 11 19:10:05 2005.

Thanks, nice documentation BTW.


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.