File: spinner.py

package info (click to toggle)
pygobject 3.55.3-3
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 6,000 kB
  • sloc: ansic: 39,431; python: 26,883; sh: 114; makefile: 81; xml: 35; cpp: 1
file content (40 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (4)
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
import gi

gi.require_version("Gtk", "4.0")
from gi.repository import Gtk


class SpinnerAnimation(Gtk.ApplicationWindow):
    def __init__(self, **kargs):
        super().__init__(**kargs, title="Spinner Demo")

        button = Gtk.ToggleButton(label="Start Spinning")
        button.connect("toggled", self.on_button_toggled)
        button.props.active = False

        self.spinner = Gtk.Spinner()

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=True)
        box.append(button)
        box.append(self.spinner)
        self.set_child(box)

    def on_button_toggled(self, button):
        if button.props.active:
            self.spinner.start()
            button.set_label("Stop Spinning")

        else:
            self.spinner.stop()
            button.set_label("Start Spinning")


def on_activate(app):
    win = SpinnerAnimation(application=app)
    win.present()


app = Gtk.Application(application_id="com.example.App")
app.connect("activate", on_activate)

app.run(None)