Ticket #1959: 0002-Add-mouse-events-for-the-grab-hands-feature-SL-1959.patch

File 0002-Add-mouse-events-for-the-grab-hands-feature-SL-1959.patch, 4.6 KB (added by manuq, 11 years ago)
  • clock.py

    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 
    5454  http://en.wikipedia.org/wiki/Date_and_time_notation_by_country
    5555
    5656"""
     57# FIXME: remove
     58import logging
    5759
    5860# We initialize threading in gobject. As we will detach another thread
    5961# to translate the time to text, this other thread will eventually
    class ClockActivity(activity.Activity): 
    366368        """
    367369        self._clock.set_display_mode(display_mode)
    368370
    369         # The hands can't be grabbed in the digital clock mode
    370371        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
    371378        self._grab_button.props.sensitive = not is_digital
    372379
    373380    def _write_time_clicked_cb(self, button):
    class ClockActivity(activity.Activity): 
    393400        """The user clicked on the "grab hands" button to toggle
    394401        grabbing the hands.
    395402        """
    396         # FIXME: implement
    397         pass
     403        self._clock.change_grab_hands_mode(button.get_active())
    398404
    399405    def _minutes_changed_cb(self, clock):
    400406        """Minutes have changed on the clock face: we have to update
    class ClockFace(gtk.DrawingArea): 
    547553        self.connect("size-allocate", self._size_allocate_cb)
    548554
    549555        # 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)
    551559
    552560        # Define a new signal to notify the application when minutes
    553561        # change.  If the user wants to display the time in full
    class ClockFace(gtk.DrawingArea): 
    556564        gobject.signal_new("time_minute", ClockFace,
    557565          gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
    558566
     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
    559575    def set_display_mode(self, mode):
    560576        """Set the type of clock to display (simple, nice, digital).
    561577        'mode' is one of MODE_XXX_CLOCK constants.
    font_desc="Sans Bold 40">%d</span></markup>') % (i + 1) 
    904920            gobject.timeout_add(1000, self._update_cb)
    905921
    906922    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")