From 5a616a58b52b2150d3113ac7059d20888e0a931f Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Thu, 05 Nov 2009 21:41:47 +0000 Subject: Merge dave's commits --- (limited to 'addons') diff --git a/addons/bubblemessage.py b/addons/bubblemessage.py index 6572a6a..1ed1fe0 100644 --- a/addons/bubblemessage.py +++ b/addons/bubblemessage.py @@ -48,7 +48,7 @@ class BubbleMessage(Action): self._bubble = None self._speaker = None - def do(self): + def do(self, **kwargs): """ Show the dialog """ diff --git a/addons/changecolor.py b/addons/changecolor.py new file mode 100644 index 0000000..460da32 --- /dev/null +++ b/addons/changecolor.py @@ -0,0 +1,127 @@ +# 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 time + +import gobject + +import gtk, gtk.gdk + +from sugar.tutorius.actions import Action +from sugar.tutorius.properties import TUAMProperty +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 ChangeColor(Action): + """ + ChangeColorEvent + """ + # widget address property + widaddr = TUAMProperty("0") + + # set timeout + timeout = 500 + + def __init__(self, widaddr=None): + """Constructor - Change a widget color + @param widaddr: the widget for which you want to change the color (UAM) + """ + Action.__init__(self) + + if widaddr: self.widaddr = widaddr + + self.init_style = None + self._new_color = None + + self.wid = None + + self._handler_id = None + + def do(self, **kwargs): + """ + do. + Change the color of the widaddr widget with the chosen color + """ + + if not "activity" in kwargs: + raise TypeError("activity argument is Mandatory") + + # get widget instance + self.wid = find_widget(kwargs["activity"], self.widaddr, ignore_errors=False) + + if not self.wid: + raise NameError("widget not found") + + # we have to get the initial color in the sugar rc theme + self.init_style = self.wid.rc_get_style() + + # define new color + self._new_color = gtk.gdk.color_parse(xo_fill_color) + + # set change color timeout (flash) + self._handler_id = gobject.timeout_add(ChangeColor.timeout, self._timeout_cb) + + def undo(self): + """ + Remove timer and go back to the original color + """ + + if self._handler_id: + try: + #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.init_style.bg[gtk.STATE_NORMAL]) + self.wid.modify_bg(gtk.STATE_PRELIGHT, self.init_style.bg[gtk.STATE_PRELIGHT]) + self.wid.modify_bg(gtk.STATE_ACTIVE, self.init_style.bg[gtk.STATE_ACTIVE]) + self.wid.modify_bg(gtk.STATE_INSENSITIVE, self.init_style.bg[gtk.STATE_INSENSITIVE]) + + def _timeout_cb(self): + """ + _timeout_cb triggers the eventfilter callback. + """ + + if self.wid.rc_get_style().bg[gtk.STATE_NORMAL] == self._new_color: + # modify bg color (go back to original color) + self.wid.modify_bg(gtk.STATE_NORMAL, self.init_style.bg[gtk.STATE_NORMAL]) + self.wid.modify_bg(gtk.STATE_PRELIGHT, self.init_style.bg[gtk.STATE_PRELIGHT]) + self.wid.modify_bg(gtk.STATE_ACTIVE, self.init_style.bg[gtk.STATE_ACTIVE]) + self.wid.modify_bg(gtk.STATE_INSENSITIVE, self.init_style.bg[gtk.STATE_INSENSITIVE]) + else: + # modify bg color (to 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) + + return True + +__action__ = { + "name" : "ChangeColor", + "display_name" : "Change widget color", + "icon" : "message-bubble", + "class" : ChangeColor, + "mandatory_props" : ["widaddr"] +} + diff --git a/addons/clickaction.py b/addons/clickaction.py index 88c5519..071af28 100644 --- a/addons/clickaction.py +++ b/addons/clickaction.py @@ -29,7 +29,7 @@ class ClickAction(Action): Action.__init__(self) self.widget = widget - def do(self): + def do(self, **kwargs): """ click the widget """ diff --git a/addons/dialogmessage.py b/addons/dialogmessage.py index 9250693..fad6d2c 100644 --- a/addons/dialogmessage.py +++ b/addons/dialogmessage.py @@ -36,7 +36,7 @@ class DialogMessage(Action): self.message = message if position: self.position = position - def do(self): + def do(self, **kwargs): """ Show the dialog """ diff --git a/addons/disablewidget.py b/addons/disablewidget.py index fd88303..b3d9ae6 100644 --- a/addons/disablewidget.py +++ b/addons/disablewidget.py @@ -30,7 +30,7 @@ class DisableWidgetAction(Action): self.target = target self._widget = None - def do(self): + def do(self, **kwargs): """Action do""" os = ObjectStore() if os.activity: diff --git a/addons/messagebuttonnext.py b/addons/messagebuttonnext.py new file mode 100644 index 0000000..74ce1bb --- /dev/null +++ b/addons/messagebuttonnext.py @@ -0,0 +1,171 @@ +# 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 gtk, gtk.gdk + +from sugar.tutorius.filters import EventFilter +from sugar.tutorius.properties import TStringProperty, TArrayProperty +from sugar.tutorius import overlayer + +from sugar import profile + +xo_line_color_profile = profile.get_color().get_stroke_color() +xo_fill_color_profile = profile.get_color().get_fill_color() + +class MessageButtonNext(EventFilter): + """ + MessageButtonNext + """ + # set message + message = TStringProperty("Message") + + # create the position as an array of fixed-size 2 + position = TArrayProperty((0,0), 2, 2) + + # set padding + padding = 40 + + def __init__(self, message=None, position=None, center_pos=False): + """Constructor. + + @param message message to display + @param position message position + """ + super(MessageButtonNext,self).__init__() + + if position: + self.position = position + else: + # TODO: to be removed when creator supports editing properties on events + self.position = (300, 200) + + if message: + self.message = message + + self.overlay = None + self.msgnext = None + + def install_handlers(self, callback, **kwargs): + """install_handlers creates the message button next and shows it""" + super(MessageButtonNext,self).install_handlers(callback, **kwargs) + + if not "activity" in kwargs: + raise TypeError("activity argument is Mandatory") + + # get activity instance + self.activity = kwargs["activity"] + + # get or inject overlayer + self.overlay = self.activity._overlayer + + if not self.overlay: + self.overlay = self.activity._overlayer + + btntext = "NEXT" + + self.msgnext = MsgNext(text=self.message,btntext=btntext) + self.msgnext._btnnext.connect("clicked", self.btnnext_clicked) + + # add space around minimum need size + wid_width, wid_height = self.msgnext.size_request() + self.msgnext.set_size_request(wid_width+MessageButtonNext.padding, wid_height+MessageButtonNext.padding) + + # set position + x, y = self.position + + self.msgnext.show() + self.overlay.put(self.msgnext, x, y) + self.overlay.queue_draw() + + def remove_handlers(self): + """remove handler removes the message button next""" + super(MessageButtonNext,self).remove_handlers() + + if self.msgnext: + self.msgnext.destroy() + self.msgnext = None + + def btnnext_clicked(self, widget): + self.do_callback() + +__event__ = { + "name" : "MessageButtonNext", + "display_name" : "Message button next", + "icon" : "message-bubble", + "class" : MessageButtonNext, + "mandatory_props" : ["message"] +} + +class MsgNext(gtk.EventBox): + """ + Create an EventBox + """ + def __init__(self, text, btntext): + """ + Creates an Event Box + """ + gtk.EventBox.__init__(self) + + self.message = text + self.btnmessage = btntext + + self.set_visible_window(True) + + # create a vbox + self.box = gtk.VBox() + + # create a label (set message to display) + self._label = gtk.Label() + self._text = "%s" % self.message + self._label.set_markup(self._text) + self._label.set_line_wrap(True) + + self._colortext = gtk.gdk.color_parse("white") + self._label.modify_fg(gtk.STATE_NORMAL, self._colortext) + self._label.modify_fg(gtk.STATE_PRELIGHT, self._colortext) + self._label.modify_fg(gtk.STATE_ACTIVE, self._colortext) + self._label.modify_fg(gtk.STATE_INSENSITIVE, self._colortext) + + self._label.show() + + # create a hbox (holding button) + self._hbox = gtk.HBox() + + # create a button inside hbox + self._btnnext = gtk.Button(self.btnmessage) + + self._colorbtn = gtk.gdk.color_parse(xo_fill_color_profile) + + self._btnnext.modify_bg(gtk.STATE_NORMAL, self._colorbtn) + self._btnnext.modify_bg(gtk.STATE_PRELIGHT, self._colorbtn) + self._btnnext.modify_bg(gtk.STATE_ACTIVE, self._colorbtn) + + self._btnnext.show() + + self._hbox.pack_end(self._btnnext, expand=False) + + self._hbox.show() + + self.box.pack_start(self._label, expand=True) + self.box.pack_start(self._hbox, expand=True) + + self.box.show() + + self.add(self.box) + + self._colormsgnext = gtk.gdk.color_parse(xo_fill_color_profile) + self.modify_bg(gtk.STATE_NORMAL, self._colormsgnext) + diff --git a/addons/oncewrapper.py b/addons/oncewrapper.py index 5db3b60..c404ae4 100644 --- a/addons/oncewrapper.py +++ b/addons/oncewrapper.py @@ -32,7 +32,7 @@ class OnceWrapper(Action): self._need_undo = False self.action = action - def do(self): + def do(self, **kwargs): """ Do the action only on the first time """ diff --git a/addons/readfile.py b/addons/readfile.py index 9fe2f81..4a6c54d 100644 --- a/addons/readfile.py +++ b/addons/readfile.py @@ -34,7 +34,7 @@ class ReadFile(Action): if filename: self.filename=filename - def do(self): + def do(self, **kwargs): """ Perform the action, call read_file on the activity """ diff --git a/addons/widgetidentifyaction.py b/addons/widgetidentifyaction.py index 3df244b..c44964b 100644 --- a/addons/widgetidentifyaction.py +++ b/addons/widgetidentifyaction.py @@ -24,7 +24,7 @@ class WidgetIdentifyAction(Action): self.activity = None self._dialog = None - def do(self): + def do(self, **kwargs): os = ObjectStore() if os.activity: self.activity = os.activity -- cgit v0.9.1