Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordave <drykod@gmail.com>2009-10-29 05:12:02 (GMT)
committer dave <drykod@gmail.com>2009-10-29 05:12:02 (GMT)
commit8340f12f9f7d3be373a8b94ce7866666abe5be80 (patch)
treefa7b277b01e61358359f67e824e0ffbd2b7b0e05
parent12b38846a451077ae2a034763bae55ebfe21b19e (diff)
change widget color action/event
-rw-r--r--addons/changecolorevent.py50
1 files changed, 40 insertions, 10 deletions
diff --git a/addons/changecolorevent.py b/addons/changecolorevent.py
index 09ae13a..e558937 100644
--- a/addons/changecolorevent.py
+++ b/addons/changecolorevent.py
@@ -23,7 +23,7 @@ import gobject
import gtk, gtk.gdk
from sugar.tutorius.filters import EventFilter
-from sugar.tutorius.properties import TStringProperty, TUAMProperty, TColorProperty
+from sugar.tutorius.properties import TStringProperty, TUAMProperty, TColorProperty, TIntProperty
from sugar.tutorius.gtkutils import find_widget
from sugar import profile
@@ -34,9 +34,7 @@ xo_fill_color = profile.get_color().get_fill_color()
class ChangeColorEvent(EventFilter):
"""
- IntroMessage is a special EventFilter that uses gobject
- start button to trigger a state change after user click on it.
- It must be used inside a gobject main loop to work.
+ ChangeColorEvent
"""
widaddr = TUAMProperty("0")
@@ -50,9 +48,12 @@ class ChangeColorEvent(EventFilter):
self._old_color = None
self._new_color = None
+ self.tmp_color = None
self.wid = None
+ self._handler_id = None
+
def install_handlers(self, callback, **kwargs):
"""install_handlers
Change the color of the widaddred widget with the chosen color
@@ -77,12 +78,10 @@ class ChangeColorEvent(EventFilter):
# define new color
self._new_color = gtk.gdk.color_parse(xo_fill_color)
- # modify bg color
- self.wid.modify_bg(gtk.STATE_NORMAL, self._new_color)
- self.wid.modify_bg(gtk.STATE_NORMAL, self._new_color)
- self.wid.modify_bg(gtk.STATE_PRELIGHT, self._new_color)
- self.wid.modify_bg(gtk.STATE_ACTIVE, self._new_color)
- self.wid.modify_bg(gtk.STATE_INSENSITIVE, self._new_color)
+ # set change color timeout (flash)
+ self.timeout = 500
+ self.tmp_color = self._old_color
+ self._handler_id = gobject.timeout_add(self.timeout, self._timeout_cb)
def remove_handlers(self):
"""remove handler
@@ -90,12 +89,43 @@ class ChangeColorEvent(EventFilter):
"""
super(ChangeColorEvent,self).remove_handlers()
+ if self._handler_id:
+ try:
+ #XXX What happens if this was already triggered?
+ #remove the timer
+ gobject.source_remove(self._handler_id)
+ except:
+ pass
+
+ # modify bg color (go back to original color)
self.wid.modify_bg(gtk.STATE_NORMAL, self._old_color)
self.wid.modify_bg(gtk.STATE_NORMAL, self._old_color)
self.wid.modify_bg(gtk.STATE_PRELIGHT, self._old_color)
self.wid.modify_bg(gtk.STATE_ACTIVE, self._old_color)
self.wid.modify_bg(gtk.STATE_INSENSITIVE, self._old_color)
+ def _timeout_cb(self):
+ """
+ _timeout_cb triggers the eventfilter callback.
+
+ It is necessary because gobject timers only stop if the callback they
+ trigger returns False
+ """
+
+ if self.tmp_color == self._old_color:
+ self.tmp_color = self._new_color
+ else:
+ self.tmp_color = self._old_color
+
+ # modify bg color
+ self.wid.modify_bg(gtk.STATE_NORMAL, self.tmp_color)
+ self.wid.modify_bg(gtk.STATE_NORMAL, self.tmp_color)
+ self.wid.modify_bg(gtk.STATE_PRELIGHT, self.tmp_color)
+ self.wid.modify_bg(gtk.STATE_ACTIVE, self.tmp_color)
+ self.wid.modify_bg(gtk.STATE_INSENSITIVE, self.tmp_color)
+
+ self._handler_id = gobject.timeout_add(self.timeout, self._timeout_cb)
+
def wid_clicked(self, widget):
self.do_callback()