I am trying to separate single click events from double click events using glib.timeout_add()
and glib.source_remove()
. Here is how I am doing it :
class Exchange:
'''
some code
'''
def __init__(self):
self.timeoutID_1 = 0
self.timeoutID_2 = 0
self.startTime1 = 0.0
self.stopTime1 = 0.0
self.startTime2 = 0.0
self.stopTime2 = 0.0
'''
some code
'''
## THE DOUBLE CLICK SIGNAL - item-activated
iconView1.connect("item-activated", self.on_item_activated_1,upButton1, store1)
sw1.add(iconView1)
iconView2.connect("item-activated", self.on_item_activated_2,upButton2, store2)
sw2.add(iconView2)
## THE SINGLE CLICK SIGNAL - selection-changed
iconView1.connect("selection-changed", self.on_selection_changed_1, copyButton1, cutButton1, pasteButton1, deleteButton1)
iconView2.connect("selection-changed", self.on_selection_changed_2, copyButton2, cutButton2, pasteButton2, deleteButton2)
def on_selection_changed_1(self, iconView1, copyButton1, cutButton1, pasteButton1, deleteButton1) :
self.startTime1 = time.time()
self.timeoutID_1 = glib.timeout_add(2000, self.selectIcon_1, iconView1, copyButton1, cutButton1, pasteButton1, deleteButton1)
def on_selection_changed_2(self, iconView2, copyButton2, cutButton2, pasteButton2, deleteButton2) :
self.startTime2 = time.time()
self.timeoutID_2 = glib.timeout_add(2000, self.selectIcon_2, iconView2, copyButton2, cutButton2, pasteButton2, deleteButton2)
def selectIcon_1(self, iconView1, copyButton1, cutButton1, pasteButton1, deleteButton1) :
copyButton1.set_sensitive(True)
cutButton1.set_sensitive(True)
pasteButton1.set_sensitive(True)
deleteButton1.set_sensitive(True)
def selectIcon_2(self, iconView2, copyButton2, cutButton2, pasteButton2, deleteButton2) :
copyButton2.set_sensitive(True)
cutButton2.set_sensitive(True)
pasteButton2.set_sensitive(True)
deleteButton2.set_sensitive(True)
def on_item_activated_1(self, iconView1, item, upButton1, store1) :
self.stopTime1 = time.time()
if self.stopTime1 - self.startTime1 < 1.50 :
glib.source_remove(self.timeoutID_1)
'''
some code
'''
def on_item_activated_2(self, iconView2, item, upButton2, store2) :
self.stopTime2 = time.time()
if self.stopTime2 - self.startTime2 < 1.50 :
glib.source_remove(self.timeoutID_2)
'''
some code
'''
Despite self.stopTime - self.startTime <1.50
being True
(signifying a valid double click) , the single click event is executed, however only once,after 2 secs, for each single-click. How can I completely cancel the execution of the selectIcon
methods for a valid double click?
UPDATE
Following mtwebster's answer I tried to use button_press_event
. Sadly though I am back to square one.
def on_button_press_event(self, widget, event) :
if event.button == 1 :
data = widget.get_path_at_pos(int(event.x), int(event.y))
if data :
if event.type == gtk.gdk._2BUTTON_PRESS :
print " double click "
elif event.type == gtk.gdk.BUTTON_PRESS :
print " single click "
OUTPUT ::
vineet@vineet:~/Documents/Project$ python draft6.py
single click
single click
double click
Adding to my woes three click events are being executed for a double click, two single clicks and one double click!! Are there any other timing mechanisms I could use instead of glib.timeout_add()
where I won't have to deal with uncertainty of the repeated call nonsense?