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 # Stop the current animating when the same widget requested to be # animated again before it has finished animating widget.animate = False def animate(widget: Gtk.Widget, frame_clock: Gdk.FrameClock) -> bool: widget.animate = True current_time = frame_clock.get_frame_time() if current_time < end_time \ and 0 < widget.get_opacity() \ and widget.animate: 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: return GLib.SOURCE_REMOVE widget.add_tick_callback(animate) return False
def animate(widget: Gtk.Widget, frame_clock: Gdk.FrameClock) -> bool: widget.animate = True current_time = frame_clock.get_frame_time() if current_time < end_time \ and 0 < widget.get_opacity() \ and widget.animate: 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: return GLib.SOURCE_REMOVE