xapp-gtk-window test script: Add an animate button (to test real-world
effects on system reponsiveness while an operation is running.)
Michael Webster
6 years ago
5 | 5 | import sys, os |
6 | 6 | import signal |
7 | 7 | import gettext |
8 | import time | |
8 | 9 | |
9 | 10 | import gi |
10 | 11 | gi.require_version('Gtk', '3.0') |
17 | 18 | class Main: |
18 | 19 | def __init__(self): |
19 | 20 | self.win = XApp.GtkWindow() |
21 | ||
22 | self._animate_progress = 0 | |
20 | 23 | |
21 | 24 | self.win.set_default_size(320, 200) |
22 | 25 | |
77 | 80 | hbox.pack_start(self.pulse_switch, True, True, 4) |
78 | 81 | box.pack_start(hbox, True, True, 4) |
79 | 82 | |
83 | hbox = Gtk.HBox() | |
84 | self.animate_button = Gtk.Button("Simulate progress over time") | |
85 | self.animate_button.connect("clicked", self.on_animate_progress_clicked) | |
86 | hbox.pack_start(self.animate_button, True, True, 4) | |
87 | ||
88 | box.pack_start(hbox, True, True, 4) | |
89 | ||
80 | 90 | frame.show_all() |
81 | 91 | self.win.connect("delete-event", lambda w, e: Gtk.main_quit()) |
82 | 92 | self.win.present() |
83 | 93 | |
84 | 94 | Gtk.main() |
95 | ||
96 | def on_animate_progress_clicked(self, button, data=None): | |
97 | self.progress.set_sensitive(False) | |
98 | self.pulse_switch.set_sensitive(False) | |
99 | ||
100 | self._animate_progress = 0 | |
101 | self.win.set_progress(0) | |
102 | ||
103 | GObject.timeout_add(500, self.on_progress_tick) | |
104 | ||
105 | def on_progress_tick(self): | |
106 | self.win.set_progress(self._animate_progress) | |
107 | ||
108 | if self._animate_progress == 100: | |
109 | self.on_animate_complete() | |
110 | return False | |
111 | else: | |
112 | self._animate_progress += 1 | |
113 | return True | |
114 | ||
115 | def on_animate_complete(self): | |
116 | self.progress.set_sensitive(True) | |
117 | self.pulse_switch.set_sensitive(True) | |
118 | self.progress.set_value(100) | |
85 | 119 | |
86 | 120 | def on_icon_name_setter_clicked(self, button, data=None): |
87 | 121 | self.win.set_icon_name(self.icon_name_entry.get_text()) |