Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Abente Lahaye <tch@sugarlabs.org>2013-01-15 20:44:16 (GMT)
committer Martin Abente Lahaye <tch@sugarlabs.org>2013-01-15 20:44:16 (GMT)
commit01a7e3c2e3f2982ede28342ea3ebc040ecc4e790 (patch)
treecd6d0e192a8ccc4c87ea14544a7e71fce6cbbed2
parent7e9cd87f080d5e4e16995b660f90a3fe7797aa5e (diff)
gtk auto change focus
-rwxr-xr-x010-gtk-auto-scan/example.py54
1 files changed, 54 insertions, 0 deletions
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()