Exemplo n.º 1
0
 def do_button_press_event(self, actor, event):
     if event.button == 1:
         self._is_pressed = True
         clutter.grab_pointer(self)
         return True
     else:
         return False
Exemplo n.º 2
0
 def do_button_press_event (self, actor, event):
     if event.button == 1:
         self._is_pressed = True
         clutter.grab_pointer(self)
         return True
     else:
         return False
Exemplo n.º 3
0
    def _on_button_press_event(self, actor, event):
        """`button-press` event handler."""
        if not self.is_reactive_allowed:
            return

        clutter.grab_pointer(self.video_texture)
        if not self.video_texture.handler_is_connected(self._motion_handler):
            self._motion_handler = self.video_texture.connect("motion-event", self._on_motion_event)

        self._motion_buffer.start(event)
        self._event_mode = self.MODE_PLAYPAUSE
Exemplo n.º 4
0
    def _on_button_press_event(self, actor, event):
        """button-press-event handler."""
        clutter.grab_pointer(self._event_rect)
        if not self._event_rect.handler_is_connected(self._motion_handler):
            self._motion_handler = self._event_rect.connect(
                'motion-event', self._on_motion_event)

        (x_menu, y_menu) = self.get_transformed_position()
        (x_moving_group, y_moving_group) = self._moving_group.get_position()

        # Events coordinates are relative to the stage.
        # So they need to be computed relatively to the moving group.
        x = event.x - x_menu - x_moving_group
        y = event.y - y_menu - y_moving_group

        x_grid = int(x / self._item_width_abs)
        y_grid = int(y / self._item_height_abs)

        if self._is_vertical:
            new_index = y_grid * self.items_per_row + x_grid
        else:
            new_index = x_grid * self.items_per_col + y_grid

        (delta_x, delta_y) = self._index_to_xy(self._selected_index)

        delta_x -= x_grid
        delta_y -= y_grid

        # Correction factor due to the fact that items are not necessary square,
        # but most probably rectangles. So the distance in the grid coordinates
        # must be corrected by a factor to have a real distance in pixels on the
        # screen.
        correction = float(self._item_width_abs) / float(self._item_height_abs)
        correction *= correction
        distance = math.sqrt(delta_x**2 * correction + delta_y**2)

        # Computation of the duration of animations, scaling grid steps to ms.
        duration = int(distance * 50)

        if self.selected_index == new_index and \
            self.active and \
            not self._cursor_timeline.is_playing() and \
            not self._moving_group_timeline.is_playing():
            self._event_mode = self.MODE_SELECT
        else:
            self.active = True
            self._event_mode = self.MODE_NONE

        self._set_selected_index(new_index, duration)

        self._motion_buffer.start(event)

        return False
Exemplo n.º 5
0
    def _on_button_press_event(self, actor, event):
        """button-press-event handler."""
        clutter.grab_pointer(self._event_rect)
        if not self._event_rect.handler_is_connected(self._motion_handler):
            self._motion_handler = self._event_rect.connect('motion-event',
                self._on_motion_event)

        (x_menu, y_menu) = self.get_transformed_position()
        (x_moving_group, y_moving_group) = self._moving_group.get_position()

        # Events coordinates are relative to the stage.
        # So they need to be computed relatively to the moving group.
        x = event.x - x_menu - x_moving_group
        y = event.y - y_menu - y_moving_group

        x_grid = int(x / self._item_width_abs)
        y_grid = int(y / self._item_height_abs)

        if self._is_vertical:
            new_index = y_grid * self.items_per_row + x_grid
        else:
            new_index = x_grid * self.items_per_col + y_grid

        (delta_x, delta_y) = self._index_to_xy(self._selected_index)

        delta_x -= x_grid
        delta_y -= y_grid

        # Correction factor due to the fact that items are not necessary square,
        # but most probably rectangles. So the distance in the grid coordinates
        # must be corrected by a factor to have a real distance in pixels on the
        # screen.
        correction = float(self._item_width_abs) / float(self._item_height_abs)
        correction *= correction
        distance = math.sqrt(delta_x ** 2 * correction + delta_y ** 2)

        # Computation of the duration of animations, scaling grid steps to ms.
        duration = int(distance * 50)

        if self.selected_index == new_index and \
            self.active and \
            not self._cursor_timeline.is_playing() and \
            not self._moving_group_timeline.is_playing():
            self._event_mode = self.MODE_SELECT
        else:
            self.active = True
            self._event_mode = self.MODE_NONE

        self._set_selected_index(new_index, duration)

        self._motion_buffer.start(event)

        return False
Exemplo n.º 6
0
    def _on_button_press_event(self, actor, event):
        """`button-press` event handler."""
        if not self.is_reactive_allowed:
            return

        clutter.grab_pointer(self.video_texture)
        if not self.video_texture.handler_is_connected(self._motion_handler):
            self._motion_handler = self.video_texture.connect(
                'motion-event', self._on_motion_event)

        self._motion_buffer.start(event)
        self._event_mode = self.MODE_PLAYPAUSE
Exemplo n.º 7
0
    def _on_button_press_event(self, actor, event):
        """button-press-event handler."""
        clutter.grab_pointer(self)
        if not self.handler_is_connected(self._motion_handler):
            self._motion_handler = self.connect('motion-event',
                                                self._on_motion_event)

        if self._motion_timeline.is_playing():
            # A click with an animation pending should stop the animation.
            self._motion_timeline.stop()

            # Go to MODE_STOP to handle correctly next button-release event.
            self._event_mode = self.MODE_STOP
            self.offset = -self.content.get_y()
        else:
            # No animation pending so we're going to do nothing or to move
            # all the content.
            self._old_offset = self.offset
            self._motion_buffer.start(event)
            self._event_mode = self.MODE_SELECTION

        return False
Exemplo n.º 8
0
    def _on_button_press_event(self, actor, event):
        """button-press-event handler."""
        clutter.grab_pointer(self)
        if not self.handler_is_connected(self._motion_handler):
            self._motion_handler = self.connect('motion-event',
                self._on_motion_event)

        if self._motion_timeline.is_playing():
            # A click with an animation pending should stop the animation.
            self._motion_timeline.stop()

            # Go to MODE_STOP to handle correctly next button-release event.
            self._event_mode = self.MODE_STOP
            self.offset = -self.content.get_y()
        else:
            # No animation pending so we're going to do nothing or to move
            # all the content.
            self._old_offset = self.offset
            self._motion_buffer.start(event)
            self._event_mode = self.MODE_SELECTION

        return False
Exemplo n.º 9
0
    def _on_button_press_event(self, actor, event):
        """button-press-event handler"""
        clutter.grab_pointer(self)
        if not self.handler_is_connected(self._motion_handler):
            self._motion_handler = self.connect("motion-event", self._on_motion_event)

        if self._timeline.is_playing():
            # before we stop the timeline, store its progression
            self._animation_progression = self._timeline.get_progress()

            # A click with an animation pending should stop the animation
            self._timeline.stop()

            # go to MODE_STOP to handle correctly next button-release event
            self._event_mode = self.MODE_STOP
        else:
            # no animation pending so we're going to do either a menu_item
            # selection or a menu motion. This will be decided later, right now
            # we just take a snapshot of this button-press-event as a start.
            self._motion_buffer.start(event)
            self._event_mode = self.MODE_SELECTION

        return False
Exemplo n.º 10
0
    def _on_button_press_event(self, actor, event):
        '''button-press-event handler.'''
        if not self.visible:
            self.visible = True
            return

        clutter.grab_pointer(self)

        x = event.x - self.get_x()
        y = event.y - self.get_y()

        dx = x - int(self.bar_x + (self.height / 2) + \
            (self.bar_width - self.height) * self._progress)
        dy = y - int(self.height / 2)

        # Calculation of the distance between our click and the middle of
        # the progress_bar cursor position.
        distance = math.sqrt(dx * dx + dy * dy)

        if distance <= (self.CURSOR_RADIUS * self.height):
            # Clicked around the cursor.
            if not self.handler_is_connected(self._motion_handler):
                self._motion_handler = self.connect('motion-event',
                                                    self._on_motion_event)
                self._progress_bar_moving = True
        else:
            # Clicked far from the cursor. Change to the pointed position.
            progress = (x - self.bar_x - (self.height / 2.0)) / \
                (self.bar_width - self.height)
            self.progress = progress
            self._progress_bar_moving = False
            self.media_player.set_media_position(self.progress)

        if self._hide_timeout_key is not None:
            gobject.source_remove(self._hide_timeout_key)

        return False
Exemplo n.º 11
0
    def _on_button_press_event(self, actor, event):
        '''button-press-event handler.'''
        if not self.visible:
            self.visible = True
            return

        clutter.grab_pointer(self)

        x = event.x - self.get_x()
        y = event.y - self.get_y()

        dx = x - int(self.bar_x + (self.height / 2) + \
            (self.bar_width - self.height) * self._progress)
        dy = y - int(self.height / 2)

        # Calculation of the distance between our click and the middle of
        # the progress_bar cursor position.
        distance = math.sqrt(dx * dx + dy * dy)

        if distance <= (self.CURSOR_RADIUS * self.height):
            # Clicked around the cursor.
            if not self.handler_is_connected(self._motion_handler):
                self._motion_handler = self.connect('motion-event',
                    self._on_motion_event)
                self._progress_bar_moving = True
        else:
            # Clicked far from the cursor. Change to the pointed position.
            progress = (x - self.bar_x - (self.height / 2.0)) / \
                (self.bar_width - self.height)
            self.progress = progress
            self._progress_bar_moving = False
            self.media_player.set_media_position(self.progress)

        if self._hide_timeout_key is not None:
            gobject.source_remove(self._hide_timeout_key)

        return False
Exemplo n.º 12
0
    def _on_button_press_event(self, actor, event):
        """button-press-event handler"""
        clutter.grab_pointer(self)
        if not self.handler_is_connected(self._motion_handler):
            self._motion_handler = self.connect('motion-event',
                                                self._on_motion_event)

        if self._timeline.is_playing():
            # before we stop the timeline, store its progression
            self._animation_progression = self._timeline.get_progress()

            # A click with an animation pending should stop the animation
            self._timeline.stop()

            # go to MODE_STOP to handle correctly next button-release event
            self._event_mode = self.MODE_STOP
        else:
            # no animation pending so we're going to do either a menu_item
            # selection or a menu motion. This will be decided later, right now
            # we just take a snapshot of this button-press-event as a start.
            self._motion_buffer.start(event)
            self._event_mode = self.MODE_SELECTION

        return False
Exemplo n.º 13
0
    def event_central(self, obj, event):
        ## This routine runs many times. Once for every kind
        ## of event the actor is getting.

        ## filter out only the mouse events.
        if event.type not in Mouserizer.__clutter_mouse_event_types:
            return Mouserizer.YES_CONTINUE_EMITTING

        ## filter out buttons we are NOT going to deal with
        if hasattr(event, "button"):
            b = 1 << (event.button - 1)
            #print bin(b)," vs ", bin(self.buttons)
            if not(b & self.buttons !=0 ):
                return Mouserizer.NO_STOP_EMITTING # is this wise?

        ## event_central ONLY runs when cursor is
        ## over the actor -- thus ENTER is implied.

        ## Make a note of PRESS/RELEASE
        if event.type==clutter.BUTTON_PRESS:
            self.ui_state = self.ui_state | Mouserizer.__FLAG_PRESSING # set bit
        if event.type==clutter.BUTTON_RELEASE:
            self.ui_state = self.ui_state | Mouserizer.__FLAG_RELEASING # set bit

        ## Make a note of MOTION
        ## First, clear it.
        self.ui_state = self.ui_state & ~Mouserizer.__FLAG_MOVING # clear bit
        if event.type==clutter.MOTION:
            self.ui_state = self.ui_state | Mouserizer.__FLAG_MOVING # set bit

        ## Now, what kinds of stuff is this actor interested in?

        ## DO META EVENTS - "More than" events. e.g. 'Click' is press, then release.
        if (self.ui & Mouserizer.CLICKABLE) != 0: # test bit
            if self.ui_state == Mouserizer.__PATTERN_CLICK:
                if event.click_count > 1:
                    self.emit('double-click', event)
                else:
                    ## A single click is fired just before double-click...!
                    self.emit('single-click', event)

        if (self.ui & Mouserizer.DRAGABLE) !=0: # test bit
            if self.ui_state == Mouserizer.__PATTERN_DRAG_START:
                self.ui_state=self.ui_state | Mouserizer.__FLAG_DRAGGING # set bit
                self.draglet = DragEnvelope( self, event )
                ## Phew! I thought I was fcuked! In order to get dragging to
                ## work when the pointer is NOT ON the Actor, I had to revert
                ## to grab_pointer* -- and that needs connecting. I connected the
                ## two appropriate event to *this* same function! And it works :D
                ##
                ## * grab_pointer causes the entire window (stage?) to focus on the
                ##   Actor passed -- so I get all motion and release events even where
                ##   the Actor aint.
                ##   ! Not sure what kind of recursive issues this may throw at me :(
                clutter.grab_pointer( self )
                self.connect('motion-event', self.event_central)
                self.connect('button-release-event', self.event_central)
                self.emit('drag-start', self.draglet )
            elif self.ui_state == Mouserizer.__PATTERN_DRAG:
                self.draglet.calcPos( event ) # A 'draglet' is a little wrapper containing the event and some tricks.
                ## Who is under me? Only do if PICK_UNDER flag is set.
                if self.__PICK_UNDER:
                    self.hide()
                    a = self.stage.get_actor_at_pos(clutter.PICK_REACTIVE, int(event.x),int(event.y))
                    self.show()
                    ## a is!
                    ## Only emit if a has a drag-over signal:
                    if gobject.signal_lookup('drag-over', a ):
                        print a, " under me"
                        a.emit('drag-over', self.draglet)
                self.emit('dragging', self.draglet)

            elif self.ui_state == Mouserizer.__PATTERN_DROP:
                self.draglet.calcPos( event )
                self.ui_state= self.ui_state & ~Mouserizer.__FLAG_DRAGGING # clear bit
                clutter.ungrab_pointer()
                self.emit("drop", self.draglet)
                del(self.draglet)

        ## META EVENTS are done.

        ## Flip opposites off.
        if event.type==clutter.BUTTON_PRESS:
            self.ui_state = self.ui_state & ~Mouserizer.__FLAG_RELEASING # clear bit
        if event.type==clutter.BUTTON_RELEASE:
            self.ui_state = self.ui_state & ~Mouserizer.__FLAG_PRESSING # clear bit
            self.ui_state = self.ui_state & ~Mouserizer.__FLAG_RELEASING # clear bit
            self.ui_state = self.ui_state & ~Mouserizer.__FLAG_DRAGGING # clear bit

        return Mouserizer.YES_CONTINUE_EMITTING