1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Module displaying the contents of an annotation.
20 """
21
22 import gtk
23 import gobject
24 from gettext import gettext as _
25
26 import advene.core.config as config
27 from advene.gui.views import AdhocView
28 import advene.util.helper as helper
29 from advene.gui.util import png_to_pixbuf
30
31 name="Annotation display plugin"
32
35
37 view_name = _("AnnotationDisplay")
38 view_id = 'annotationdisplay'
39 tooltip = _("Display the contents of an annotation")
40
41 - def __init__(self, controller=None, parameters=None, annotation=None):
49
51 """This method takes either an annotation, a time value or None as parameter.
52 """
53 self.annotation=a
54 self.refresh()
55 return True
56
60
62 if annotation != self.annotation:
63 return True
64 if event == 'AnnotationEditEnd':
65 self.refresh()
66 elif event == 'AnnotationDelete':
67 if self.master_view is None:
68
69 self.close()
70 else:
71
72 self.set_annotation(None)
73 return True
74
76 if self.annotation is None:
77 d={ 'title': _("No annotation"),
78 'begin': '--:--:--:--',
79 'end': '--:--:--:--',
80 'contents': '',
81 'imagecontents': None}
82 elif isinstance(self.annotation, int) or isinstance(self.annotation, long):
83 d={ 'title': _("Current time"),
84 'begin': helper.format_time(self.annotation),
85 'end': '--:--:--:--',
86 'contents': '',
87 'imagecontents': None}
88 else:
89 col=self.controller.get_element_color(self.annotation)
90 if col:
91 title='<span background="%s">Annotation <b>%s</b></span>' % (col, self.annotation.id)
92 else:
93 title='Annotation <b>%s</b>' % self.annotation.id
94 d={ 'title': title,
95 'begin': helper.format_time(self.annotation.fragment.begin),
96 'end': helper.format_time(self.annotation.fragment.end) }
97 if self.annotation.content.mimetype.startswith('image/'):
98
99 if 'svg' in self.annotation.content.mimetype:
100 try:
101 loader = gtk.gdk.PixbufLoader('svg')
102 except Exception, e:
103 print "Unable to load the SVG pixbuf loader: ", str(e)
104 loader=None
105 else:
106 loader = gtk.gdk.PixbufLoader()
107 if loader is not None:
108 try:
109 loader.write (self.annotation.content.data)
110 loader.close ()
111 p = loader.get_pixbuf ()
112 width = p.get_width()
113 height = p.get_height()
114 pixbuf=png_to_pixbuf (self.controller.package.imagecache[self.