From: Marius Gedminas <marius@gedmin.as>
... | ... |
@@ -714,6 +714,7 @@ class DotWidget(gtk.DrawingArea): |
714 | 714 |
self.x, self.y = 0.0, 0.0 |
715 | 715 |
self.zoom_ratio = 1.0 |
716 | 716 |
self.animation = NoAnimation(self) |
717 |
+ self.presstime = None |
|
717 | 718 |
|
718 | 719 |
def set_dotcode(self, dotcode): |
719 | 720 |
p = subprocess.Popen( |
... | ... |
@@ -820,29 +821,43 @@ class DotWidget(gtk.DrawingArea): |
820 | 821 |
def on_area_button_press(self, area, event): |
821 | 822 |
if event.button == 2 or event.button == 1: |
822 | 823 |
area.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR)) |
823 |
- self.prevmousex = event.x |
|
824 |
- self.prevmousey = event.y |
|
824 |
+ self.prevmousex = self.startmousex = event.x |
|
825 |
+ self.prevmousey = self.startmousey = event.y |
|
826 |
+ self.presstime = time.time() |
|
825 | 827 |
self.animation.stop() |
826 | 828 |
|
827 | 829 |
if event.type not in (gtk.gdk.BUTTON_PRESS, gtk.gdk.BUTTON_RELEASE): |
828 | 830 |
return False |
829 | 831 |
x, y = int(event.x), int(event.y) |
830 |
- url = self.get_url(x, y) |
|
831 |
- if url is not None: |
|
832 |
- self.emit('clicked', unicode(url), event) |
|
833 |
- return True |
|
834 |
- |
|
835 |
- jump = self.get_jump(x, y) |
|
836 |
- if jump is not None: |
|
837 |
- jumpx, jumpy = jump |
|
838 |
- self.animate_to(jumpx, jumpy) |
|
839 | 832 |
return False |
840 | 833 |
|
834 |
+ def is_click(self, event, click_fuzz=4, click_timeout=1.0): |
|
835 |
+ assert event.type == gtk.gdk.BUTTON_RELEASE |
|
836 |
+ if self.presstime is None: |
|
837 |
+ # got a button release without seeing the press? |
|
838 |
+ return False |
|
839 |
+ deltax = self.startmousex - event.x |
|
840 |
+ deltay = self.startmousey - event.y |
|
841 |
+ return (time.time() < self.presstime + click_timeout |
|
842 |
+ and math.hypot(deltax, deltay) < click_fuzz) |
|
843 |
+ |
|
841 | 844 |
def on_area_button_release(self, area, event): |
842 | 845 |
if event.button == 2 or event.button == 1: |
843 | 846 |
area.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.ARROW)) |
844 | 847 |
self.prevmousex = None |
845 | 848 |
self.prevmousey = None |
849 |
+ |
|
850 |
+ if event.button == 1 and self.is_click(event): |
|
851 |
+ x, y = int(event.x), int(event.y) |
|
852 |
+ url = self.get_url(x, y) |
|
853 |
+ if url is not None: |
|
854 |
+ self.emit('clicked', unicode(url), event) |
|
855 |
+ else: |
|
856 |
+ jump = self.get_jump(x, y) |
|
857 |
+ if jump is not None: |
|
858 |
+ jumpx, jumpy = jump |
|
859 |
+ self.animate_to(jumpx, jumpy) |
|
860 |
+ |
|
846 | 861 |
return True |
847 | 862 |
return False |
848 | 863 |
|