Codebase list xapp / e960387
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
1 changed file(s) with 34 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
55 import sys, os
66 import signal
77 import gettext
8 import time
89
910 import gi
1011 gi.require_version('Gtk', '3.0')
1718 class Main:
1819 def __init__(self):
1920 self.win = XApp.GtkWindow()
21
22 self._animate_progress = 0
2023
2124 self.win.set_default_size(320, 200)
2225
7780 hbox.pack_start(self.pulse_switch, True, True, 4)
7881 box.pack_start(hbox, True, True, 4)
7982
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
8090 frame.show_all()
8191 self.win.connect("delete-event", lambda w, e: Gtk.main_quit())
8292 self.win.present()
8393
8494 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)
85119
86120 def on_icon_name_setter_clicked(self, button, data=None):
87121 self.win.set_icon_name(self.icon_name_entry.get_text())