Ejemplo n.º 1
0
 def on_entry_drop_targets_drag_data_received(self, entry, context, x, y, selection_data, info, timestamp):
         if not gtk.targets_include_uri(context.targets):
                 return
         
         uris = drop_get_uris(selection_data)
         
         if not uris:
                 return
         
         if entry.get_text():
                 mimes = [entry.get_text()]
         else:
                 mimes = []
         
         for uri in uris:
                 try:
                         mime = gio.content_type_guess(uri)
                 except:
                         mime = None
                 
                 if mime:
                         mimes.append(mime)
         
         entry.set_text(', '.join(mimes))
         self.on_entry_drop_targets_focus_out(entry, None)
         context.finish(True, False, timestamp)
         
         entry.stop_emission('drag_data_received')
Ejemplo n.º 2
0
        def on_drag_data_received(self, view, context, x, y, data, info, timestamp):   
                if not (gtk.targets_include_uri(context.targets) and data.data and self.in_bounds(x, y)):
                        return

                uris = drop_get_uris(data)
                uris.reverse()
                stop = False
                
                for uri in uris:
                        try:
                                mime = gio.content_type_guess(uri)
                        except:
                                mime = None

                        if not mime:
                                continue
                        
                        snippets = Library().from_drop_target(mime, self.language_id)
                        
                        if snippets:
                                stop = True
                                self.apply_uri_snippet(snippets[0], mime, uri)

                if stop:
                        context.finish(True, False, timestamp)
                        view.stop_emission('drag-data-received')
                        view.get_toplevel().present()
                        view.grab_focus()
Ejemplo n.º 3
0
    def on_entry_drop_targets_drag_data_received(self, entry, context, x, y,
                                                 selection_data, info,
                                                 timestamp):
        if not gtk.targets_include_uri(context.targets):
            return

        uris = drop_get_uris(selection_data)

        if not uris:
            return

        if entry.get_text():
            mimes = [entry.get_text()]
        else:
            mimes = []

        for uri in uris:
            try:
                mime = gio.content_type_guess(uri)
            except:
                mime = None

            if mime:
                mimes.append(mime)

        entry.set_text(', '.join(mimes))
        self.on_entry_drop_targets_focus_out(entry, None)
        context.finish(True, False, timestamp)

        entry.stop_emission('drag_data_received')
    def on_drag_data_received(self, view, context, x, y, data, info,
                              timestamp):
        if not (gtk.targets_include_uri(context.targets) and data.data
                and self.in_bounds(x, y)):
            return

        uris = drop_get_uris(data)
        uris.reverse()
        stop = False

        for uri in uris:
            try:
                mime = gio.content_type_guess(uri)
            except:
                mime = None

            if not mime:
                continue

            snippets = Library().from_drop_target(mime, self.language_id)

            if snippets:
                stop = True
                self.apply_uri_snippet(snippets[0], mime, uri)

        if stop:
            context.finish(True, False, timestamp)
            view.stop_emission('drag-data-received')
            view.get_toplevel().present()
            view.grab_focus()
Ejemplo n.º 5
0
        def on_tree_view_drag_motion(self, widget, context, x, y, timestamp):
                # Return False if we are dragging
                if self.dragging:
                        return False
                
                # Check uri target
                if not gtk.targets_include_uri(context.targets):
                        return False

                # Check action
                action = None
                if context.suggested_action == gdk.ACTION_COPY:
                        action = gdk.ACTION_COPY
                else:
                        for act in context.actions:
                                if act == gdk.ACTION_COPY:
                                      action = gdk.ACTION_COPY
                                      break  
                
                if action == gdk.ACTION_COPY:
                        context.drag_status(gdk.ACTION_COPY, timestamp)        
                        return True
                else:
                        return False
Ejemplo n.º 6
0
    def on_tree_view_drag_motion(self, widget, context, x, y, timestamp):
        # Return False if we are dragging
        if self.dragging:
            return False

        # Check uri target
        if not gtk.targets_include_uri(context.targets):
            return False

        # Check action
        action = None
        if context.suggested_action == gdk.ACTION_COPY:
            action = gdk.ACTION_COPY
        else:
            for act in context.actions:
                if act == gdk.ACTION_COPY:
                    action = gdk.ACTION_COPY
                    break

        if action == gdk.ACTION_COPY:
            context.drag_status(gdk.ACTION_COPY, timestamp)
            return True
        else:
            return False