File: xapp-gtk-window

package info (click to toggle)
xapp 2.8.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,724 kB
  • sloc: ansic: 11,268; python: 1,463; xml: 258; sh: 22; makefile: 9
file content (138 lines) | stat: -rwxr-xr-x 4,541 bytes parent folder | download | duplicates (5)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#! /usr/bin/python3

"""
A demo/test script for the XAppAppGtkWindow class
"""
import sys, os
import signal
import gettext
import time

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('XApp', '1.0')

from gi.repository import GLib, Gtk, XApp, GObject

signal.signal(signal.SIGINT, signal.SIG_DFL)

class Main:
    def __init__(self):
        self.win = XApp.GtkWindow()

        self._animate_progress = 0

        self.win.set_default_size(320, 200)

        frame = Gtk.Frame()
        frame.set_margin_start(2)
        frame.set_margin_end(2)
        frame.set_margin_top(2)
        frame.set_margin_bottom(2)

        self.win.add(frame)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.set_margin_start(2)
        box.set_margin_end(2)
        box.set_margin_top(2)
        box.set_margin_bottom(2)

        frame.add(box)

        heading = Gtk.Label()
        heading.set_markup("Use '<span font_family='mono' weight='bold'>xprop -spy</span>' to monitor changes")
        box.pack_start(heading, True, True, 4)

        hbox = Gtk.HBox()
        self.icon_name_entry = Gtk.Entry()
        self.icon_name_setter = Gtk.Button("Set icon name")
        self.icon_name_setter.connect("clicked", self.on_icon_name_setter_clicked)
        hbox.pack_start(self.icon_name_entry, True, True, 4)
        hbox.pack_start(self.icon_name_setter, False, False, 4)
        box.pack_start(hbox, True, True, 4)

        hbox = Gtk.HBox()
        self.icon_path_entry = Gtk.Entry()
        self.icon_path_setter = Gtk.Button("Set icon path")
        self.icon_path_setter.connect("clicked", self.on_icon_path_setter_clicked)
        hbox.pack_start(self.icon_path_entry, True, True, 4)
        hbox.pack_start(self.icon_path_setter, False, False, 4)
        box.pack_start(hbox, True, True, 4)

        hbox = Gtk.HBox()
        self.progress_label = Gtk.Label("Progress:")
        self.progress = Gtk.Scale()
        self.progress.connect("value-changed", self.on_progress_value_changed)
        self.progress.set_draw_value(True)
        self.progress.set_digits(0)
        self.progress.set_range(0, 100)

        hbox.pack_start(self.progress_label, False, False, 4)
        hbox.pack_start(self.progress, True, True, 4)
        box.pack_start(hbox, True, True, 4)

        hbox = Gtk.HBox()
        self.pulse_label = Gtk.Label("Progress pulse:")
        self.pulse_switch = Gtk.Switch()
        self.pulse_switch.set_halign(Gtk.Align.CENTER)
        self.pulse_switch.connect("notify::active", self.on_pulse_switch_changed)
        hbox.pack_start(self.pulse_label, False, False, 4)
        hbox.pack_start(self.pulse_switch, True, True, 4)
        box.pack_start(hbox, True, True, 4)

        hbox = Gtk.HBox()
        self.animate_button = Gtk.Button("Simulate progress over time")
        self.animate_button.connect("clicked", self.on_animate_progress_clicked)
        hbox.pack_start(self.animate_button, True, True, 4)

        box.pack_start(hbox, True, True, 4)

        frame.show_all()
        self.win.connect("delete-event", lambda w, e: Gtk.main_quit())
        self.win.present()

        Gtk.main()

    def on_animate_progress_clicked(self, button, data=None):
        self.progress.set_sensitive(False)
        self.pulse_switch.set_sensitive(False)

        self._animate_progress = 0
        self.win.set_progress(0)

        GObject.timeout_add(500, self.on_progress_tick)

    def on_progress_tick(self):
        self.win.set_progress(self._animate_progress)

        if self._animate_progress == 100:
            self.on_animate_complete()
            return False
        else:
            self._animate_progress += 1
            return True

    def on_animate_complete(self):
        self.progress.set_sensitive(True)
        self.pulse_switch.set_sensitive(True)
        self.progress.set_value(100)

    def on_icon_name_setter_clicked(self, button, data=None):
        self.win.set_icon_name(self.icon_name_entry.get_text())

    def on_icon_path_setter_clicked(self, button, data=None):
        try:
            self.win.set_icon_from_file(self.icon_path_entry.get_text())
        except GLib.Error as e:
            print(e.message)

    def on_progress_value_changed(self, range, data=None):
        self.win.set_progress(int(self.progress.get_value()))
        self.pulse_switch.set_active(False)

    def on_pulse_switch_changed(self, switch, pspec, data=None):
        self.win.set_progress_pulse(self.pulse_switch.get_active())

if __name__ == "__main__":
    main = Main()