Exemplo n.º 1
0
    def force_move(self, from_value, to_value, interval):
        """Animate movement from one value to another in some interval.

        This function will try to calculate the correct speed for the animation
        to respect the interval.
        """
        if from_value == to_value:
            if self.state_change:
                self.state_change(False)
            return

        # Note that we invert things here because other functions usually
        # take the MOUSE GESTURE and move the other way around
        dv = from_value - to_value
        self.speed = dv / (interval * \
                               (1 - (0.5 * self.accel_constant * interval)))
        self.accel = -(self.speed * self.accel_constant)
        self.time = ecore.time_get()
        self.cancel_click = True

        self.forced_goal = abs(dv)
        self.forced = True

        if not self.animation:
            if self.state_change:
                self.state_change(True)
            self.animation = ecore.animator_add(self._animation)
Exemplo n.º 2
0
    def pause_timer(self):
        if self._timer is None:
            return

        self._stop_timer = int(ecore.time_get())
        self._timer.stop()
        self._timer_paused = True
Exemplo n.º 3
0
 def animate():
     t = ecore.time_get()
     progress = (t - self.time_start) / self.duration
     if progress >= 1.0:
         progress = 1.0
         self.anim = None
     self._exec(progress)
     return progress < 1.0
Exemplo n.º 4
0
 def animate():
     t = ecore.time_get()
     progress = (t - self.time_start) / self.duration
     if progress >= 1.0:
         progress = 1.0
         self.anim = None
     self._exec(progress)
     return progress < 1.0
Exemplo n.º 5
0
 def create_timer(self, time, func):
     if self._timer is not None:
         self._timer.delete()
     self._start_timer = int(ecore.time_get())
     self._total_time = time
     self._timer_func = func
     self._timer = ecore.timer_add(time, func)
     return self._timer
Exemplo n.º 6
0
    def _animation(self):
        "Calculates an offset to move and calls the move_offset."
        t = ecore.time_get()
        dt = t - self.time
        ddv = (self.speed * dt) + (0.5 * self.accel * dt * dt)
        dv = int(ddv)

        if dt < ecore.animator_frametime_get() / 2.0:
            return True

        if self.forced:
            if self.forced_goal == 0:
                self.stop()
                return False

            if -1 < dv < 1:
                dv = int(self.speed / abs(self.speed))

            if self.forced_goal < abs(dv):
                if dv < 0:
                    dv = -(self.forced_goal)
                else:
                    dv = self.forced_goal
                self.forced_goal = 0
            else:
                self.forced_goal -= abs(dv)

        else: # not forced
            if abs(ddv) < self.min_movement and \
                    abs(self.speed) < self.min_speed:
                self.stop()
                return False

        self.speed = self.speed + (self.accel * dt)
        self.time = t

        moved = self.move_offset(dv)

        # Stop animation if move_offset couldn't move anymore or if already
        # crossed speed zero (stop) line.
        if not moved or (self.speed * self.accel) > 0:
            self.stop()
            return False

        return True
Exemplo n.º 7
0
    def mouse_down(self, value):
        """Feeds object with a mouse down event at value.

        @return: False if the animation stopped, otherwise True.
        """
        scrolling = True
        self.cancel_kinetic = self.cancel_click = False

        if self.animation:
            self.animation.stop()
            self.animation = None
            scrolling = False
            self.cancel_kinetic = self.cancel_click = True

        self.first_value = self.base_value = value
        self.time = ecore.time_get()

        return scrolling
Exemplo n.º 8
0
    def __animate(self, start_time):
        time = ecore.time_get() - start_time
        if time > self.duration:
            time = self.duration
            last_run = True
        else:
            last_run = False

        p_in = (time - self.t0_in) / self.duration_in
        p_out = (time - self.t0_out) / self.duration_out
        self.animate(time, p_in, p_out)

        if time == self.duration or last_run:
            self.tear_down()
            if self.end_callback:
                self.end_callback(self, self.container)
            self.anim = None

        return not last_run
Exemplo n.º 9
0
    def __animate(self, start_time):
        time = ecore.time_get() - start_time
        if time > self.duration:
            time = self.duration
            last_run = True
        else:
            last_run = False

        p_in = (time - self.t0_in) / self.duration_in
        p_out = (time - self.t0_out) / self.duration_out
        self.animate(time, p_in, p_out)

        if time == self.duration or last_run:
            self.tear_down()
            if self.end_callback:
                self.end_callback(self, self.container)
            self.anim = None

        return not last_run
Exemplo n.º 10
0
    def mouse_up(self, value):
        """Feeds object with mouse up event at value.

        @return: True if a click happened, False otherwise.
        """
        # If it's just a small movement and click was not cancelled yet,
        # this is a click.
        delta_first = value - self.first_value
        if abs(delta_first) < self.threshold and not self.cancel_click:
            if self.state_change:
                self.state_change(False)
            self.cancel_click = False
            return True

        # A very slow drag cause the kinetic scroll to stop.
        if self.cancel_kinetic:
            if self.animation:
                self.animation.stop()
                self.animation = None
            if self.state_change:
                self.state_change(False)
            return False

        # Set the values and create the animation
        t = ecore.time_get()
        dt = t - self.time
        dv = value - self.base_value

        self.time = t
        self.speed = dv / dt
        self.accel = -(self.speed * self.accel_constant)
        self.forced = False

        if not self.animation:
            if self.state_change:
                self.state_change(True)
            self.animation = ecore.animator_add(self._animation)

        return False
Exemplo n.º 11
0
    def mouse_move(self, prev_value, value):
        "Feeds object with mouse move event from prev_value to value."
        # A very slow drag (identified by a small mouse_move event) will
        # cause the kinetic scroll to be cancelled when the mouse goes up.
        dv = value - prev_value
        self.cancel_kinetic = (abs(dv) < self.drag_only_threshold)

        self.move_offset(dv)

        # If you drag over the threshold, it's a way to cancel a click
        # before mouse goes up.
        delta_first = value - self.first_value
        if not self.cancel_click and abs(delta_first) > self.threshold:
            if self.state_change:
                self.state_change(True)
            self.cancel_click = True

        # If movement changed orientation, reset kinetic information.
        delta_base = value - self.base_value
        if dv * delta_base < 0:
            self.base_value = prev_value
            self.time = ecore.time_get()
Exemplo n.º 12
0
    def __init__(self, start, end, duration, callback, *args, **kargs):
        """Constructor.

        @param start: initial value (or list/tuple of values).
        @param end: final value (or list/tuple of values).
        @param duration: in seconds.
        @param callback: function to use at every animation tick.
           Signature: C{function(value, *args, **kargs)}, value will be a tuple
           if tuple were given as B{start} and B{end}.
        """
        self.duration = duration
        self.time_start = ecore.time_get()
        if isinstance(start, (tuple, list)) and \
               isinstance(end, (tuple, list)):
            self.value_start = tuple(start)
            self.value_range = tuple((e - s) for s, e in zip(start, end))
        else:
            self.value_start = start
            self.value_range = end - start
        self.func = callback
        self.args = args
        self.kargs = kargs
        self.anim = None
        self._run()
Exemplo n.º 13
0
    def __init__(self, start, end, duration, callback, *args, **kargs):
        """Constructor.

        @param start: initial value (or list/tuple of values).
        @param end: final value (or list/tuple of values).
        @param duration: in seconds.
        @param callback: function to use at every animation tick.
           Signature: C{function(value, *args, **kargs)}, value will be a tuple
           if tuple were given as B{start} and B{end}.
        """
        self.duration = duration
        self.time_start = ecore.time_get()
        if isinstance(start, (tuple, list)) and \
               isinstance(end, (tuple, list)):
            self.value_start = tuple(start)
            self.value_range = tuple((e - s) for s, e in zip(start, end))
        else:
            self.value_start = start
            self.value_range = end - start
        self.func = callback
        self.args = args
        self.kargs = kargs
        self.anim = None
        self._run()
Exemplo n.º 14
0
def get_pos(center_x, center_y, w, h):
    t = ecore.time_get()
    t = (t % pi2) - math.pi # keep time between -pi and pi
    x = center_x + w * math.cos(t)
    y = center_y + h * math.sin(t)
    return x, y
Exemplo n.º 15
0
def get_pos(center_x, center_y, w, h):
    t = ecore.time_get()
    t = (t % pi2) - math.pi  # keep time between -pi and pi
    x = center_x + w * math.cos(t)
    y = center_y + h * math.sin(t)
    return x, y
Exemplo n.º 16
0
    def run(self, container, end_callback=None):
        ContainerEffect.run(self, container, end_callback)

        self.setup()
        self.anim = ecore.animator_add(self.__animate, ecore.time_get())
Exemplo n.º 17
0
    def run(self, container, end_callback=None):
        ContainerEffect.run(self, container, end_callback)

        self.setup()
        self.anim = ecore.animator_add(self.__animate, ecore.time_get())