Ejemplo n.º 1
0
        def move():
            for i in items:
                src = str(i.toLocalFile())
                if isdir(src):
                    # If we move/copy a dir the destination must have it's name at the end
                    qdir = QtCore.QDir(src)
                    dst = join(dst, str(qdir.dirName()))
                else:
                    dst = join(currentDir, str(parent.data()))

                try:
                    shutil.move(src, dst)
                except:
                    showException('moving items', 'moving files/folders')
                    return False
            self.parent.reloadClicked()
Ejemplo n.º 2
0
 def copy():
     for i in items:
         src = str(i.toLocalFile())
         if isfile(src):
             dst = join(currentDir, str(parent.data()))
             try:
                 shutil.copy(src, dst)
             except:
                 showException('copying files', 'copying files')
                 return False
         else:
             # If we move/copy a dir the destination must have it's name at the end
             qdir = QtCore.QDir(src)
             dst = join(dst, str(qdir.dirName()))
             try:
                 shutil.copytree(src, dst)
             except:
                 showException('copying a folder', 'copying a folder')
                 return False
Ejemplo n.º 3
0
    def keyPressEvent(self, event):
        '''Handle Copy, Paste, Cut, Delete from keyboard shortcuts.'''
        # modelindexes of selected items
        items = self.selectedIndexes()
        # the list to which we save the items
        container = self.parent.mainWindow.filemanagerContainer
        if len(items) > 0:  # Copy, Cut - save the list of items to a global container, Delete
            itm = []
            # we want nice paths to selected items, as modelindexes would be useless in another folder
            for i in items:
                itm.append(str(self.model.filePath(i)))

            if event.matches(QtGui.QKeySequence.Copy):
                event.accept()
                print('copy')
                # save items to the container
                self.parent.mainWindow.filemanagerContainer = itm
                self.parent.mainWindow.filemanagerContainerType = COPY
            elif event.matches(QtGui.QKeySequence.Cut):
                event.accept()
                print('cut')
                # save items to the container
                self.parent.mainWindow.filemanagerContainer = itm
                self.parent.mainWindow.filemanagerContainerType = MOVE
            elif event.matches(QtGui.QKeySequence.Delete):
                event.accept()
                print('delete-move-to-trash / NOT IMPLEMENTED')
            else:
                event.ignore()
        if len(container) > 0:  # Paste action - copy items from global container to current directory
            if event.matches(QtGui.QKeySequence.Paste):
                event.accept()
                print('paste')
                # current folder is the destination folder
                parent = self.parent.listView.rootIndex()
                dst = str(self.model.filePath(parent))

                if self.parent.mainWindow.filemanagerContainerType == MOVE:
                    for src in container:
                        if isdir(src):
                            # If we move/copy a dir the destination must have it's name at the end
                            qdir = QtCore.QDir(src)
                            dst = join(dst, str(qdir.dirName()))
                        else:
                            dst = str(self.model.filePath(parent))

                        try:
                            shutil.move(src, dst)
                        except:
                            showException('moving items', 'moving files/folders')
                    self.parent.reloadClicked()

                if self.parent.mainWindow.filemanagerContainerType == COPY:
                    for src in container:
                        if isfile(src):
                            dst = str(self.model.filePath(parent))
                            try:
                                shutil.copy(src, dst)
                            except:
                                showException('copying files', 'copying files')
                        else:
                            # If we move/copy a dir the destination must have it's name at the end
                            qdir = QtCore.QDir(src)
                            dst = join(dst, str(qdir.dirName()))
                            try:
                                shutil.copytree(src, dst)
                            except:
                                showException('copying a folder', 'copying a folder')
                    self.parent.reloadClicked()
            else:
                event.ignore()
        else:
            event.ignore()