From 01a7e3c2e3f2982ede28342ea3ebc040ecc4e790 Mon Sep 17 00:00:00 2001 From: Martin Abente Lahaye Date: Tue, 15 Jan 2013 20:44:16 +0000 Subject: gtk auto change focus --- diff --git a/010-gtk-auto-scan/example.py b/010-gtk-auto-scan/example.py new file mode 100755 index 0000000..22b5132 --- /dev/null +++ b/010-gtk-auto-scan/example.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +import gtk +import gobject + + +OPTIONS = ['a', 'b', 'c', 'd'] +OPT_LENGHT = 4 +DELAY = 1000 + + +class MyApp(): + + def __init__(self): + window = gtk.Window() + vbox = gtk.VBox() + hbox = gtk.HBox() + label = gtk.Label() + + window.connect('destroy', self.destroy) + + window.add(vbox) + vbox.add(label) + vbox.add(hbox) + + for option in OPTIONS: + button = gtk.Button() + button.set_label(option) + button.connect('activate', self.__button_cb, label, option) + + hbox.add(button) + + window.show_all() + + self._button_index = 0 + gobject.timeout_add(DELAY, self.__timeout_cb, hbox) + + def destroy(self, window, data=None): + gtk.main_quit() + + def __button_cb(self, button, label, option): + label.set_text(option) + + def __timeout_cb(self, hbox): + self._button_index = (self._button_index + 1) % OPT_LENGHT + + buttons = hbox.get_children() + button = buttons[self._button_index] + button.grab_focus() + + return True + +if __name__ == "__main__": + my_app = MyApp() + gtk.main() -- cgit v0.9.1