From 9e9201628af4e772be0fc03ade575f5d95027c91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Thu, 14 Feb 2013 16:54:22 -0300
Subject: [PATCH 2/6] Add mouse events for the grab hands feature - SL #1959
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
- The three events, press; motion and release, are connected and
disconnected when the grab hands mode is toggled.
- Add the events masks to the captured events.
- Exit grab hands mode when the digital clock is selected.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
---
clock.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 51 insertions(+), 4 deletions(-)
diff --git a/clock.py b/clock.py
index a8ea8df..db9de81 100755
a
|
b
|
More about clocks and time in the World |
54 | 54 | http://en.wikipedia.org/wiki/Date_and_time_notation_by_country |
55 | 55 | |
56 | 56 | """ |
| 57 | # FIXME: remove |
| 58 | import logging |
57 | 59 | |
58 | 60 | # We initialize threading in gobject. As we will detach another thread |
59 | 61 | # to translate the time to text, this other thread will eventually |
… |
… |
class ClockActivity(activity.Activity): |
366 | 368 | """ |
367 | 369 | self._clock.set_display_mode(display_mode) |
368 | 370 | |
369 | | # The hands can't be grabbed in the digital clock mode |
370 | 371 | is_digital = display_mode == _MODE_DIGITAL_CLOCK |
| 372 | |
| 373 | # Exit grab hands mode if the clock is digital |
| 374 | if self._clock.grab_hands_mode == True and is_digital: |
| 375 | self._grab_button.set_active(False) |
| 376 | |
| 377 | # The hands can't be grabbed in the digital clock mode |
371 | 378 | self._grab_button.props.sensitive = not is_digital |
372 | 379 | |
373 | 380 | def _write_time_clicked_cb(self, button): |
… |
… |
class ClockActivity(activity.Activity): |
393 | 400 | """The user clicked on the "grab hands" button to toggle |
394 | 401 | grabbing the hands. |
395 | 402 | """ |
396 | | # FIXME: implement |
397 | | pass |
| 403 | self._clock.change_grab_hands_mode(button.get_active()) |
398 | 404 | |
399 | 405 | def _minutes_changed_cb(self, clock): |
400 | 406 | """Minutes have changed on the clock face: we have to update |
… |
… |
class ClockFace(gtk.DrawingArea): |
547 | 553 | self.connect("size-allocate", self._size_allocate_cb) |
548 | 554 | |
549 | 555 | # The masks to capture the events we are interested in |
550 | | self.add_events(gdk.EXPOSURE_MASK | gdk.VISIBILITY_NOTIFY_MASK) |
| 556 | self.add_events(gdk.EXPOSURE_MASK | gdk.VISIBILITY_NOTIFY_MASK |
| 557 | | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK |
| 558 | | gtk.gdk.BUTTON1_MOTION_MASK) |
551 | 559 | |
552 | 560 | # Define a new signal to notify the application when minutes |
553 | 561 | # change. If the user wants to display the time in full |
… |
… |
class ClockFace(gtk.DrawingArea): |
556 | 564 | gobject.signal_new("time_minute", ClockFace, |
557 | 565 | gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []) |
558 | 566 | |
| 567 | # This flag is True if the clock is in grab hands mode |
| 568 | self.grab_hands_mode = False |
| 569 | |
| 570 | # Event handlers for grabbing the hands. |
| 571 | self._press_id = None |
| 572 | self._motion_id = None |
| 573 | self._release_id = None |
| 574 | |
559 | 575 | def set_display_mode(self, mode): |
560 | 576 | """Set the type of clock to display (simple, nice, digital). |
561 | 577 | 'mode' is one of MODE_XXX_CLOCK constants. |
… |
… |
font_desc="Sans Bold 40">%d</span></markup>') % (i + 1) |
904 | 920 | gobject.timeout_add(1000, self._update_cb) |
905 | 921 | |
906 | 922 | active = property(_get_active, _set_active) |
| 923 | |
| 924 | def change_grab_hands_mode(self, toggle_grab): |
| 925 | """Connect or disconnect the callbacks for to grab the hands |
| 926 | of the clock. |
| 927 | """ |
| 928 | logging.debug("CHANGE GRAB %r", toggle_grab) |
| 929 | self.grab_hands_mode = toggle_grab |
| 930 | |
| 931 | if toggle_grab: |
| 932 | self._press_id = self.connect("button-press-event", |
| 933 | self._press_cb) |
| 934 | self._motion_id = self.connect("motion-notify-event", |
| 935 | self._motion_cb) |
| 936 | self._release_id = self.connect("button-release-event", |
| 937 | self._release_cb) |
| 938 | else: |
| 939 | self.disconnect(self._press_id) |
| 940 | self.disconnect(self._motion_id) |
| 941 | self.disconnect(self._release_id) |
| 942 | |
| 943 | # Update again the clock every seconds. |
| 944 | gobject.timeout_add(1000, self._update_cb) |
| 945 | |
| 946 | def _press_cb(self, widget, event): |
| 947 | logging.debug("PRESS") |
| 948 | |
| 949 | def _motion_cb(self, widget, event): |
| 950 | logging.debug("MOTION") |
| 951 | |
| 952 | def _release_cb(self, widget, event): |
| 953 | logging.debug("RELEASE") |