Ejemplo n.º 1
0
    def add_node(self, parentItem, path, type):
        item = QTreeWidgetItem(parentItem)
        item.setText(0, path_leaf(path))
        buttonGroup = QButtonGroup()

        isNewFile = type is "UNTRACKED"
        isModifiedFile = type is "MODIFIED"
        isMissing = type is "MISSING"
        isDirectory = type is "DIR"

        if isNewFile:
            item.setText(1, type)
            item.setForeground(1, QBrush(QColor(0, 255, 0)))
        if isModifiedFile:
            item.setText(1, type)
            item.setForeground(1, QBrush(QColor(0, 0, 255)))
        if isMissing:
            item.setText(1, type)
            item.setForeground(1, QBrush(QColor(255, 0, 0)))
        if isDirectory:
            for i in range(self.tree.columnCount()):
                item.setBackground(i, QBrush(QColor(230, 230, 255)))

        # must keep reference to buttonGroup for its callback to work
        parent_data = self.retrieve_data(parentItem)
        if parent_data != None:
            path = os.path.join(parent_data[0], path)
        self.attach_data(item, (path, buttonGroup, type))

        for i in range(self.uncheckableColumns, self.tree.columnCount()):
            if i == self.tree.columnCount() - 7 and isMissing:
                continue # option to add not enabled for missing files
            if i == self.tree.columnCount() - 4 and isNewFile:
                continue # option to resolve not enabled for new files
            if i == self.tree.columnCount() - 3 and not isMissing:
                continue # option to stop tracking enabled only for missing files
            if i == self.tree.columnCount() - 2 and not isNewFile:
                continue # option to delete enabled only for untracked files
            if i == self.tree.columnCount() - 2 and isDirectory:
                continue # option to delete not enabled for directories, too dangerous
            button = QRadioButton()
            buttonGroup.addButton(button, i - self.uncheckableColumns) # id is the index
            button.treeItem = item
            self.tree.setItemWidget(item, i, button)

        buttonGroup.buttonClicked.connect(self.tree_item_radio_clicked)

        return item