~cando/gnome-activity-journal/tomboy-mods

« back to all changes in this revision

Viewing changes to src/supporting_widgets.py

  • Committer: Stefano Candori
  • Date: 2010-12-05 17:19:34 UTC
  • Revision ID: stefano.candori@gmail.com-20101205171934-l240v6y16mf2op6w
Implemented Tomboy's notes preview

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
import content_objects
48
48
from config import BASE_PATH, VERSION, settings, PluginManager, get_icon_path, get_data_path, bookmarker, SUPPORTED_SOURCES
49
49
from store import STORE, get_related_events_for_uri, CLIENT
50
 
from external import TRACKER
 
50
from external import TRACKER,TOMBOY
51
51
 
52
52
 
53
53
class DayLabel(gtk.DrawingArea):
704
704
            err, debug = message.parse_error()
705
705
            print "Error: %s" % err, debug
706
706
 
 
707
class TomboyPreviewTooltip(PreviewTooltip):
 
708
 
 
709
     def __init__(self):
 
710
        PreviewTooltip.__init__(self)
 
711
        self.set_border_width(2)
 
712
        self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#C0C0C0"))
 
713
        self.area = gtk.DrawingArea()
 
714
        self.area.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#fffacd"))
 
715
        self.area.connect("expose_event", self.expose)
 
716
        self.add(self.area)
 
717
 
 
718
        self.connect("hide", self._handle_hide)
 
719
        self.connect("show", self._handle_show)
 
720
 
 
721
     def replace_content(self, content):
 
722
         children = self.get_children()
 
723
         if children:
 
724
             self.remove(children[0])
 
725
             # hack to force the tooltip to have the exact same size
 
726
             # as the child image
 
727
             self.resize(1,1)
 
728
         self.add(content)
 
729
 
 
730
     def expose(self, widget, event):
 
731
        gc = self.get_style().fg_gc[gtk.STATE_NORMAL]
 
732
        text = self.text.replace(self.note_title,"\n",1)
 
733
        text = '<span foreground="#4682b4"><big><u><b>'+ self.note_title +\
 
734
               '</b></u></big></span>'+ text
 
735
        attr,text,acc = pango.parse_markup(text)
 
736
        layout = self.area.create_pango_layout(text)
 
737
        layout.set_alignment(pango.ALIGN_LEFT)
 
738
        layout.set_attributes(attr)
 
739
        x,y = layout.get_size();x/=pango.SCALE;y/=pango.SCALE
 
740
        if x > self.TOOLTIP_SIZE[1]:
 
741
            x,y = SIZE_LARGE
 
742
            self.area.set_size_request(x,y)
 
743
        else:
 
744
            x,y = self.TOOLTIP_SIZE
 
745
            self.area.set_size_request(x,y)
 
746
        self.resize(1,1)
 
747
        self.area.window.draw_layout(gc, 0, 0, layout)
 
748
 
 
749
     def preview(self, gio_file):
 
750
         uri = gio_file.uri
 
751
         self.note_title = TOMBOY.get_note_title(uri)
 
752
         self.text = TOMBOY.get_note_contents(uri)
 
753
         return True
 
754
 
 
755
     def _handle_hide(self,widget):
 
756
         self.hide()
 
757
     def _handle_show(self,widget):
 
758
         self.show_all()
 
759
 
707
760
class AnimatedImage(gtk.Image):
708
761
    animating = None
709
762
    mod = 7
1541
1594
else:
1542
1595
    VideoPreviewTooltip = None
1543
1596
    AudioPreviewTooltip = None
 
1597
if TOMBOY is not None:
 
1598
    TomboyPreviewTooltip = TomboyPreviewTooltip()
 
1599
else:
 
1600
    TomboyPreviewTooltip = None
1544
1601
StaticPreviewTooltip = StaticPreviewTooltip()
1545
1602
ContextMenu = ContextMenu()
1546
1603
SearchBox = SearchBox()