def build_pixbuf(self): if self.annotation is None: pixbuf=png_to_pixbuf(self.controller.package.imagecache.not_yet_available_image, width=self.width) elif 'overlay' in self.presentation: pixbuf=overlay_svg_as_pixbuf(self.annotation.rootPackage.imagecache[self.annotation.fragment.begin], self.annotation.content.data, width=self.width) elif 'snapshot' in self.presentation: if 'timestamp' in self.presentation: pixbuf=overlay_svg_as_pixbuf(self.annotation.rootPackage.imagecache[self.annotation.fragment.begin], helper.format_time(self.annotation.fragment.begin), width=self.width) else: pixbuf=png_to_pixbuf(self.annotation.rootPackage.imagecache[self.annotation.fragment.begin], width=self.width) elif 'timestamp' in self.presentation: # Generate only a timestamp pixbuf = self.render_text(helper.format_time(self.annotation.fragment.begin)) elif 'content' in self.presentation: # Display text pixbuf = self.render_text(self.controller.get_title(self.annotation)) else: pixbuf=png_to_pixbuf(self.controller.package.imagecache.not_yet_available_image, width=self.width) pixbuf.as_html=self.as_html pixbuf._placeholder=self pixbuf._tag='span' pixbuf._attr=[] return pixbuf
def build_pixbuf(self): if self.annotation is None: pixbuf=png_to_pixbuf(self.controller.gui.imagecache.not_yet_available_image, width=self.width) elif 'overlay' in self.presentation: pixbuf=overlay_svg_as_pixbuf(self.controller.imagecache[self.annotation.media.url][self.annotation.begin], self.annotation.content.data, width=self.width) elif 'snapshot' in self.presentation: if 'timestamp' in self.presentation: pixbuf=overlay_svg_as_pixbuf(self.controller.imagecache[self.annotation.media.url][self.annotation.begin], helper.format_time(self.annotation.begin), width=self.width) else: pixbuf=png_to_pixbuf(self.controller.imagecache[self.annotation.media.url][self.annotation.begin], width=self.width) elif 'timestamp' in self.presentation: # Generate only a timestamp # FIXME: hardcoded value in viewBox is bad... We should find out the appropriate size. loader = gtk.gdk.PixbufLoader('svg') loader.write("""<svg version='1'> preserveAspectRatio="xMinYMin meet" viewBox="0 0 220 20"> <text x='0' y='10' fill="black" font-size="12" stroke="black" font-family="sans-serif"> %s </text> </svg> """ % helper.format_time(self.annotation.begin)) loader.close () pixbuf = loader.get_pixbuf () else: pixbuf=png_to_pixbuf(self.controller.gui.imagecache.not_yet_available_image, width=self.width) pixbuf.as_html=self.as_html pixbuf._placeholder=self pixbuf._tag='span' pixbuf._attr=[] return pixbuf
def refresh(self, *p): if self.annotation is None: d = { 'title': _("No annotation"), 'begin': helper.format_time(None), 'end': helper.format_time(None), 'contents': '', 'imagecontents': None } elif isinstance(self.annotation, int) or isinstance( self.annotation, long): d = { 'title': _("Current time"), 'begin': helper.format_time(self.annotation), 'end': helper.format_time(None), 'contents': '', 'imagecontents': None } elif isinstance(self.annotation, AnnotationType): col = self.controller.get_element_color(self.annotation) if col: title = '<span background="%s">Annotation Type <b>%s</b></span>' % ( col, self.controller.get_title(self.annotation)) else: title = 'Annotation Type <b>%s</b>' % self.controller.get_title( self.annotation) if len(self.annotation.annotations): b = min(a.fragment.begin for a in self.annotation.annotations) e = max(a.fragment.end for a in self.annotation.annotations) else: b = None e = None d = { 'title': title, 'begin': helper.format_time(b), 'end': helper.format_time(e), 'contents': _("Schema %(schema)s (id %(id)s)\n%(description)s\n%(stats)s") % { 'schema': self.controller.get_title(self.annotation.schema), 'id': self.annotation.id, 'description': self.annotation.getMetaData( config.data.namespace_prefix['dc'], "description") or "", 'stats': helper.get_annotations_statistics( self.annotation.annotations) }, 'imagecontents': None, } else: # FIXME: there should be a generic content handler # mechanism for basic display of various contents d = { 'id': self.annotation.id, 'begin': helper.format_time(self.annotation.fragment.begin), 'end': helper.format_time(self.annotation.fragment.end), 'duration': helper.format_time(self.annotation.fragment.duration), 'color': self.controller.get_element_color(self.annotation), } if d['color']: d['title'] = '<span background="%(color)s">Annotation <b>%(id)s</b></span> (d: %(duration)s)' % d else: d['title'] = 'Annotation <b>%(id)s</b> (d: %(duration)s)' % d svg_data = None if self.annotation.content.mimetype.startswith('image/svg'): svg_data = self.annotation.content.data elif self.annotation.content.mimetype == 'application/x-advene-zone': # Build svg data = self.annotation.content.parsed() svg_data = '''<svg xmlns='http://www.w3.org/2000/svg' version='1' viewBox="0 0 320 300" x='0' y='0' width='320' height='200'><%(shape)s style="fill:none;stroke:green;stroke-width:2;" width="%(width)s%%" height="%(height)s%%" x="%(x)s%%" y="%(y)s%%"></rect></svg>''' % data if svg_data: pixbuf = overlay_svg_as_pixbuf( self.controller.package.imagecache[ self.annotation.fragment.begin], self.annotation.content.data) d['contents'] = '' d['imagecontents'] = pixbuf elif self.annotation.content.mimetype.startswith('image/'): # Image content, other than image/svg # Load the element content loader = gtk.gdk.PixbufLoader() try: loader.write(self.annotation.content.data, len(self.annotation.content.data)) loader.close() pixbuf = loader.get_pixbuf() except gobject.GError: # The PNG data was invalid. pixbuf = gtk.gdk.pixbuf_new_from_file( config.data.advenefile( ('pixmaps', 'notavailable.png'))) d['contents'] = '' d['imagecontents'] = pixbuf else: d['contents'] = self.annotation.content.data d['imagecontents'] = None for k, v in d.iteritems(): if k == 'title': self.label[k].set_markup(v) elif k == 'imagecontents': if v is None: self.sw['imagecontents'].hide() self.sw['contents'].show() else: self.sw['imagecontents'].show_all() self.sw['contents'].hide() pixbuf = d['imagecontents'] w = self.widget.get_allocation().width - 6 width = pixbuf.get_width() height = pixbuf.get_height() if width > w and w > 0: height = 1.0 * w * height / width pixbuf = pixbuf.scale_simple(int(w), int(height), gtk.gdk.INTERP_BILINEAR) self.label['imagecontents'].set_from_pixbuf(pixbuf) else: widget = self.label.get(k) if widget is not None: widget.set_text(v) if self.annotation is None or isinstance(self.annotation, AnnotationType): self.label['image'].hide() else: if isinstance(self.annotation, int) or isinstance( self.annotation, long): b = self.annotation elif isinstance(self.annotation, Annotation): b = self.annotation.fragment.begin self.label['image'].value = b self.label['image'].show() return False
def refresh(self, *p): if self.annotation is None: d={ 'title': _("No annotation"), 'begin': helper.format_time(None), 'end': helper.format_time(None), 'contents': '', 'imagecontents': None} elif isinstance(self.annotation, int) or isinstance(self.annotation, long): d={ 'title': _("Current time"), 'begin': helper.format_time(self.annotation), 'end': helper.format_time(None), 'contents': '', 'imagecontents': None} elif isinstance(self.annotation, AnnotationType): col=self.controller.get_element_color(self.annotation) if col: title='<span background="%s">Annotation Type <b>%s</b></span>' % (col, self.controller.get_title(self.annotation)) else: title='Annotation Type <b>%s</b>' % self.controller.get_title(self.annotation) if len(self.annotation.annotations): b=min(a.fragment.begin for a in self.annotation.annotations) e=max(a.fragment.end for a in self.annotation.annotations) else: b=None e=None d={ 'title': title, 'begin': helper.format_time(b), 'end': helper.format_time(e), 'contents': _("Schema %(schema)s\n%(description)s\n%(total)s\nId: %(id)s") % { 'schema': self.controller.get_title(self.annotation.schema), 'description': self.annotation.getMetaData(config.data.namespace_prefix['dc'], "description") or "", 'total': helper.format_element_name('annotation', len(self.annotation.annotations)), 'id': self.annotation.id }, 'imagecontents': None, } else: # FIXME: there should be a generic content handler # mechanism for basic display of various contents d={ 'id': self.annotation.id, 'begin': helper.format_time(self.annotation.fragment.begin), 'end': helper.format_time(self.annotation.fragment.end), 'duration': helper.format_time(self.annotation.fragment.duration), 'color': self.controller.get_element_color(self.annotation), } if d['color']: d['title']='<span background="%(color)s">Annotation <b>%(id)s</b></span> (d: %(duration)s)' % d else: d['title']='Annotation <b>%(id)s</b> (d: %(duration)s)' % d svg_data=None if self.annotation.content.mimetype.startswith('image/svg'): svg_data=self.annotation.content.data elif self.annotation.content.mimetype == 'application/x-advene-zone': # Build svg data=self.annotation.content.parsed() svg_data='''<svg xmlns='http://www.w3.org/2000/svg' version='1' viewBox="0 0 320 300" x='0' y='0' width='320' height='200'><%(shape)s style="fill:none;stroke:green;stroke-width:2;" width="%(width)s%%" height="%(height)s%%" x="%(x)s%%" y="%(y)s%%"></rect></svg>''' % data if svg_data: pixbuf=overlay_svg_as_pixbuf(self.controller.package.imagecache[self.annotation.fragment.begin], self.annotation.content.data) d['contents']='' d['imagecontents']=pixbuf elif self.annotation.content.mimetype.startswith('image/'): # Image content, other than image/svg # Load the element content loader = gtk.gdk.PixbufLoader() try: loader.write (self.annotation.content.data, len (self.annotation.content.data)) loader.close () pixbuf = loader.get_pixbuf () except gobject.GError: # The PNG data was invalid. pixbuf=gtk.gdk.pixbuf_new_from_file(config.data.advenefile( ( 'pixmaps', 'notavailable.png' ) )) d['contents']='' d['imagecontents'] = pixbuf else: d['contents']=self.annotation.content.data d['imagecontents']=None for k, v in d.iteritems(): if k == 'title': self.label[k].set_markup(v) elif k == 'imagecontents': if v is None: self.sw['imagecontents'].hide() self.sw['contents'].show() else: self.sw['imagecontents'].show_all() self.sw['contents'].hide() pixbuf=d['imagecontents'] w=self.widget.get_allocation().width - 6 width=pixbuf.get_width() height=pixbuf.get_height() if width > w and w > 0: height = 1.0 * w * height / width pixbuf=pixbuf.scale_simple(int(w), int(height), gtk.gdk.INTERP_BILINEAR) self.label['imagecontents'].set_from_pixbuf(pixbuf) else: widget = self.label.get(k) if widget is not None: widget.set_text(v) if self.annotation is None or isinstance(self.annotation, AnnotationType): self.label['image'].hide() else: if isinstance(self.annotation, int) or isinstance(self.annotation, long): b=self.annotation elif isinstance(self.annotation, Annotation): b=self.annotation.fragment.begin self.label['image'].value = b self.label['image'].show() return False
def refresh(self, *p): if self.annotation is None: d={ 'title': _("No annotation"), 'begin': '--:--:--:--', 'end': '--:--:--:--', 'contents': '', 'imagecontents': None} elif isinstance(self.annotation, int) or isinstance(self.annotation, long): d={ 'title': _("Current time"), 'begin': helper.format_time(self.annotation), 'end': '--:--:--:--', 'contents': '', 'imagecontents': None} elif isinstance(self.annotation, AnnotationType): col=self.controller.get_element_color(self.annotation) if col: title='<span background="%s">Annotation Type <b>%s</b></span>' % (col, self.controller.get_title(self.annotation)) else: title='Annotation Type <b>%s</b>' % self.controller.get_title(self.annotation) if len(self.annotation.annotations): b=min(a.begin for a in self.annotation.annotations) e=max(a.end for a in self.annotation.annotations) else: b=None e=None d={ 'title': title, 'begin': helper.format_time(b), 'end': helper.format_time(e), 'contents': _("Schema %(schema)s\n%(description)s\n%(total)s\nId: %(id)s") % { 'schema': ",".join(self.controller.get_title(s) for s in self.annotation.my_schemas), 'description': self.annotation.description or "", 'total': helper.format_element_name('annotation', len(self.annotation.annotations)), 'id': self.annotation.id }, 'imagecontents': None, } else: # FIXME: there should be a generic content handler # mechanism for basic display of various contents col=self.controller.get_element_color(self.annotation) if col: title='<span background="%s">Annotation <b>%s</b></span>' % (col, self.annotation.id) else: title='Annotation <b>%s</b>' % self.annotation.id d={ 'title': title, 'begin': helper.format_time(self.annotation.begin), 'end': helper.format_time(self.annotation.end) } svg_data=None if self.annotation.content.mimetype.startswith('image/'): svg_data=self.annotation.content.data elif self.annotation.content.mimetype == 'application/x-advene-zone': # Build svg data=self.annotation.content.parsed() svg_data='''<svg xmlns='http://www.w3.org/2000/svg' version='1' viewBox="0 0 320 300" x='0' y='0' width='320' height='200'><%(shape)s style="fill:none;stroke:green;stroke-width:2;" width="%(width)s%%" height="%(height)s%%" x="%(x)s%%" y="%(y)s%%"></rect></svg>''' % data if svg_data: pixbuf=overlay_svg_as_pixbuf(self.controller.imagecache[self.annotation.media.url][self.annotation.begin], self.annotation.content.data) d['contents']='' d['imagecontents']=pixbuf else: d['contents']=self.annotation.content.data d['imagecontents']=None for k, v in d.iteritems(): if k == 'title': self.label[k].set_markup(v) elif k == 'imagecontents': if v is None: self.sw['imagecontents'].hide() self.sw['contents'].show() else: self.sw['imagecontents'].show_all() self.sw['contents'].hide() pixbuf=d['imagecontents'] w=self.widget.get_allocation().width - 6 width=pixbuf.get_width() height=pixbuf.get_height() if width > w and w > 0: height = 1.0 * w * height / width pixbuf=pixbuf.scale_simple(int(w), int(height), gtk.gdk.INTERP_BILINEAR) self.label['imagecontents'].set_from_pixbuf(pixbuf) else: self.label[k].set_text(v) if self.annotation is None or isinstance(self.annotation, AnnotationType): self.label['image'].hide() else: if isinstance(self.annotation, int) or isinstance(self.annotation, long): b=self.annotation elif isinstance(self.annotation, Annotation): b=self.annotation.begin self.label['image'].value = b self.label['image'].show() return False
except (ImportError, ValueError): import advene.util.ctypesrsvg as Rsvg # Advene part import advene.core.config as config from advene.gui.util import png_to_pixbuf, enable_drag_source, name2color, overlay_svg_as_pixbuf import advene.util.helper as helper from advene.model.annotation import Annotation import advene.gui.popup active_color = name2color('#fdfd4b') pixbuf_template = """<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="320pt" height="200pt" version='1' preserveAspectRatio="xMinYMin meet" viewBox='0 0 320 200'><svg:text x='50' y='100' fill="white" font-size="48" stroke="white" font-family="sans-serif">%s</svg:text></svg:svg>""" resize_pixbuf = { 'begin': overlay_svg_as_pixbuf(svg_data=pixbuf_template % 'Set begin', width=80), 'end': overlay_svg_as_pixbuf(svg_data=pixbuf_template % 'Set end', width=80), } class GenericColorButtonWidget(Gtk.DrawingArea): """ Widget emulating a color button widget """ def __init__(self, element=None, container=None): super().__init__() self.set_can_focus(True) self.element = element # If not None, it should contain a Gdk.Color # which will override the normal color