def _newItem(self, parent_item, block): """ Creates a new QTreeWidgetItem and adds it. Input: parent_item[QTreeWidgetItem]: Parent item to add the new item to block[BlockInfo]: block to add """ new_child = QTreeWidgetItem() new_child.setText(0, block.name) new_child.setToolTip(0, block.toolTip()) if parent_item == self.root_item: new_child.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable) self.addTopLevelItem(new_child) else: parent_item.addChild(new_child) new_child.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsUserCheckable) state = Qt.Unchecked if block.included: state = Qt.Checked new_child.setCheckState(0, state) self._path_item_map[block.path] = new_child self._item_block_map[new_child.__str__()] = block if block.star: new_child.setForeground(0, QBrush(QColor("blue"))) if parent_item != self.root_item: default_flags = parent_item.flags() parent_item.setFlags(default_flags | Qt.ItemIsDropEnabled) for child_name in block.children_list: child = block.children[child_name] self._newItem(new_child, child) return new_child