Пример #1
0
    def __dropTarget__ (self, treeview, context, x, y, selection, info, etime):
        """
        @summary: Handle drop event on target treeview.
        @param treeview: TreeView that receives data.
        @param context: Drag&Drop context.
        @param x: X coordinate.
        @param y: Y coordinate.  
        @param selection: Drag&Drop selection.
        @param info: Drag&Drop information.
        @param timestamp: Timestamp when the event raise.
        """
        iter = None
        path = None
        position = gtk.TREE_VIEW_DROP_AFTER
        drop_info = None
        
        # Gets model of the TreeView
        model = treeview.get_model()
        
        # Gets drop position into TreeView
        if (treeview == self.__treeview__):
            drop_info = treeview.get_dest_row_at_pos(x, y)
        elif (treeview == self.__iconview__):
            drop_info = treeview.get_dest_item_at_pos(x, y)
        else:
            __log__.warning("Unknown view")
        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)
        
        if (selection.data == None):
            __log__.info("There is not data in the drag & drop event.")
            context.finish(False, False, etime)
        if ((info == self.TARGET_TEXT) and
            (context.action != gtk.gdk.ACTION_COPY)):
            __log__.info("It can not receive these data.")
            context.finish(False, False, etime)
        elif ((info == 0) and 
              (context.action != gtk.gdk.ACTION_MOVE)):
            __log__.info("It can not receive these data.")
            context.finish(False, False, etime)

        if (info == self.TARGET_TEXT):
            # Declare a list of files that are going to drop on target TreeView
            files = []
            # Check type target
            uris = selection.get_uris()
            
            if (uris != None):
                __log__.debug("Checking each file received")
                for uri in uris:
                    (scheme, netloc, path, params, query, fragment) = urlparse(uri)
                    if (scheme == "file"):
                        files.append(urllib.url2pathname(path))
                    else:
                        __log__.warning("URI scheme not supported. %s" % scheme)

            if (len(files) == 0):
                __log__.info("There are not valid files.")
                context.finish(False, False, etime)
                
            # Add items
            Thread(target=self.addTargetFiles,
                   args=(files, iter, position,)).start()

            context.finish(True, False, etime)
                
        elif  (info == 0):
            # Gets model of the TreeView
            model = treeview.get_model()
            paths = None
            try:
                paths = cPickle.loads(selection.data)
            except:
                __log__.warning("Data was not retrieved.")
                paths = None
            if (paths != None):
                sortTuple = self.__model__.get_sort_column_id()
                if (sortTuple[0] != None):
                    if (sortTuple[0] >= 0):
                        UIUtils.setColumnOrder(self.__model__, -2, gtk.SORT_ASCENDING, False)
                else:
                    UIUtils.setColumnOrder(self.__model__, -2, gtk.SORT_ASCENDING, False)
                self.moveTargetFiles(paths, iter, position, gtkLock=False)
            
            context.finish(True, False, etime)
        else:
            context.finish(False, False, etime)