diff options
author | dave <drykod@gmail.com> | 2009-11-05 20:12:01 (GMT) |
---|---|---|
committer | dave <drykod@gmail.com> | 2009-11-05 20:12:01 (GMT) |
commit | ee1c56be61da79fccf7994578fd7ea2cf051f8a6 (patch) | |
tree | 7cf1e70598dd476732bf157bbb0d4242db95b863 | |
parent | 3377e4d1d0678f5112a480b46a48ffee13455e90 (diff) |
updated actions/events
-rw-r--r-- | addons/bubblemessagewimg.py | 2 | ||||
-rw-r--r-- | addons/changecolor.py | 31 | ||||
-rw-r--r-- | addons/messagebuttonnext.py | 32 | ||||
-rw-r--r-- | tutorius/overlayer.py | 12 |
4 files changed, 46 insertions, 31 deletions
diff --git a/addons/bubblemessagewimg.py b/addons/bubblemessagewimg.py index 513cc2e..1d44cdb 100644 --- a/addons/bubblemessagewimg.py +++ b/addons/bubblemessagewimg.py @@ -48,7 +48,7 @@ class BubbleMessageWImg(Action): self.imgpath = imgpath # temporary image file path - self.imgpath = "/home/dave/Pictures/Favicon_01.png" + #self.imgpath = "/home/dave/Pictures/Favicon_01.png" self.overlay = None self._bubble = None diff --git a/addons/changecolor.py b/addons/changecolor.py index cf3431c..27ae284 100644 --- a/addons/changecolor.py +++ b/addons/changecolor.py @@ -20,8 +20,8 @@ import gobject import gtk, gtk.gdk -from sugar.tutorius.actions import Action, DragWrapper -from sugar.tutorius.properties import TStringProperty, TUAMProperty, TColorProperty, TIntProperty +from sugar.tutorius.actions import Action +from sugar.tutorius.properties import TUAMProperty from sugar.tutorius.gtkutils import find_widget from sugar import profile @@ -55,14 +55,18 @@ class ChangeColor(Action): def do(self, **kwargs): """ do. - Change the color of the widaddred widget with the chosen color + Change the color of the widaddr widget with the chosen color """ if not "activity" in kwargs: - logging.debug("ACTIVITY NOT IN KWARGS **********") - + raise TypeError("activity argument is Mandatory") + # get widget instance self.wid = find_widget(kwargs["activity"], self.widaddr) + + if not self.wid: + # TODO: error + raise TypeError("widget not found") # we have to get the initial color in the sugar rc theme current_style = self.wid.rc_get_style() @@ -83,7 +87,6 @@ class ChangeColor(Action): if self._handler_id: try: - #XXX What happens if this was already triggered? #remove the timer gobject.source_remove(self._handler_id) except: @@ -91,9 +94,6 @@ class ChangeColor(Action): # modify bg color (go back to original 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): """ @@ -110,10 +110,15 @@ class ChangeColor(Action): # modify bg 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) - + + if self._handler_id: + try: + #remove the timer + gobject.source_remove(self._handler_id) + except: + pass + + # TODO: reset self._handler_id = gobject.timeout_add(self.timeout, self._timeout_cb) __action__ = { diff --git a/addons/messagebuttonnext.py b/addons/messagebuttonnext.py index f013e8d..b18119b 100644 --- a/addons/messagebuttonnext.py +++ b/addons/messagebuttonnext.py @@ -19,7 +19,6 @@ import gtk, gtk.gdk from sugar.tutorius.filters import EventFilter from sugar.tutorius.properties import TStringProperty, TArrayProperty from sugar.tutorius import overlayer -from sugar.tutorius.services import ObjectStore class MessageButtonNext(EventFilter): """ @@ -30,6 +29,9 @@ class MessageButtonNext(EventFilter): # Create the position as an array of fixed-size 2 position = TArrayProperty((0,0), 2, 2) + # Padding + padding = 40 + def __init__(self, message=None, position=None): """Constructor. @@ -41,6 +43,7 @@ class MessageButtonNext(EventFilter): if position: self.position = position else: + # TODO: to be removed when creator supports editing properties on events self.position = (300, 200) if message: @@ -53,33 +56,34 @@ class MessageButtonNext(EventFilter): """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 = ObjectStore().activity._overlayer + self.overlay = self.activity._overlayer if not self.overlay: - self.overlay = ObjectStore().activity._overlayer - - self.msgnext = None - - self.btntext = "NEXT" + self.overlay = self.activity._overlayer - self.msgnext = overlayer.MsgNext(text=self.message,btntext=self.btntext) + btntext = "NEXT" + self.msgnext = overlayer.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+40, wid_height+40) - - self.msgnext.show() + self.msgnext.set_size_request(wid_width+MessageButtonNext.padding, wid_height+MessageButtonNext.padding) # set position x, y = self.position - self.overlay.put(self.msgnext, x, y) - + 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() diff --git a/tutorius/overlayer.py b/tutorius/overlayer.py index 17734cd..78b7a3f 100644 --- a/tutorius/overlayer.py +++ b/tutorius/overlayer.py @@ -552,6 +552,7 @@ class TextBubbleWImg(gtk.Widget): context.set_source_rgb(*xo_fill_color) context.fill() + # draw/write text context.set_source_rgb(1.0, 1.0, 1.0) pangoctx = pangocairo.CairoContext(context) self._text_layout.set_markup(self.__label) @@ -569,7 +570,7 @@ class TextBubbleWImg(gtk.Widget): # paint image context.set_source_pixbuf( self.pixbuf, - int((self.allocation.width-text_size[0])/2), + int((self.allocation.width-self.imgsize[0])/2), int(self.line_width+self.padding/2)) context.paint() @@ -612,8 +613,13 @@ class TextBubbleWImg(gtk.Widget): self._text_layout.set_markup(self.__label) width, height = self._text_layout.get_pixel_size() - requisition.width = int(width+2*self.padding+self.imgsize[0]) - requisition.height = int(height+2*self.padding+self.imgsize[1]) + + max_width = width + if self.imgsize[0] > width: + max_width = self.imgsize[0] + requisition.width = int(2*self.padding+max_width) + + requisition.height = int(2*self.padding+height+self.imgsize[1]) def do_size_allocate(self, allocation): """Save zone allocated to the widget.""" |