File: osd_progress_bar.py

package info (click to toggle)
secrets 12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,616 kB
  • sloc: python: 6,838; xml: 7; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,397 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# SPDX-License-Identifier: GPL-3.0-only
from gi.repository import Adw, GObject, Gtk


class OsdProgressBar(Adw.Bin):
    __gtype_name__ = "OsdProgressBar"

    def __init__(self):
        super().__init__()

        progress = Gtk.ProgressBar(
            visible=False,
            halign=Gtk.Align.FILL,
            valign=Gtk.Align.START,
            pulse_step=0.01,
        )
        progress.add_css_class("osd")

        overlay = Gtk.Overlay()
        overlay.add_overlay(progress)

        self.props.child = overlay

        self._progress = progress
        self._overlay = overlay

        def callback(_value: float) -> None:
            self._progress.pulse()

        target = Adw.CallbackAnimationTarget.new(callback)
        animation = Adw.TimedAnimation.new(
            self,
            0.0,
            0.0,
            Adw.DURATION_INFINITE,
            target,
        )

        self._animation = animation

    def start_pulse(self) -> None:
        self._progress.set_visible(True)
        self._animation.play()

    def end_pulse(self) -> None:
        self._progress.set_visible(False)
        self._animation.pause()
        self._animation.reset()

    @GObject.Property(type=Gtk.Widget)
    def content(self):
        return self._overlay.props.child

    @content.setter  # type: ignore
    def content(self, content):
        self._overlay.props.child = content