diff options
author | Andi_G <andigros72@googlemail.com> | 2011-03-10 05:02:02 (GMT) |
---|---|---|
committer | Andi_G <andigros72@googlemail.com> | 2011-03-10 05:02:02 (GMT) |
commit | 33e9c963c764c2abcf6a637c7776bc906f7c6eaf (patch) | |
tree | 18de310f99aa42b8a4989cb46fc0467f959bda1b | |
parent | 7aee3f318dc13427551d94a176346872ea67bbdb (diff) |
Added clickable annotation icons, fixed db issues
-rw-r--r-- | annoicon.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/annoicon.py b/annoicon.py new file mode 100644 index 0000000..4a30e8d --- /dev/null +++ b/annoicon.py @@ -0,0 +1,79 @@ +import logging +import time + +import gtk +from sugar.graphics import style +from sugar.graphics.xocolor import XoColor +from sugar.graphics.icon import _IconBuffer, Icon + +_logger = logging.getLogger('anno-activity') + + +class AnnoIcon(gtk.EventBox): + __gtype_name__ = 'SugarAnnoIcon' + annotation = None + _event_cb_id = None + _tooltip_cb_id = None + + def __init__(self, icon_name=None, xo_color=None, annotation=None, event_cb=None): + gtk.EventBox.__init__(self) + + self.__event_cb = event_cb + self.annotation = annotation + #self.set_size_request(20, -1) + self.set_size_request(20, 20) + # Take care of the background first + white = gtk.gdk.color_parse("white") + self.modify_bg(gtk.STATE_NORMAL, white) + + self.set_app_paintable(True) + + self._icon = Icon(icon_name=icon_name, xo_color=xo_color, + pixel_size=18) #gtk.ICON_SIZE_LARGE_TOOLBAR + #icon_size=style.SMALL_ICON_SIZE) #gtk.ICON_SIZE_LARGE_TOOLBAR + self._icon.props.has_tooltip = True + self._tooltip_cb_id = self._icon.connect('query_tooltip', self.__annotation_icon_query_tooltip_cb) + + self._event_cb_id = self.connect('event', self.__event_cb, self.annotation) + + self.add(self._icon) + self._icon.show() + self.add_events(gtk.gdk.BUTTON_PRESS_MASK) + + + def get_icon(self): + return self._icon + + + def __annotation_icon_query_tooltip_cb(self, widget, x, y, keyboard_mode, tip): + tooltip_header = self.annotation.get_note_title() + tooltip_body = self.annotation.get_note_body() + + vbox = gtk.VBox() + + l = gtk.Label('<big>%s</big>' % tooltip_header) + l.set_use_markup(True) + l.set_width_chars(40) + l.set_line_wrap(True) + vbox.pack_start(l, expand = False, fill = False) + l.show() + + l = gtk.Label('%s' % tooltip_body) + l.set_use_markup(True) + l.set_alignment(0, 0) + l.set_padding(2, 6) + l.set_width_chars(40) + l.set_line_wrap(True) + l.set_justify(gtk.JUSTIFY_FILL) + vbox.pack_start(l, expand = True, fill = True) + l.show() + + tip.set_custom(vbox) + + return True + + + def _disconnect(self): + self._icon.disconnect(self._tooltip_cb_id) + self.disconnect(self._event_cb_id) + _logger.debug('disconnecting icon: %d' % self._event_cb_id ) |