def textview_drag_received(self, widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.get_data().decode('utf-8')) position=int(data['timestamp']) #(x, y) = self.textview.get_window()_to_buffer_coords(Gtk.TextWindowType.TEXT, # int(x), # int(y)) it=self.textview.get_iter_at_location(x, y) if it is None: return False # Check that preceding mark.value is lower m, i=self.find_preceding_mark(it.iter) if m is not None and m.value > position: self.message(_("Invalid timestamp mark")) return False m, i=self.find_following_mark(it.iter) if m is not None and m.value < position: self.message(_("Invalid timestamp mark")) return False # Create the timestamp self.create_timestamp_mark(position, it.iter) # If the drag originated from our own widgets, remove it. source=Gtk.drag_get_source_widget(context) if source in self.marks: self.remove_timestamp_mark(source) return True return False
def editor_drag_received(self, widget, context, x, y, selection, targetType, time): """Handle the drop from an annotation to the editor. """ # FIXME: Upon DND, TextView receives the event twice. Some # posts from 2004 signal the same problem, some hacks can be # found in existing code : # widget.emit_stop_by_name ("drag-data-received") # context.finish(False, False, time) # widget.stop_emission("drag-data-received") # but none of them seems to work here. Just use a basic approach, # imagining that nobody is fast enough to really do two DNDs # at the same time. # But on win32, timestamp is always 0. So we must use x and y information as well. if time == self.last_dndtime and x == self.last_x and y == self.last_y: return True self.last_dndtime=time self.last_x=x self.last_y=y x, y = self.editor.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, *widget.get_pointer()) it = self.editor.get_iter_at_location(x, y) self.editor.get_buffer().place_cursor(it) if targetType == config.data.target_type['annotation']: for uri in unicode(selection.data, 'utf8').split('\n'): source=self.controller.package.annotations.get(uri) if source is None: return True m=gtk.Menu() for (title, choice) in ( (_("Snapshot only"), ['link', 'snapshot', ]), (_("Overlayed snapshot only"), ['link', 'overlay', ]), (_("Timestamp only"), ['link', 'timestamp', ]), (_("Snapshot+timestamp"), ['link', 'snapshot', 'timestamp']), ): i=gtk.MenuItem(title) i.connect('activate', (lambda it, ann, data: self.insert_annotation_content(data, ann, focus=True)), source, choice) m.append(i) m.show_all() m.popup(None, None, None, 0, gtk.get_current_event_time()) return True elif targetType == config.data.target_type['annotation-type']: # FIXME: use splitlines() source=self.controller.package.get(unicode(selection.data, 'utf8')) # FIXME: propose various choices (insert all annotations, insert title, etc) self.editor.get_buffer().insert_at_cursor(source.title) return True elif targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.data) t=long(data['timestamp']) # FIXME: propose various choices (insert timestamp, insert snapshot, etc) self.editor.get_buffer().insert_at_cursor(helper.format_time(t)) return True else: print "Unknown target type for drop: %d" % targetType return False
def mainbox_drag_received(widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.get_data()) position=int(data['timestamp']) comment=data.get('comment', '') self.append(position, comment=comment) return True else: logger.warn("Unknown target type for drop: %d" % targetType) return False
def mainbox_drag_received(widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.get_data()) position=int(data['timestamp']) comment=data.get('comment', '') self.append(position, comment=comment) return True else: logger.warning("Unknown target type for drop: %d", targetType) return False
def remove_drag_received(widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.get_data()) position=int(data['timestamp']) w=self.get_matching_bookmark(position) if position is not None: self.bookmarks.remove(w) self.refresh() return True else: logger.warning("Unknown target type for drop: %d", targetType) return False
def drag_received(self, widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['annotation']: source_uri=unicode(selection.data, 'utf8').split('\n')[0] source=self.controller.package.annotations.get(source_uri) self.set_value(source.fragment.begin) elif targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.data) v=long(float(data['timestamp'])) self.set_value(v) else: print "Unknown target type for drop: %d" % targetType return True
def remove_drag_received(widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.get_data()) position=int(data['timestamp']) w=self.get_matching_bookmark(position) if position is not None: self.bookmarks.remove(w) self.refresh() return True else: logger.warn("Unknown target type for drop: %d" % targetType) return False
def drag_received(self, widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['annotation']: source_uri = unicode(selection.data, 'utf8').split('\n')[0] source = self.controller.package.annotations.get(source_uri) self.set_value(source.fragment.begin) elif targetType == config.data.target_type['timestamp']: data = decode_drop_parameters(selection.data) v = long(float(data['timestamp'])) self.set_value(v) else: print "Unknown target type for drop: %d" % targetType return True
def drag_received_cb(self, widget, context, x, y, selection, targetType, time): refTime = None if targetType == config.data.target_type['annotation']: sources = [ self.controller.package.annotations.get(uri) for uri in unicode(selection.data, 'utf8').split('\n') ] if sources: # use first annotation as reference refTime = sources[0].fragment.begin elif targetType == config.data.target_type['timestamp']: data = decode_drop_parameters(selection.data) refTime = long(data['timestamp']) if refTime is not None: self.set_offset(refTime - self.controller.player.current_position_value) return True
def drag_received(self, widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['annotation']: source_uri = str(selection.get_data(), 'utf8').split('\n')[0] source = self.controller.package.annotations.get(source_uri) self.set_value(source.fragment.begin) elif targetType == config.data.target_type['timestamp']: data = decode_drop_parameters(selection.get_data().decode('utf-8')) v = int(float(data['timestamp'])) self.set_value(v) else: logger.warning("Unknown target type for drop: %d", targetType) return True
def drawer_drag_received(self, widget, context, x, y, selection, targetType, time): here = None url = None title = '' if targetType == config.data.target_type['annotation']: here = self.controller.package.annotations.get( str(selection.get_data(), 'utf8').split('\n')[0]) elif targetType == config.data.target_type['view']: data = decode_drop_parameters(selection.get_data()) v = self.controller.package.get_element_by_id(data['id']) if v is None: logger.error("Cannot find view %s", data['id']) return True here = v title = self.controller.get_title(v) ctx = self.controller.build_context() root = ctx.evaluateValue('here/absolute_url') url = '%s/action/OpenView?id=%s' % (root, v.id) elif targetType == config.data.target_type['uri-list']: here = None url = str(selection.get_data().splitlines()[0], 'utf8') title = url else: # Invalid drop target return True if url is None and here is not None: ctx = self.controller.build_context(here=here) title = self.controller.get_title(here) url = ctx.evaluateValue('here/absolute_url') if url is None: logger.error("Cannot guess url after DND") return True s = self.view.drawer.clicked_shape((x, y)) if s is None: # Drop on no shape. Create one. s = self.view.drawer.shape_class() s.name = s.SHAPENAME + _(" created from ") + title s.color = self.view.defaultcolor s.set_bounds(((x, y), (x + 20, y + 20))) self.view.drawer.add_object(s) # Drop on an existing shape. Update its link attribute s.link = url s.link_label = title return False
def drawer_drag_received(self, widget, context, x, y, selection, targetType, time): here=None url=None title='' if targetType == config.data.target_type['annotation']: here=self.controller.package.get(unicode(selection.data, 'utf8').splitlines()[0]) elif targetType == config.data.target_type['view']: data=decode_drop_parameters(selection.data) v=self.controller.package.get(data['id']) if v is None: print "Cannot find view", data['id'] return True here=v title=self.controller.get_title(v) ctx=self.controller.build_context() root=ctx.evaluate('here/absolute_url') url='%s/action/OpenView?id=%s' % (root, v.id) elif targetType == config.data.target_type['uri-list']: here=None url=unicode(selection.data.splitlines()[0], 'utf8') title=url else: # Invalid drop target return True if url is None and here is not None: ctx=self.controller.build_context(here=here) title=self.controller.get_title(here) url=ctx.evaluate('here/absolute_url') if url is None: print "Cannot guess url" return True s=self.view.drawer.clicked_shape( (x, y) ) if s is None: # Drop on no shape. Create one. s = self.view.drawer.shape_class() s.name = s.SHAPENAME + _(" created from ") + title s.color = self.view.defaultcolor s.set_bounds( ( (x, y), (x+20, y+20) ) ) self.view.drawer.add_object(s) # Drop on an existing shape. Update its link attribute s.link=url s.link_label=title return False
def drag_received(self, widget, context, x, y, selection, targetType, time): if targetType == config.data.target_type['annotation']: source_uri=unicode(selection.data, 'utf8').split('\n')[0] source=self.controller.package.get(source_uri) if self.callback and not self.callback(source.begin): return True self.value = source.begin self.update_display() elif targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.data) v=long(float(data['timestamp'])) if self.callback and not self.callback(v): return True self.value=v self.update_display() else: print "Unknown target type for drop: %d" % targetType return True
def drag_received_cb(self, widget, context, x, y, selection, targetType, time): refTime = None if targetType == config.data.target_type['annotation']: sources = [ self.controller.package.annotations.get(uri) for uri in str(selection.get_data(), 'utf8').split('\n') ] if sources: # use first annotation as reference refTime = sources[0].fragment.begin elif targetType == config.data.target_type['timestamp']: data = decode_drop_parameters(selection.get_data()) refTime = int(data['timestamp']) if refTime is not None: self.set_offset(refTime - self.controller.player.current_position_value) return True
def drag_received(self, widget, context, x, y, selection, targetType, time): def create_and_open_view(sources): v=self.controller.create_static_view(elements=sources) p=get_edit_popup(v, controller=self.controller) self.add_view(p, name=_("Edit %s") % self.controller.get_title(v, max_size=40)) # FIXME: put focus on edit window return True def edit_annotation(a): p=get_edit_popup(a, controller=self.controller) self.add_view(p, name=_("Edit %s") % self.controller.get_title(a, max_size=40)) return True def edit_selection(sources): """Edit the selected elements in an edit accumulator. """ v=self.controller.gui.open_adhoc_view('editaccumulator', destination=self.location) if v is not None: for a in sources: v.edit(a) return True if targetType == config.data.target_type['adhoc-view']: data=decode_drop_parameters(selection.data) label=None view=None if 'id' in data: # Saved parametered view. Get the view itself. ident=data['id'] v=self.controller.package.get(ident) # Get the view_id if v is None: self.log(_("Cannot find the view %s") % ident) return True name=v label=v.title view=self.controller.gui.open_adhoc_view(name, label=label, destination=None) self.add_view(view, name=view.view_name) elif 'name' in data: name=data['name'] def stbv_name(v): f=v.content.as_file try: n=ET.parse(f).getroot().attrib.get('id') except: n=None f.close() return n saved=[ v for v in self.controller.package.all.views if v.content.mimetype == 'application/x-advene-adhoc-view' and stbv_name(v) == name ] if name == 'transcription': menu=gtk.Menu() i=gtk.MenuItem(_("Open a new transcription for...")) menu.append(i) sm=gtk.Menu() i.set_submenu(sm) for at in self.controller.package.all.annotation_types: title=self.controller.get_title(at) i=gtk.MenuItem(title, use_underline=False) i.connect('activate', lambda i, s, t: self.controller.gui.open_adhoc_view(name, source=s, label=t, destination=self.location), "here/all/annotation_types/%s/annotations/sorted" % at.id, title) sm.append(i) elif saved: menu=gtk.Menu() if name == 'comment': i=gtk.MenuItem(_("Create a new comment view")) else: i=gtk.MenuItem(_("Open a new view")) i.connect('activate', lambda i: self.controller.gui.open_adhoc_view(name, label=label, destination=self.location)) menu.append(i) else: menu=None if menu is not None: if saved: i=gtk.MenuItem(_("Open a saved view")) menu.append(i) sm=gtk.Menu() i.set_submenu(sm) for v in saved: i=gtk.MenuItem(v.title, use_underline=False) if name == 'comment': i.connect('activate', lambda i, vv: self.controller.gui.open_adhoc_view('edit', element=vv, destination=self.location), v) else: i.connect('activate', lambda i, vv: self.controller.gui.open_adhoc_view(vv, label=vv.title, destination=self.location), v) sm.append(i) menu.show_all() menu.popup(None, None, None, 0, gtk.get_current_event_time()) else: view=self.controller.gui.open_adhoc_view(name, label=label, destination=None) if view is not None: self.add_view(view, name=view.view_name) else: # Bug self.log("Cannot happen") return True if 'master' in data and view is not None: # A master view has been specified. Connect it to # the created view. master=self.controller.gui.get_adhoc_view_instance_from_id(data['master']) view.set_master_view(master) return True elif targetType == config.data.target_type['adhoc-view-instance']: v=self.controller.gui.get_adhoc_view_instance_from_id(selection.data) if v is not None: wid=v.widget self.add_view(v, name=v._label) if hasattr(v, 'reparent_done'): v.reparent_done() else: print "Cannot find view ", selection.data return True elif targetType == config.data.target_type['view']: v=self.controller.package.views.get(unicode(selection.data, 'utf8')) if helper.get_view_type(v) in ('static', 'dynamic'): # Edit the view. self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) else: print "Unhandled case in viewbook: targetType=view" return True elif targetType == config.data.target_type['query']: v=self.controller.package.queries.get(unicode(selection.data, 'utf8')) if v is not None: self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) return True elif targetType == config.data.target_type['schema']: v=self.controller.package.get(unicode(selection.data, 'utf8')) if v is not None: self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) return True elif targetType == config.data.target_type['relation']: v=self.controller.package.relations.get(unicode(selection.data, 'utf8')) if v is not None: self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) return True elif targetType == config.data.target_type['annotation-type']: at=self.controller.package.get(unicode(selection.data, 'utf8')) # Propose a menu to open various views for the annotation-type: menu=gtk.Menu() title=self.controller.get_title(at, max_size=40) i=gtk.MenuItem(_("Use annotation-type %s :") % title, use_underline=False) menu.append(i) for label, action in ( (_("to edit it"), lambda i :self.controller.gui.open_adhoc_view('edit', element=at, destination=self.location)), (_("to create a new static view"), lambda i: create_and_open_view([ at ])), (_("as a transcription"), lambda i: self.controller.gui.open_adhoc_view('transcription', source='here/annotation_types/%s/annotations' % at.id, destination=self.location, label=title)), (_("in a timeline"), lambda i: self.controller.gui.open_adhoc_view('timeline', elements=at.annotations, annotationtypes=[ at ], destination=self.location, label=title)), (_("as a montage"), lambda i: self.controller.gui.open_adhoc_view('montage', elements=at.annotations, destination=self.location, label=title)), (_("in a table"), lambda i: self.controller.gui.open_adhoc_view('table', elements=at.annotations, destination=self.location, label=title)), (_("in a query"), lambda i: self.controller.gui.open_adhoc_view('interactivequery', here=at, destination=self.location, label=_("Query %s") % title)), (_("in the TALES browser"), lambda i: self.controller.gui.open_adhoc_view('browser', element=at, destination=self.location, label=_("Browsing %s") % title)), ): i=gtk.MenuItem(u" " + label, use_underline=False) i.connect('activate', action) menu.append(i) menu.show_all() menu.popup(None, None, None, 0, gtk.get_current_event_time()) return True elif targetType == config.data.target_type['annotation']: sources=[ self.controller.package.get(uri) for uri in unicode(selection.data, 'utf8').split('\n') ] # Propose a menu to open various views for the annotation: menu=gtk.Menu() if len(sources) == 1: a=sources[0] title=self.controller.get_title(a, max_size=40) i=gtk.MenuItem(_("Use annotation %s :") % title, use_underline=False) menu.append(i) for label, action in ( (_("to edit it"), lambda i: edit_annotation(a)), (_("to create a new static view"), lambda i: create_and_open_view(sources)), (_("in a query"), lambda i: self.controller.gui.open_adhoc_view('interactivequery', here=a, destination=self.location, label=_("Query %s") % title)), (_("in the TALES browser"), lambda i: self.controller.gui.open_adhoc_view('browser', element=a, destination=self.location, label=_("Browse %s") % title)), (_("to display its contents"), lambda i: self.controller.gui.open_adhoc_view('annotationdisplay', annotation=a, destination=self.location, label=_("%s") % title)) , (_("as a bookmark"), lambda i: self.controller.gui.open_adhoc_view('activebookmarks', elements=[ a.begin ], destination=self.location)), ): i=gtk.MenuItem(u" " + label, use_underline=False) i.connect('activate', action) menu.append(i) def apply_query(m, q): ctx=self.controller.build_context(here=a) res, qexpr=self.controller.evaluate_query(q, context=ctx) self.controller.gui.open_adhoc_view('interactiveresult', query=q, result=res, destination=self.location) return True if self.controller.package.all.queries: sm=gtk.Menu() for q in self.controller.package.queries: i=gtk.MenuItem(self.controller.get_title(q, max_size=40), use_underline=False) i.connect('activate', apply_query, q) sm.append(i) i=gtk.MenuItem(u" " + _("as the context for the query..."), use_underline=False) i.set_submenu(sm) menu.append(i) else: title=_("Set of annotations") i=gtk.MenuItem(_("Use annotations:"), use_underline=False) menu.append(i) for label, action in ( (_("to edit them"), lambda i: edit_selection(sources)), (_("in a table"), lambda i: self.controller.gui.open_adhoc_view('table', elements=sources)), (_("to create a new static view"), lambda i: create_and_open_view(sources)), (_("as bookmarks"), lambda i: self.controller.gui.open_adhoc_view('activebookmarks', elements=[ a.begin for a in sources ], destination=self.location)), ): i=gtk.MenuItem(u" " + label, use_underline=False) i.connect('activate', action) menu.append(i) menu.show_all() menu.popup(None, None, None, 0, gtk.get_current_event_time()) return True elif targetType == config.data.target_type['timestamp']: data=decode_drop_parameters(selection.data) v=self.controller.gui.open_adhoc_view('activebookmarks', destination=self.location) v.append(long(data['timestamp']), comment=data.get('comment', '')) return True else: print "Unknown drag target received ", targetType return False
def drag_received(self, widget, context, x, y, selection, targetType, time): def create_and_open_view(sources): v = self.controller.create_static_view(elements=sources) p = get_edit_popup(v, controller=self.controller) self.add_view(p, name=_("Edit %s") % self.controller.get_title(v, max_size=40)) # FIXME: put focus on edit window return True def edit_annotation(a): p = get_edit_popup(a, controller=self.controller) self.add_view(p, name=_("Edit %s") % self.controller.get_title(a, max_size=40)) return True def edit_selection(sources): """Edit the selected elements in an edit accumulator. """ v = self.controller.gui.open_adhoc_view('editaccumulator', destination=self.location) if v is not None: for a in sources: v.edit(a) return True if targetType == config.data.target_type['adhoc-view']: data = decode_drop_parameters(selection.data) label = None view = None if 'id' in data: # Saved parametered view. Get the view itself. ident = data['id'] v = helper.get_id(self.controller.package.views, ident) # Get the view_id if v is None: self.log(_("Cannot find the view %s") % ident) return True name = v label = v.title view = self.controller.gui.open_adhoc_view(name, label=label, destination=None) if view is not None: self.add_view(view, name=view.view_name) elif 'name' in data: name = data['name'] if name == 'comment': saved = [ v for v in self.controller.package.views if helper.get_view_type(v) == 'static' and v.matchFilter['class'] == 'package' and not v.id.startswith('_') ] else: saved = [ v for v in self.controller.package.views if v.content.mimetype == 'application/x-advene-adhoc-view' and ET.parse( v.content.stream).getroot().attrib['id'] == name ] if name == 'transcription': menu = gtk.Menu() i = gtk.MenuItem(_("Open a new transcription for...")) menu.append(i) sm = gtk.Menu() i.set_submenu(sm) for at in self.controller.package.annotationTypes: title = self.controller.get_title(at, max_size=40) i = gtk.MenuItem(title, use_underline=False) i.connect( 'activate', lambda i, s, t: self.controller.gui. open_adhoc_view(name, source=s, label=t, destination=self.location), "here/annotationTypes/%s/annotations/sorted" % at.id, title) sm.append(i) elif saved: menu = gtk.Menu() if name == 'comment': i = gtk.MenuItem(_("Create a new comment view")) else: i = gtk.MenuItem(_("Open a new view")) i.connect( 'activate', lambda i: self.controller.gui.open_adhoc_view( name, label=label, destination=self.location)) menu.append(i) else: menu = None if menu is not None: if saved: i = gtk.MenuItem(_("Open a saved view")) menu.append(i) sm = gtk.Menu() i.set_submenu(sm) for v in saved: i = gtk.MenuItem(v.title, use_underline=False) if name == 'comment': i.connect( 'activate', lambda i, vv: self.controller.gui. open_adhoc_view('edit', element=vv, destination=self.location), v) else: i.connect( 'activate', lambda i, vv: self.controller.gui. open_adhoc_view(vv, label=vv.title, destination=self.location), v) sm.append(i) menu.show_all() menu.popup(None, None, None, 0, gtk.get_current_event_time()) else: view = self.controller.gui.open_adhoc_view( name, label=label, destination=None) if view is not None: self.add_view(view, name=view.view_name) else: # Bug self.log("Cannot happen") return True if 'master' in data and view is not None: # A master view has been specified. Connect it to # the created view. master = self.controller.gui.get_adhoc_view_instance_from_id( data['master']) view.set_master_view(master) return True elif targetType == config.data.target_type['adhoc-view-instance']: v = self.controller.gui.get_adhoc_view_instance_from_id( selection.data) if v is not None: wid = v.widget self.add_view(v, name=v._label) if hasattr(v, 'reparent_done'): v.reparent_done() else: print "Cannot find view ", selection.data return True elif targetType == config.data.target_type['view']: v = self.controller.package.views.get( unicode(selection.data, 'utf8')) if helper.get_view_type(v) in ('static', 'dynamic'): # Edit the view. self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) else: print "Unhandled case in viewbook: targetType=view" return True elif targetType == config.data.target_type['query']: v = self.controller.package.queries.get( unicode(selection.data, 'utf8')) if v is not None: self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) return True elif targetType == config.data.target_type['schema']: v = self.controller.package.schemas.get( unicode(selection.data, 'utf8')) if v is not None: self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) return True elif targetType == config.data.target_type['relation']: v = self.controller.package.relations.get( unicode(selection.data, 'utf8')) if v is not None: self.controller.gui.open_adhoc_view('edit', element=v, destination=self.location) return True elif targetType == config.data.target_type['annotation-type']: at = self.controller.package.annotationTypes.get( unicode(selection.data, 'utf8')) # Propose a menu to open various views for the annotation-type: menu = gtk.Menu() title = self.controller.get_title(at, max_size=40) i = gtk.MenuItem(_("Use annotation-type %s :") % title, use_underline=False) menu.append(i) for label, action in ( (_("to edit it"), lambda i: self.controller.gui.open_adhoc_view( 'edit', element=at, destination=self.location)), (_("to create a new static view"), lambda i: create_and_open_view([at])), (_("as a transcription"), lambda i: self.controller.gui.open_adhoc_view( 'transcription', source='here/annotationTypes/%s/annotations/sorted' % at. id, destination=self.location, label=title)), (_("in a timeline"), lambda i: self.controller.gui. open_adhoc_view('timeline', elements=at.annotations, annotationtypes=[at], destination=self.location, label=title)), (_("as a montage"), lambda i: self.controller.gui. open_adhoc_view('montage', elements=at.annotations, destination=self.location, label=title)), (_("in a table"), lambda i: self.controller.gui. open_adhoc_view('table', elements=at.annotations, destination=self.location, label=title)), (_("in a query"), lambda i: self.controller.gui. open_adhoc_view('interactivequery', here=at, destination=self.location, label=_("Query %s") % title)), (_("in the TALES browser"), lambda i: self.controller.gui. open_adhoc_view('browser', element=at, destination=self.location, label=_("Browsing %s") % title)), ): i = gtk.MenuItem(u" " + label, use_underline=False) i.connect('activate', action) menu.append(i) menu.show_all() menu.popup(None, None, None, 0, gtk.get_current_event_time()) return True elif targetType == config.data.target_type['annotation']: sources = [ self.controller.package.annotations.get(uri) for uri in unicode(selection.data, 'utf8').split('\n') ] # Propose a menu to open various views for the annotation: menu = gtk.Menu() if len(sources) == 1: a = sources[0] title = self.controller.get_title(a, max_size=40) i = gtk.MenuItem(_("Use annotation %s :") % title, use_underline=False) menu.append(i) for label, action in ( (_("to edit it"), lambda i: edit_annotation(a)), (_("to create a new static view"), lambda i: create_and_open_view(sources)), (_("in a query"), lambda i: self.controller.gui. open_adhoc_view('interactivequery', here=a, destination=self.location, label=_("Query %s") % title)), (_("in the TALES browser"), lambda i: self.controller.gui. open_adhoc_view('browser', element=a, destination=self.location, label=_("Browse %s") % title)), (_("to display its contents"), lambda i: self.controller. gui.open_adhoc_view('annotationdisplay', annotation=a, destination=self.location, label=_("%s") % title)), (_("as a bookmark"), lambda i: self.controller.gui. open_adhoc_view('activebookmarks', elements=[a.fragment.begin], destination=self.location)), ): i = gtk.MenuItem(u" " + label, use_underline=False) i.connect('activate', action) menu.append(i) def apply_query(m, q): ctx = self.controller.build_context(here=a) res, qexpr = self.controller.evaluate_query(q, context=ctx) self.controller.gui.open_adhoc_view( 'interactiveresult', query=q, result=res, destination=self.location) return True if self.controller.package.queries: sm = gtk.Menu() for q in self.controller.package.queries: i = gtk.MenuItem(self.controller.get_title( q, max_size=40), use_underline=False) i.connect('activate', apply_query, q) sm.append(i) i = gtk.MenuItem(u" " + _("as the context for the query..."), use_underline=False) i.set_submenu(sm) menu.append(i) else: title = _("Set of annotations") i = gtk.MenuItem(_("Use annotations:"), use_underline=False) menu.append(i) for label, action in ( (_("to edit them"), lambda i: edit_selection(sources)), (_("in a table"), lambda i: self.controller.gui. open_adhoc_view('table', elements=sources)), (_("to create a new static view"), lambda i: create_and_open_view(sources)), (_("as bookmarks"), lambda i: self.controller.gui.open_adhoc_view( 'activebookmarks', elements=[a.fragment.begin for a in sources], destination=self.location)), ): i = gtk.MenuItem(u" " + label, use_underline=False) i.connect('activate', action) menu.append(i) menu.show_all() menu.popup(None, None, None, 0, gtk.get_current_event_time()) return True elif targetType == config.data.target_type['timestamp']: data = decode_drop_parameters(selection.data) v = self.controller.gui.open_adhoc_view('activebookmarks', destination=self.location) v.append(long(data['timestamp']), comment=data.get('comment', '')) return True else: print "Unknown drag target received ", targetType return False
def editor_drag_received(self, widget, context, x, y, selection, targetType, time): """Handle the drop from an annotation to the editor. """ # FIXME: Upon DND, TextView receives the event twice. Some # posts from 2004 signal the same problem, some hacks can be # found in existing code : # widget.emit_stop_by_name ("drag-data-received") # context.finish(False, False, time) # widget.stop_emission("drag-data-received") # but none of them seems to work here. Just use a basic approach, # imagining that nobody is fast enough to really do two DNDs # at the same time. # But on win32, timestamp is always 0. So we must use x and y information as well. if time == self.last_dndtime and x == self.last_x and y == self.last_y: return True self.last_dndtime = time self.last_x = x self.last_y = y x, y = self.editor.window_to_buffer_coords(Gtk.TextWindowType.TEXT, *widget.get_pointer()) it = self.editor.get_iter_at_location(x, y) self.editor.get_buffer().place_cursor(it.iter) if targetType == config.data.target_type['annotation']: for uri in str(selection.get_data(), 'utf8').split('\n'): source = self.controller.package.annotations.get(uri) if source is None: return True m = Gtk.Menu() for (title, choice) in ( (_("Snapshot only"), [ 'link', 'snapshot', ]), (_("Overlayed snapshot only"), [ 'link', 'overlay', ]), (_("Timestamp only"), [ 'link', 'timestamp', ]), (_("Snapshot+timestamp"), ['link', 'snapshot', 'timestamp']), (_("Annotation content"), ['link', 'content']), ): i = Gtk.MenuItem(title) i.connect( 'activate', (lambda it, ann, data: self.insert_annotation_content( data, ann, focus=True)), source, choice) m.append(i) m.show_all() m.popup(None, None, None, 0, Gtk.get_current_event_time()) return True elif targetType == config.data.target_type['annotation-type']: for uri in str(selection.get_data(), 'utf8').split('\n'): source = self.controller.package.annotationTypes.get(uri) if source is None: return True m = Gtk.Menu() for (title, choice) in ( (_("as a list"), ['list']), (_("as a grid"), ['grid']), (_("as a table"), ['table']), (_("as a transcription"), ['transcription']), ): i = Gtk.MenuItem(title) i.connect( 'activate', (lambda it, at, data: self. insert_annotationtype_content(data, at, focus=True)), source, choice) m.append(i) m.show_all() m.popup(None, None, None, 0, Gtk.get_current_event_time()) return True elif targetType == config.data.target_type['timestamp']: data = decode_drop_parameters(selection.get_data()) t = int(data['timestamp']) # FIXME: propose various choices (insert timestamp, insert snapshot, etc) self.editor.get_buffer().insert_at_cursor(helper.format_time(t)) return True else: logger.warn("Unknown target type for drop: %d" % targetType) return False