diff options
author | dave <drykod@gmail.com> | 2009-10-28 07:55:58 (GMT) |
---|---|---|
committer | dave <drykod@gmail.com> | 2009-10-28 07:55:58 (GMT) |
commit | 12b38846a451077ae2a034763bae55ebfe21b19e (patch) | |
tree | 02db7477fe69b616997b29bb1af24b0371e9143a | |
parent | 3950864bebc5a003a9ca4bbda13fbd73a3c6f985 (diff) |
change color of activity widget
-rw-r--r-- | addons/changecolorevent.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/addons/changecolorevent.py b/addons/changecolorevent.py new file mode 100644 index 0000000..09ae13a --- /dev/null +++ b/addons/changecolorevent.py @@ -0,0 +1,109 @@ +# Copyright (C) 2009, Tutorius.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import logging + +import time + +import gobject + +import gtk, gtk.gdk + +from sugar.tutorius.filters import EventFilter +from sugar.tutorius.properties import TStringProperty, TUAMProperty, TColorProperty +from sugar.tutorius.gtkutils import find_widget + +from sugar import profile + +# for easy profile access +xo_line_color = profile.get_color().get_stroke_color() +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. + """ + widaddr = TUAMProperty("0") + + def __init__(self, widaddr=None): + """Constructor - Change a widget color + @param widaddr: the widget for which you want to change the color (UAM) + """ + super(ChangeColorEvent,self).__init__() + + if widaddr: self.widaddr = widaddr + + self._old_color = None + self._new_color = None + + self.wid = None + + def install_handlers(self, callback, **kwargs): + """install_handlers + Change the color of the widaddred widget with the chosen color + """ + super(ChangeColorEvent,self).install_handlers(callback, **kwargs) + + logging.debug("INSIDE INSTALL HANDLERS CHANGE COLOR") + + if not "activity" in kwargs: + logging.debug("ACTIVITY NOT IN KWARGS **********") + + # get widget instance + self.wid = find_widget(kwargs["activity"], self.widaddr) + self.wid.connect("clicked", self.wid_clicked) + + logging.debug("GOT WIDGET IN CHANGE COLOR") + + # we have to get the initial color in the sugar rc theme + current_style = self.wid.rc_get_style() + self._old_color = current_style.bg[gtk.STATE_NORMAL] + + # 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) + + def remove_handlers(self): + """remove handler + Go back to the original color + """ + super(ChangeColorEvent,self).remove_handlers() + + 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 wid_clicked(self, widget): + self.do_callback() + +__event__ = { + "name" : "ChangeColorEvent", + "display_name" : "Change color", + "icon" : "message-bubble", + "class" : ChangeColorEvent, + "mandatory_props" : ["widaddr"] +} + |