def build_liststore(self): # Store reference to the element, string representation (title and id) # and boolean indicating wether it is imported or not store = Gtk.ListStore( GObject.TYPE_PYOBJECT, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN, GObject.TYPE_STRING, ) for l in self.differ.diff(): name, s, d, action, value = l # Note: s and d are normally Advene elements, except for # resources for which we have the path. store.append(row=[ l, labels.setdefault(name, name), "%s %s (%s)" % (helper.get_type(s), self.controller.get_title(s), getattr(s, 'id', str(s))), True, self.controller. get_title(s.type) if hasattr(s, 'type') else helper.get_type(s) ]) return store
def refresh(self, *p, **kw): def display_popup(widget, event, element): if event.button == 3: menu = advene.gui.popup.Menu(element, controller=self.controller) menu.popup() return True return False g = self.controller.gui for (w, elements) in ((self.created, g.last_created), (self.edited, g.last_edited)): w.foreach(w.remove) for e in reversed(elements): if isinstance(e, Annotation): b = AnnotationRepresentation(e, self.controller) elif isinstance(e, Relation): b = RelationRepresentation(e, self.controller) else: b = Gtk.Button("\n".join( (helper.get_type(e), self.controller.get_title(e))), use_underline=False) b.connect('clicked', (lambda i, el: self.controller.gui.edit_element(el)), e) content = getattr(e, 'content', None) if content: b.set_tooltip_text(content.data) enable_drag_source(b, e, self.controller) b.connect('button-press-event', display_popup, e) w.pack_start(b, False, True, 0) self.widget.show_all() return True
def refresh(self, *p, **kw): def display_popup(widget, event, element): if event.button == 3: menu = advene.gui.popup.Menu(element, controller=self.controller) menu.popup() return True return False g=self.controller.gui for (w, elements) in ( (self.created, g.last_created), (self.edited, g.last_edited) ): w.foreach(w.remove) for e in reversed(elements): b=gtk.Button("\n".join((helper.get_type(e), self.controller.get_title(e))), use_underline=False) b.set_alignment(0, 0) colorname=self.controller.get_element_color(e) if colorname: if config.data.os == 'win32': text=b.get_label() b.foreach(b.remove) l=gtk.Label() l.set_markup('<span background="%s">%s</span>' % (colorname, text)) l.show() b.add(l) else: style = b.modify_bg(gtk.STATE_NORMAL, name2color(colorname)) b.connect('clicked', (lambda i, el: self.controller.gui.edit_element(el)), e) content=getattr(e, 'content', None) if content: b.set_tooltip_text(content.data) enable_drag_source(b, e, self.controller) b.connect('button-press-event', display_popup, e) w.pack_start(b, expand=False) self.widget.show_all() return True
def refresh(self, *p, **kw): def display_popup(widget, event, element): if event.button == 3: menu = advene.gui.popup.Menu(element, controller=self.controller) menu.popup() return True return False g=self.controller.gui for (w, elements) in ( (self.created, g.last_created), (self.edited, g.last_edited) ): w.foreach(w.remove) for e in reversed(elements): if isinstance(e, Annotation): b = AnnotationRepresentation(e, self.controller) elif isinstance(e, Relation): b = RelationRepresentation(e, self.controller) else: b = Gtk.Button("\n".join((helper.get_type(e), self.controller.get_title(e))), use_underline=False) b.connect('clicked', (lambda i, el: self.controller.gui.edit_element(el)), e) content=getattr(e, 'content', None) if content: b.set_tooltip_text(content.data) enable_drag_source(b, e, self.controller) b.connect('button-press-event', display_popup, e) w.pack_start(b, False, True, 0) self.widget.show_all() return True
def update(self, node=None): self.node=node self.element=self.node[DetailedTreeModel.COLUMN_ELEMENT] self.label['title'].set_markup(_("%(type)s <b>%(title)s</b>\nId: %(id)s") % { 'type': helper.get_type(self.element), 'title': self.controller.get_title(self.element).replace('<', '<'), 'id': self.element.id }) self.update_preview() return True
def update(self, node=None): self.node=node self.element=self.node[DetailedTreeModel.COLUMN_ELEMENT] self.label['title'].set_markup(_("%(type)s <b>%(title)s</b>\nId: %(id)s") % { 'type': helper.get_type(self.element), 'title': self.controller.get_title(self.element).replace('<', '<'), 'id': self.element.id }) # Reset the sensitive state on apply buttons for b in self.apply_buttons: b.set_sensitive(True) return True
def build_model(self, elements): """Build the ListStore containing the data. Columns: element, content (title), type, id """ l = Gtk.ListStore(object, str, str, str) if not elements: return l for e in elements: l.append((e, self.controller.get_title(e), helper.get_type(e), getattr(e, 'id', str(e)))) return l
def update(self, node=None): self.node = node self.element = self.node self.label['title'].set_markup( _("%(type)s <b>%(title)s</b>\nId: %(id)s") % { 'type': helper.get_type(self.element), 'title': self.controller.get_title(self.element).replace('<', '<'), 'id': self.element.id }) self.update_preview() return True
def build_model(self, elements): """Build the ListStore containing the data. Columns: element, content (title), type, id """ l=gtk.ListStore(object, str, str, str) if not elements: return l for e in elements: l.append( (e, self.controller.get_title(e), helper.get_type(e), e.id) ) return l
def update(self, node=None): self.node = node self.element = self.node self.label['title'].set_markup( _("%(type)s <b>%(title)s</b>\nId: %(id)s") % { 'type': helper.get_type(self.element), 'title': self.controller.get_title(self.element).replace('<', '<'), 'id': self.element.id }) # Reset the sensitive state on apply buttons for b in self.apply_buttons: b.set_sensitive(True) return True
def build_liststore(self): # Store reference to the element, string representation (title and id) # and boolean indicating wether it is imported or not store=gtk.ListStore( gobject.TYPE_PYOBJECT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_BOOLEAN, ) for l in self.differ.diff(): name, s, d, action=l # Note: s and d are normally Advene elements, except for # resources for which we have the path. store.append(row=[ l, labels.setdefault(name, name), "%s %s (%s)" % (helper.get_type(s), self.controller.get_title(s), getattr(s, 'id', unicode(s))), True ]) return store
def build_widget(self): el = self.node.element vbox=Gtk.VBox() info = Gtk.TextView() info.set_wrap_mode(Gtk.WrapMode.WORD_CHAR) def set_text(widget, t): b=widget.get_buffer() b.delete(*b.get_bounds()) b.set_text(t) b.set_modified(False) return True info.set_text = set_text.__get__(info) sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) if isinstance(el, Package): info.set_text(_("""Package %(title)s: %(schema)s %(annotation)s in %(annotation_type)s %(relation)s in %(relation_type)s %(query)s %(view)s Description: %(description)s Annotation statistics: %(statistics)s """) % { 'title': el.title, 'schema': helper.format_element_name('schema', len(el.schemas)), 'annotation': helper.format_element_name('annotation', len(el.annotations)), 'annotation_type': helper.format_element_name('annotation_type', len(el.annotationTypes)), 'relation': helper.format_element_name('relation', len(el.relations)), 'relation_type': helper.format_element_name('relation_type', len(el.relationTypes)), 'query': helper.format_element_name('query', len(el.queries)), 'view': helper.format_element_name('view', len(el.views)), 'description': el.getMetaData(config.data.namespace_prefix['dc'], 'description'), 'statistics': helper.get_annotations_statistics(el.annotations) }) elif isinstance(el, AnnotationType): info.set_text(_("""%(type)s %(title)s\n%(statistics)s""") % ({ "type": helper.get_type(el), "title": self.controller.get_title(el), "statistics": helper.get_annotations_statistics(el.annotations) })) elif isinstance(el, Schema): info.set_text(_("""%(type)s %(title)s\n%(statistics)s""") % ({ "type": helper.get_type(el), "title": self.controller.get_title(el), "statistics": helper.get_schema_statistics(el) })) else: info.set_text(_("""%(type)s %(title)s""") % ({"type": helper.get_type(el), "title": self.controller.get_title(el)})) sw.add(info) edit_button = Gtk.Button(_("Edit")) edit_button.connect('clicked', lambda w: self.controller.gui.edit_element(el)) frame = Gtk.Expander.new(_("Metadata")) frame.set_expanded(False) self.view = EditWidget(self.node.set_config, self.node.get_config) for p in self.node.list_keys(): self.view.add_entry(p, p, "") frame.add(self.view) vbox.add(sw) if not isinstance(el, (VirtualNode, AbstractBundle)): vbox.pack_start(edit_button, False, False, 0) vbox.pack_start(frame, False, False, 0) vbox.show_all() return vbox
def build_widget(self): el = self.node.element vbox = Gtk.VBox() info = Gtk.TextView() info.set_wrap_mode(Gtk.WrapMode.WORD_CHAR) def set_text(widget, t): b = widget.get_buffer() b.delete(*b.get_bounds()) b.set_text(t) b.set_modified(False) return True info.set_text = set_text.__get__(info) sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) if isinstance(el, Package): info.set_text( _("""Package %(title)s: %(schema)s %(annotation)s in %(annotation_type)s %(relation)s in %(relation_type)s %(query)s %(view)s Description: %(description)s Annotation statistics: %(statistics)s """) % { 'title': el.title, 'schema': helper.format_element_name('schema', len(el.schemas)), 'annotation': helper.format_element_name('annotation', len( el.annotations)), 'annotation_type': helper.format_element_name('annotation_type', len(el.annotationTypes)), 'relation': helper.format_element_name('relation', len(el.relations)), 'relation_type': helper.format_element_name('relation_type', len(el.relationTypes)), 'query': helper.format_element_name('query', len(el.queries)), 'view': helper.format_element_name('view', len(el.views)), 'description': el.getMetaData(config.data.namespace_prefix['dc'], 'description'), 'statistics': helper.get_annotations_statistics(el.annotations) }) elif isinstance(el, AnnotationType): info.set_text( _("""%(type)s %(title)s\n%(statistics)s""") % ({ "type": helper.get_type(el), "title": self.controller.get_title(el), "statistics": helper.get_annotations_statistics(el.annotations) })) elif isinstance(el, Schema): info.set_text( _("""%(type)s %(title)s\n%(statistics)s""") % ({ "type": helper.get_type(el), "title": self.controller.get_title(el), "statistics": helper.get_schema_statistics(el) })) else: info.set_text( _("""%(type)s %(title)s""") % ({ "type": helper.get_type(el), "title": self.controller.get_title(el) })) sw.add(info) edit_button = Gtk.Button(_("Edit")) edit_button.connect('clicked', lambda w: self.controller.gui.edit_element(el)) frame = Gtk.Expander.new(_("Metadata")) frame.set_expanded(False) self.view = EditWidget(self.node.set_config, self.node.get_config) for p in self.node.list_keys(): self.view.add_entry(p, p, "") frame.add(self.view) vbox.add(sw) if not isinstance(el, (VirtualNode, AbstractBundle)): vbox.pack_start(edit_button, False, False, 0) vbox.pack_start(frame, False, False, 0) vbox.show_all() return vbox
def contextual_drag_begin(widget, context, element, controller): if callable(element): element=element() context._element=element if hasattr(widget, '_drag_begin'): if widget._drag_begin(widget, context): return False w=Gtk.Window(Gtk.WindowType.POPUP) w.set_decorated(False) w.get_style_context().add_class('advene_drag_icon') v=Gtk.VBox() v.get_style_context().add_class('advene_drag_icon') def get_coloured_label(t, color=None): l=Gtk.Label() #l.set_ellipsize(Pango.EllipsizeMode.END) if color is None: color='white' l.set_markup("""<span background="%s" foreground="black">%s</span>""" % (color, t.replace('<', '<'))) return l if isinstance(element, int): begin = image_new_from_pixbuf(png_to_pixbuf(controller.get_snapshot(position=element, precision=config.data.preferences['bookmark-snapshot-precision']), width=config.data.preferences['drag-snapshot-width'])) begin.get_style_context().add_class('advene_drag_icon') l=Gtk.Label() l.set_text(helper.format_time(element)) l.get_style_context().add_class('advene_drag_icon') v.pack_start(begin, False, True, 0) v.pack_start(l, False, True, 0) w.set_size_request(int(1.5 * config.data.preferences['drag-snapshot-width']), -1) elif isinstance(element, Annotation): # Pictures HBox h=Gtk.HBox() h.get_style_context().add_class('advene_drag_icon') begin = image_new_from_pixbuf(png_to_pixbuf(controller.get_snapshot(annotation=element), width=config.data.preferences['drag-snapshot-width'])) begin.get_style_context().add_class('advene_drag_icon') h.pack_start(begin, False, True, 0) # Padding h.pack_start(Gtk.HBox(), True, True, 0) end = image_new_from_pixbuf(png_to_pixbuf(controller.get_snapshot(annotation=element, position=element.fragment.end), width=config.data.preferences['drag-snapshot-width'])) end.get_style_context().add_class('advene_drag_icon') h.pack_start(end, False, True, 0) v.pack_start(h, False, True, 0) l=get_coloured_label(controller.get_title(element), controller.get_element_color(element)) l.get_style_context().add_class('advene_drag_icon') v.pack_start(l, False, True, 0) w.get_style_context().add_class('advene_drag_icon') w.set_size_request(int(2.5 * config.data.preferences['drag-snapshot-width']), -1) elif isinstance(element, AnnotationType): l=get_coloured_label(_("Annotation Type %(title)s:\n%(count)s") % { 'title': controller.get_title(element), 'count': helper.format_element_name('annotation', len(element.annotations)), }, controller.get_element_color(element)) v.pack_start(l, False, True, 0) elif isinstance(element, RelationType): l=get_coloured_label(_("Relation Type %(title)s:\n%(count)s") % { 'title': controller.get_title(element), 'count': helper.format_element_name('relation', len(element.relations)), }, controller.get_element_color(element)) v.pack_start(l, False, True, 0) else: l=get_coloured_label("%s %s" % (helper.get_type(element), controller.get_title(element)), controller.get_element_color(element)) v.pack_start(l, False, True, 0) w.add(v) w.show_all() widget._icon=w Gtk.drag_set_icon_widget(context, w, 0, 0) return True
def contextual_drag_begin(widget, context, element, controller): if callable(element): element = element() context._element = element if hasattr(widget, '_drag_begin'): if widget._drag_begin(widget, context): return False # set_icon_widget does not work on native Gtk on MacOS X if config.data.os == 'darwin' and not os.environ.get('DISPLAY'): return False # set_icon_widget is broken ATM in recent gtk on win32. elif config.data.os == 'win32': return False w = gtk.Window(gtk.WINDOW_POPUP) w.set_decorated(False) bw_style = get_color_style(w, 'black', 'white') w.set_style(bw_style) v = gtk.VBox() v.set_style(bw_style) def get_coloured_label(t, color=None): l = gtk.Label() #l.set_ellipsize(pango.ELLIPSIZE_END) if color is None: color = 'white' l.set_markup("""<span background="%s" foreground="black">%s</span>""" % (color, t.replace('<', '<'))) return l cache = controller.package.imagecache if isinstance(element, (long, int)): begin = image_new_from_pixbuf( png_to_pixbuf( cache.get(element, epsilon=config.data. preferences['bookmark-snapshot-precision']), width=config.data.preferences['drag-snapshot-width'])) begin.set_style(bw_style) l = gtk.Label() l.set_style(bw_style) l.set_text(helper.format_time(element)) l.set_style(bw_style) v.pack_start(begin, expand=False) v.pack_start(l, expand=False) w.set_style(bw_style) w.set_size_request( long(1.5 * config.data.preferences['drag-snapshot-width']), -1) elif isinstance(element, Annotation): # Pictures HBox h = gtk.HBox() h.set_style(bw_style) begin = image_new_from_pixbuf( png_to_pixbuf( cache.get(element.fragment.begin), width=config.data.preferences['drag-snapshot-width'])) begin.set_style(bw_style) h.pack_start(begin, expand=False) # Padding h.pack_start(gtk.HBox(), expand=True) end = image_new_from_pixbuf( png_to_pixbuf( cache.get(element.fragment.end), width=config.data.preferences['drag-snapshot-width'])) end.set_style(bw_style) h.pack_start(end, expand=False) v.pack_start(h, expand=False) l = get_coloured_label(controller.get_title(element), controller.get_element_color(element)) l.set_style(bw_style) v.pack_start(l, expand=False) w.set_style(bw_style) w.set_size_request( long(2.5 * config.data.preferences['drag-snapshot-width']), -1) elif isinstance(element, AnnotationType): l = get_coloured_label( _("Annotation Type %(title)s:\n%(count)s") % { 'title': controller.get_title(element), 'count': helper.format_element_name('annotation', len(element.annotations)), }, controller.get_element_color(element)) v.pack_start(l, expand=False) elif isinstance(element, RelationType): l = get_coloured_label( _("Relation Type %(title)s:\n%(count)s") % { 'title': controller.get_title(element), 'count': helper.format_element_name('relation', len(element.relations)), }, controller.get_element_color(element)) v.pack_start(l, expand=False) else: l = get_coloured_label( "%s %s" % (helper.get_type(element), controller.get_title(element)), controller.get_element_color(element)) v.pack_start(l, expand=False) w.add(v) w.show_all() widget._icon = w context.set_icon_widget(w, 0, 0) return True
def contextual_drag_begin(widget, context, element, controller): if callable(element): element=element() context._element=element if hasattr(widget, '_drag_begin'): if widget._drag_begin(widget, context): return False # set_icon_widget does not work on native Gtk on MacOS X if config.data.os == 'darwin' and not os.environ.get('DISPLAY'): return False # set_icon_widget is broken ATM in recent gtk on win32. elif config.data.os == 'win32': return False w=gtk.Window(gtk.WINDOW_POPUP) w.set_decorated(False) bw_style=get_color_style(w, 'black', 'white') w.set_style(bw_style) v=gtk.VBox() v.set_style(bw_style) def get_coloured_label(t, color=None): l=gtk.Label() #l.set_ellipsize(pango.ELLIPSIZE_END) if color is None: color='white' l.set_markup("""<span background="%s" foreground="black">%s</span>""" % (color, t.replace('<', '<'))) return l # FIXME: not multi-media compatible cache=controller.gui.imagecache if isinstance(element, (long, int)): begin=image_new_from_pixbuf(png_to_pixbuf (cache.get(element, epsilon=config.data.preferences['bookmark-snapshot-precision']), width=config.data.preferences['drag-snapshot-width'])) begin.set_style(bw_style) l=gtk.Label() l.set_style(bw_style) l.set_text(helper.format_time(element)) l.set_style(bw_style) v.pack_start(begin, expand=False) v.pack_start(l, expand=False) w.set_style(bw_style) w.set_size_request(long(1.5 * config.data.preferences['drag-snapshot-width']), -1) elif isinstance(element, Annotation): # Pictures HBox h=gtk.HBox() h.set_style(bw_style) begin=image_new_from_pixbuf(png_to_pixbuf (cache.get(element.begin), width=config.data.preferences['drag-snapshot-width'])) begin.set_style(bw_style) h.pack_start(begin, expand=False) # Padding h.pack_start(gtk.HBox(), expand=True) end=image_new_from_pixbuf(png_to_pixbuf (cache.get(element.end), width=config.data.preferences['drag-snapshot-width'])) end.set_style(bw_style) h.pack_start(end, expand=False) v.pack_start(h, expand=False) l=get_coloured_label(controller.get_title(element), controller.get_element_color(element)) l.set_style(bw_style) v.pack_start(l, expand=False) w.set_style(bw_style) w.set_size_request(long(2.5 * config.data.preferences['drag-snapshot-width']), -1) elif isinstance(element, AnnotationType): l=get_coloured_label(_("Annotation Type %(title)s:\n%(count)s") % { 'title': controller.get_title(element), 'count': helper.format_element_name('annotation', len(element.annotations)), }, controller.get_element_color(element)) v.pack_start(l, expand=False) elif isinstance(element, RelationType): l=get_coloured_label(_("Relation Type %(title)s:\n%(count)s") % { 'title': controller.get_title(element), 'count': helper.format_element_name('relation', len(element.relations)), }, controller.get_element_color(element)) v.pack_start(l, expand=False) else: l=get_coloured_label("%s %s" % (helper.get_type(element), controller.get_title(element)), controller.get_element_color(element)) v.pack_start(l, expand=False) w.add(v) w.show_all() widget._icon=w context.set_icon_widget(w, 0, 0) return True