Package advene :: Package gui :: Package views :: Module annotationdisplay
[hide private]
[frames] | no frames]

Source Code for Module advene.gui.views.annotationdisplay

  1  # 
  2  # Advene: Annotate Digital Videos, Exchange on the NEt 
  3  # Copyright (C) 2008 Olivier Aubert <olivier.aubert@liris.cnrs.fr> 
  4  # 
  5  # Advene is free software; you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation; either version 2 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Advene is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # along with Advene; if not, write to the Free Software 
 17  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 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   
33 -def register(controller):
34 controller.register_viewclass(AnnotationDisplay)
35
36 -class AnnotationDisplay(AdhocView):
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):
42 super(AnnotationDisplay, self).__init__(controller=controller) 43 self.close_on_package_load = True 44 self.contextual_actions = () 45 self.controller=controller 46 self.annotation=annotation 47 self.no_image_pixbuf=png_to_pixbuf(controller.package.imagecache.not_yet_available_image, width=50) 48 self.widget=self.build_widget()
49
50 - def set_annotation(self, a=None):
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
57 - def set_master_view(self, v):
58 v.register_slave_view(self) 59 self.close_on_package_load = False
60
61 - def update_annotation(self, annotation=None, event=None):
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 # Autonomous view. We should close it. 69 self.close() 70 else: 71 # There is a master view, just empty the representation 72 self.set_annotation(None) 73 return True
74
75 - def refresh(self, *p):
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 # SVG autodetection does not seem to work too well. Let's help it. 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.