tuikit/container.py
changeset 9 7175ed629a76
parent 5 ae128c885d0f
child 13 19ebde2fd594
--- a/tuikit/container.py	Wed Apr 13 13:07:26 2011 +0200
+++ b/tuikit/container.py	Sun Jul 31 13:04:39 2011 +0200
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from .widget import Widget
-
+import logging
 
 class Container(Widget):
     def __init__(self, width = 10, height = 10):
@@ -14,6 +14,10 @@
         self.widthrequest = (None, None)
         self.heightrequest = (None, None)
 
+        self.colorprefix = None
+
+        self.trapfocus = False  # if True, tab cycles inside container
+
 
     def add(self, widget, **kw):
         self.children.append(widget)
@@ -34,6 +38,26 @@
             child.settop(top)
 
 
+    def focusnext(self):
+        i = self.children.index(self.top.focuswidget)
+        while True:
+            i += 1
+            if i >= len(self.children):
+                i = 0
+            if self.children[i].canfocus():
+                self.children[i].setfocus()
+                break
+        log = logging.getLogger('tuikit')
+        log.debug(str(self.top.focuswidget.__class__))
+
+
+    def keypress(self, keyname, char):
+        if keyname == 'tab':
+            self.focusnext()
+            return
+        Widget.keypress(self, keyname, char)
+
+
     def resize(self):
         Widget.resize(self)
         for child in self.children:
@@ -45,6 +69,8 @@
             return
 
         screen.pushclip(x, y, self.width, self.height)
+        if self.colorprefix:
+            screen.pushcolorprefix(self.colorprefix)
 
         Widget.draw(self, screen, x, y)
 
@@ -59,6 +85,8 @@
 
         screen.popclip()
 
+        if self.colorprefix:
+            screen.popcolorprefix()
         screen.popclip()