예제 #1
0
    def __init__(self, path, text, replaceText, search, parent=None):
        QtGui.QDialog.__init__(self, parent, QtCore.Qt.Window |
                               QtCore.Qt.WindowCloseButtonHint)

        self.setWindowTitle(path)
        self.resize(700, 400)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 5)
        self.setLayout(mainLayout)

        diff = DiffWindow()

        self.path = path
        self.text = text
        self.replaceText = replaceText
        self.search = search

        a = open(path, 'r').read().splitlines()
        b = open(path, 'r').read().splitlines()
        for i in range(len(b)):
            b[i] = search.sub(replaceText, b[i])

        diffExists = diff.generateUnifiedDiff(a, b)

        if diffExists:
            mainLayout.addWidget(diff)
        else:
            message = QtGui.QMessageBox.information(
                self, "Replace", "There is nothing to replace.")
            return

        hbox = QtGui.QHBoxLayout()
        hbox.addStretch(1)
        mainLayout.addLayout(hbox)

        self.replaceButton = QtGui.QPushButton("Replace")
        self.replaceButton.clicked.connect(self.replace)
        hbox.addWidget(self.replaceButton)

        self.cancelButton = QtGui.QPushButton("Cancel")
        self.cancelButton.pressed.connect(self.close)
        hbox.addWidget(self.cancelButton)

        hbox.addStretch(1)

        self.replaced = False
        self.exec_()
예제 #2
0
    def __init__(self, path, text, replaceText, search, parent=None):
        QtGui.QDialog.__init__(
            self, parent, QtCore.Qt.Window | QtCore.Qt.WindowCloseButtonHint)

        self.setWindowTitle(path)
        self.resize(700, 400)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 5)
        self.setLayout(mainLayout)

        diff = DiffWindow()

        self.path = path
        self.text = text
        self.replaceText = replaceText
        self.search = search

        a = open(path, 'r').read().splitlines()
        b = open(path, 'r').read().splitlines()
        for i in range(len(b)):
            b[i] = search.sub(replaceText, b[i])

        diffExists = diff.generateUnifiedDiff(a, b)

        if diffExists:
            mainLayout.addWidget(diff)
        else:
            message = QtGui.QMessageBox.information(
                self, "Replace", "There is nothing to replace.")
            return

        hbox = QtGui.QHBoxLayout()
        hbox.addStretch(1)
        mainLayout.addLayout(hbox)

        self.replaceButton = QtGui.QPushButton("Replace")
        self.replaceButton.clicked.connect(self.replace)
        hbox.addWidget(self.replaceButton)

        self.cancelButton = QtGui.QPushButton("Cancel")
        self.cancelButton.pressed.connect(self.close)
        hbox.addWidget(self.cancelButton)

        hbox.addStretch(1)

        self.replaced = False
        self.exec_()