Пример #1
0
    def create_subtree_for_a_trap(self, tree, trap):  # todo: done
        """
            Create a node that display informations about a trap. Can have
            subnodes that diplay infos about some (energy, frequency
            of this trap.
        """
        # add it to the list, so it can be deleted later
        self.correspondence_index_position.append(self.nb_created)
        tree_item_for_this_trap = QTreeWidgetItem(tree)

        # get informations from the JSON file

        if trap.get("density") is not None:
            density = "{:.2e}".format(float(trap["density"]))
        else:
            density = "None"
        density_line = QLineEditWidthed(density, self.editable, "--------------")
        tree.setItemWidget(tree_item_for_this_trap, 0, density_line)
        tree.setItemWidget(tree_item_for_this_trap, 1, QLabel("at. fr."))

        """
        if trap.get("angular_frequency") is not None:
            angular_frequency = "{:.2e}".format(float(trap["angular_frequency"]))
        else:
            angular_frequency = "None"
        angular_frequency_line = QLineEditWidthed(angular_frequency, self.editable, "--------------")
        tree.setItemWidget(tree_item_for_this_trap, 1, angular_frequency_line)
        """

        # create a list that store the ids of its subnodes. see a comment in
        # ShowNewFile.__init() to see how it works.
        tree_item_for_this_trap.correspondence_index_position_energy = []
        tree_item_for_this_trap.nb_energy_created = 0
        
        if self.editable:
            # lets create a button that remove this trap
            remove_bt = QPushButton()
            remove_bt.setIcon(QIcon("ressources/trash-alt-solid.svg"))
            remove_bt.setMaximumSize(50, 50)
            remove_bt.clicked.connect(partial(self.on_click_remove_bt_trap, tree, self.nb_created))
            # add the button to the tree
            tree.setItemWidget(tree_item_for_this_trap, 6, remove_bt)
            # lets create a button that add energy to this trap
            add_energy_bt = QPushButton()
            add_energy_bt.setIcon(QIcon("ressources/plus-circle-solid.svg"))
            add_energy_bt.setMaximumSize(50, 50)
            add_energy_bt.clicked.connect(partial(self.addEnergyToATrap, tree, tree_item_for_this_trap, {}))
            # add the button to the tree
            tree.setItemWidget(tree_item_for_this_trap, 7, add_energy_bt)
        # increment the creation counter
        tree_item_for_this_trap.setExpanded(True)
        self.nb_created += 1

        return tree_item_for_this_trap