Пример #1
0
 def explore_tree(self, up_widget, node_plan, deep=True):
     """
     :type up_widget: QTreeWidgetItem
     :type node_plan: CalculationTree
     :type deep: bool
     :param up_widget: List widget item
     :param node_plan: node from calculation plan
     :return:
     """
     widget = QTreeWidgetItem(up_widget)
     widget.setText(0, CalculationPlan.get_el_name(node_plan.operation))
     self.setCurrentItem(widget)
     if isinstance(node_plan.operation, (MeasurementCalculate, ROIExtractionProfile, MaskCreate)):
         desc = QTreeWidgetItem(widget)
         desc.setText(0, "Description")
         if isinstance(node_plan.operation, ROIExtractionProfile):
             txt = node_plan.operation.pretty_print(analysis_algorithm_dict)
         else:
             txt = str(node_plan.operation)
         for line in txt.split("\n")[1:]:
             QTreeWidgetItem(desc, [line])
     if deep:
         for el in node_plan.children:
             self.explore_tree(widget, el)
     up_widget.setExpanded(True)
    def update_view(self, reset=False):
        if reset:
            self.clear()
            root = QTreeWidgetItem(self)
            root.setText(0, f"Root {self.calculation_plan.get_root_type()}")
            self.setCurrentItem(root)
            for el in self.calculation_plan.execution_tree.children:
                self.explore_tree(root, el, True)
            return
        self.blockSignals(True)
        root = self.get_node([])
        root.setText(0, f"Root {self.calculation_plan.get_root_type()}")
        for path, el, op_type in self.calculation_plan.get_changes():
            if op_type == PlanChanges.add_node:
                node = self.get_node(path)
                self.explore_tree(node, el, False)
            elif op_type == PlanChanges.remove_node:
                node = self.get_node(path[:-1])
                index = path[-1]
                if str(node.child(0).text(0)) == "Description":
                    index += 1
                node.removeChild(node.child(index))
            elif op_type == PlanChanges.replace_node:
                node = self.get_node(path)
                node.setText(0, CalculationPlan.get_el_name(el.operation))
                if isinstance(
                        el.operation,
                    (MeasurementCalculate, SegmentationProfile, MaskCreate)):
                    child = node.child(0)
                    child.takeChildren()
                    if isinstance(el.operation, SegmentationProfile):
                        txt = el.operation.pretty_print(
                            analysis_algorithm_dict)
                    else:
                        txt = str(el.operation)
                    for line in txt.split("\n")[1:]:
                        QTreeWidgetItem(child, [line])

            else:
                logging.error("Unknown operation {}".format(op_type))
        self.blockSignals(False)
        self.set_path()
        self.changed_node.emit()