File: Tutorial_15_gtk_progress_bar.py

package info (click to toggle)
sugar-pippy-activity 76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,664 kB
  • sloc: python: 5,860; makefile: 16; sh: 1
file content (57 lines) | stat: -rw-r--r-- 1,344 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
57
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GLib


class PyApp(Gtk.Window):

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

        self.set_title('Barras de progreso')
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_border_width(20)

        self.fraction = 0

        grid = Gtk.Grid()
        grid.set_row_spacing(10)

        self.bar1 = Gtk.ProgressBar()
        self.bar1.set_hexpand(True)
        self.bar1.set_vexpand(True)
        grid.attach(self.bar1, 1, 0, 3, 1)

        label = Gtk.Label(label="Una barra de progreso simple")
        label.set_hexpand(True)
        grid.attach(label, 1, 1, 1, 1)

        self.bar2 = Gtk.ProgressBar()
        self.bar2.set_hexpand(True)
        self.bar2.set_vexpand(True)
        grid.attach(self.bar2, 1, 2, 3, 1)

        label = Gtk.Label(label="Una barra de progreso con pulsos")
        grid.attach(label, 1, 3, 1, 1)

        GLib.timeout_add(200, self._update)

        self.add(grid)
        self.show_all()

        self.connect('destroy', Gtk.main_quit)

    def _update(self):
        self.fraction += 0.01
        if self.fraction >= 1:
            self.fraction = 0

        self.bar1.set_fraction(self.fraction)
        self.bar2.pulse()

        return True


PyApp()
Gtk.main()