tuikit/widget.py
changeset 75 2430c643838a
parent 74 23767a33a781
child 76 fa5301e58eca
--- a/tuikit/widget.py	Fri Feb 01 00:24:02 2013 +0100
+++ b/tuikit/widget.py	Fri Feb 01 09:34:15 2013 +0100
@@ -51,7 +51,7 @@
         self.allow_focus = False
 
         #: Dictionary containing optional parameters for layout managers etc.
-        self.hints = {}
+        self._hints = {}
 
         #: Hidden widget does not affect layout.
         self.hidden = False
@@ -167,6 +167,35 @@
         """Real setter for top. Allows override."""
         self._top = value
 
+    def reset_hints(self):
+        """Reset all hints to their initial value.
+
+        This must be called at before any call to update_hint.
+
+        """
+        self._hints.update({k:v() for k,v in self.parent._hint_class.items()})
+
+    def update_hint(self, hint_name, *args, **kwargs):
+        """Set or update hint value.
+
+        Args after hint_name are forwarded to update() method or initializer
+        of hint's class.
+
+        """
+        if hint_name not in self._hints:
+            raise ValueError('Hint %r is not registered.' % hint_name)
+        try:
+            # try update
+            self._hints[hint_name].update(*args, **kwargs)
+        except AttributeError:
+            # if update does not exist, call initializer instead
+            self._hints[hint_name] = self._hints[hint_name].__class__(*args, **kwargs)
+
+    def hint_value(self, hint_name):
+        try:
+            return self._hints[hint_name].get_value()
+        except AttributeError:
+            return self._hints[hint_name]
 
     ### events