PDA

View Full Version : Custom Double Click


Camaro
08-14-2012, 08:40 AM
Ok, I've let this bug me all day and it's time to ask for help. I'm trying to extend the PyMel button class by adding double click functionality(something that I can't believe isn't in there by default). What I've got so far works pretty well, but I'm currently stumped when it comes to executing the regular (single click) command if the double click isn't executed fast enough (0.2 seconds). Perhaps the code could explain it better than I:

import time
import pymel.core as pm
BUTTON = pm.uitypes.Button

class dcButton(BUTTON):
'''
Extends the already wrapped pymel
button to add double click functionality
'''
def __init__(self, *args, **kwargs):
BUTTON.__init__(self, *args, **kwargs)
self.start = 0
self.end = 0
self.clicks = 0
self.setCommand(self.Click)

def Start(self):
self.start = time.time()
return self.start

def End(self):
self.end = time.time()
return self.end

def Total(self):
return self.end - self.start

def Click(self, *args):
self.clicks = self.clicks + 1
if self.clicks == 1:
start = self.Start()
if self.clicks == 2:
self.End()
if self.Total() < .2:
print 'Double Click'
self.clicks = 0

with pm.window():
with pm.columnLayout():
btn = dcButton(w=300, h=50)

If you run that and double click the button it'll print "Double Click" to the script editor output (obviously temporary). I love PyMel, but it doesn't seem like they went out of their way to add extra stuff that you'd think would be obvious, such as this. And PyQt is out of the question because a) I wouldn't know the first thing about coding with it and b) I have to pass this functionality onto a friend, and getting him to install the proper version of PyQt will be tricky.

I noticed that when I tried it with a shelf button, I had a single click command that printed out a certain text, and a double click command that printed out a different text. When I tested it I noticed that the single click command was slightly delayed because, at least I think, it was waiting to see if the mouse was going to be clicked a second time in order to execute the double click command, and if it it's not double clicked in time it just executes the single. I think that's built into the command with C++, so that's way over my head. But that's the exact functionality I am aiming for if possible. I'm pretty sure loops are out of the question, so don't bother with those.

Any and all help is appreciated in advance.

NaughtyNathan
08-14-2012, 10:50 AM
why don't you just use the iconTextButton control? this has click and double click built-in...? If you want it with just text and no icon just change the style to "textOnly".

Camaro
08-14-2012, 04:35 PM
Thanks Nathan. While that does work and would probably suit my needs, I would still really like to get this working.

CGTalk Moderation
08-14-2012, 04:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.