Пример #1
0
class MainWindow(QMainWindow):
    def __init__(self, src, dest):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(640, 160))
        self.setWindowTitle("Copy Images")

        self.centralWidget = QWidget(self)
        self.setCentralWidget(self.centralWidget)

        self.layout = QVBoxLayout(self.centralWidget)

        self.source = QPushButton("Select src file (.txt list file of images)")
        self.layout.addWidget(self.source)
        self.source.released.connect(self.selectSource)

        self.destination = QPushButton(
            "Select dest folder to copy the images to")
        self.layout.addWidget(self.destination)
        self.destination.released.connect(self.selectDestination)

        run = QPushButton("Start copy process")
        self.layout.addWidget(run)
        run.released.connect(self.copyFiles)

        self.textOutput = QTextEdit()
        self.layout.addWidget(self.textOutput)

        self.sourcePath = None
        self.destinationPath = None

        if None != src:
            self.selectSource(src)

        if None != dest:
            self.selectDestination(dest)

        self.copyThread = copyThread(src, dest)
        self.copyThread.newText.connect(self.writeText)

    def selectSource(self, src=None):
        if src == None:
            self.sourcePath, _ = QFileDialog.getOpenFileName(
                None, 'Choose the file to work with', '',
                'Image list .txt (*.txt);; * (*.*)', '')
        else:
            self.sourcePath = src
        self.source.setText("Source: " + self.sourcePath)
        self.textOutput.append("Source selected: " + self.sourcePath)

    def selectDestination(self, dest=None):
        if dest == None:
            self.destinationPath = QFileDialog.getExistingDirectory(
                self, 'Choose the destination to copy to', '')
        else:
            self.destinationPath = dest
        self.destination.setText("Destination: " + self.destinationPath)
        self.textOutput.append("Destination: " + self.destinationPath)

    def copyFiles(self):
        if self.sourcePath is not None and self.destinationPath is not None:
            self.copyThread.sourcePath = self.sourcePath
            self.copyThread.destinationPath = self.destinationPath
            self.copyThread.start()
        else:
            self.textOutput.append(
                'Please select a source file and a destination folder.')

    def writeText(self, line):
        self.textOutput.append(line)
        self.textOutput.ensureCursorVisible()