示例#1
0
class PyCodeCheckerDialog(QDialog):
    def __init__(self, parent, textPad, codeView):
        super().__init__()

        self.mainWindow = parent
        self.textPad = textPad
        self.codeView = codeView

        palette = QPalette()
        role = QPalette.Background
        palette.setColor(role, QColor('#2c2c2c'))
        self.setGeometry(self.codeView.x() + 200, self.codeView.y(), 400, 300)
        self.setPalette(palette)

        self.setWindowTitle('Make Codestyle Check (using pyspellchecker)')
        self.initUI()

    def initUI(self):
        filename = os.path.basename(self.textPad.filename)
        vbox = QVBoxLayout()

        self.label = WhiteLabel(filename + ' :\n\n')
        self.label.setAlignment(Qt.AlignCenter)

        self.listWidget = ListWidget()

        updateButton = PushButton('Save + Update')
        updateButton.clicked.connect(self.update)
        okButton = PushButton('Ok')
        okButton.clicked.connect(self.onClose)

        hbox = QHBoxLayout()
        hbox.addWidget(updateButton)
        hbox.addWidget(okButton)

        vbox.addWidget(self.label)
        vbox.addWidget(self.listWidget)
        vbox.addLayout(hbox)

        self.setLayout(vbox)

        self.fillList()

        # signals
        self.listWidget.itemDoubleClicked.connect(self.gotoPos)

        self.show()

    def update(self):
        self.listWidget.clear()
        self.mainWindow.save()
        self.fillList()

    def fillList(self):
        filename = os.path.basename(self.textPad.filename)
        self.label.setText(filename)

        check = PyCodeChecker(filename)
        text = check.getString()
        self.lineList, self.cursorList, self.textList = check.getListFromString(
            text)

        i = 0
        for elem in self.textList:
            item = QListWidgetItem()
            try:
                text = 'Line: ' + str(self.lineList[i]) + '  Pos: ' + str(self.cursorList[i]) + \
                        '  ' + str(self.textList[i])
                item.setText(text)
                self.listWidget.addItem(item)

            except Exception as e:
                item.destroy()

            i += 1

    def gotoPos(self):
        row = self.listWidget.currentRow()

        line = self.lineList[row]
        cursor = self.cursorList[row]

        self.textPad.setSelection(
            int(line) - 1,
            int(cursor) - 1,
            int(line) - 1, int(cursor))

    def onClose(self):
        self.destroy()
示例#2
0
class FindDeadCodeDialog(QDialog):
    def __init__(self, parent, textPad, codeView):
        super().__init__()

        self.mainWindow = parent
        self.textPad = textPad
        self.codeView = codeView

        palette = QPalette()
        role = QPalette.Background
        palette.setColor(role, QColor('#2c2c2c'))
        self.setGeometry(self.codeView.x() + 200, self.codeView.y(), 400, 300)
        self.setPalette(palette)

        self.setWindowTitle('Find Dead Code (using vulture)')
        self.initUI()

    def initUI(self):
        filename = os.path.basename(self.textPad.filename)
        vbox = QVBoxLayout()

        self.label = WhiteLabel(filename + ' :\n\n')
        self.label.setAlignment(Qt.AlignCenter)

        self.listWidget = ListWidget()

        updateButton = PushButton('Save + Update')
        updateButton.clicked.connect(self.update)
        okButton = PushButton('Ok')
        okButton.clicked.connect(self.onClose)

        hbox = QHBoxLayout()
        hbox.addWidget(updateButton)
        hbox.addWidget(okButton)

        vbox.addWidget(self.label)
        vbox.addWidget(self.listWidget)
        vbox.addLayout(hbox)

        self.setLayout(vbox)

        self.fillList()

        # signals
        self.listWidget.itemDoubleClicked.connect(self.gotoPos)

        self.show()

    def update(self):
        self.listWidget.clear()
        self.mainWindow.save()
        self.fillList()

    def fillList(self):
        filename = os.path.basename(self.textPad.filename)
        self.label.setText(filename)

        text = self.textPad.text()
        deadCodeChecker = DeadCodeChecker(text)
        outputList = deadCodeChecker.getList()

        self.lineNumberList = []
        self.codeList = []

        for elem in outputList:
            textList = elem.split(' ')
            self.lineNumberList.append(textList[0])
            codeText = ''

            for elem in textList[1:]:
                codeText += ' ' + elem

            self.codeList.append(codeText)

        i = 0
        for elem in self.codeList[0:-1]:
            item = QListWidgetItem()
            text = 'Line: ' + str(self.lineNumberList[i]) + '\t-> ' + str(
                self.codeList[i])
            pos = int(self.lineNumberList[i])
            item.setText(text)
            self.listWidget.addItem(item)
            i += 1

    def gotoPos(self):
        row = self.listWidget.currentRow()
        linenumber = int(self.lineNumberList[row]) - 1

        if linenumber >= 0:

            lineText = self.textPad.text(linenumber)
            rawcode = self.codeList[row]
            code = rawcode[rawcode.find("'") + 1:rawcode.rfind("'")]

            x = self.textPad.findFirst(code,
                                       False,
                                       True,
                                       False,
                                       True,
                                       True,
                                       line=linenumber,
                                       index=0)

            self.listWidget.clearSelection()
            self.textPad.setFocus()

    def onClose(self):
        self.destroy()