Пример #1
0
    def to_invisible(
            widget: Gtk.Widget,
            duration: int = 600) -> bool:
        """Animate the opacity from 1 to 0 for duration in milliseconds."""
        frame_clock = widget.get_frame_clock()
        start_time = frame_clock.get_frame_time()
        end_time = start_time + 1000*duration

        if hasattr(widget, 'anime_id') \
                and widget.anime_id:
            widget.remove_tick_callback(widget.anime_id)

        def animate(
                widget: Gtk.Widget,
                frame_clock: Gdk.FrameClock) -> bool:
            current_time = frame_clock.get_frame_time()
            if current_time < end_time \
                    and widget.get_opacity() > 0:
                t = (current_time-start_time) / (end_time-start_time)
                t = 1 - Animation.ease_out_cubic(t)
                widget.set_opacity(t)
                return GLib.SOURCE_CONTINUE
            else:
                widget.anime_id = None
                return GLib.SOURCE_REMOVE

        widget.anime_id = widget.add_tick_callback(animate)

        return False
Пример #2
0
 def animate(
         widget: Gtk.Widget,
         frame_clock: Gdk.FrameClock) -> bool:
     current_time = frame_clock.get_frame_time()
     if current_time < end_time \
             and widget.get_opacity() > 0:
         t = (current_time-start_time) / (end_time-start_time)
         t = 1 - Animation.ease_out_cubic(t)
         widget.set_opacity(t)
         return GLib.SOURCE_CONTINUE
     else:
         widget.anime_id = None
         return GLib.SOURCE_REMOVE