Esempio n. 1
0
    def __init__(self, title: str, data: Dict[str, str]):

        super().__init__()

        # ─────────────────── Add content ────────────────── #

        self.setColumnCount(2)
        parent_item = QTreeWidgetItem(self, [f'{title} : '])
        parent_item.set_selectable(False)
        self.addTopLevelItem(parent_item)

        for key, val in data.items():
            item = QTreeWidgetItem(parent_item, [f'{key} : ', val])
            parent_item.addChild(item)

            # Cosmetics
            item.set_selectable(False)
            item.setTextAlignment(0, Qt.AlignRight)

        # ──────────────────── Cosmetics ─────────────────── #

        # Hide header
        self.header().hide()

        # No background
        self.setStyleSheet('background-color: transparent;')

        # Dynamically change height when widget is collapsed or expanded
        # You have to update the maximum height of the widget, based on
        # its contents. For each top item you need to get the height for
        # that row using rowHeight() and do the same recursively for
        # child items whenever the item is expanded. Also, you need to
        # overwrite the sizeHint and minimumSizeHint.
        self.expanded.connect(self.update_height)
        self.collapsed.connect(self.update_height)
 def reset_model(self, index):
     """Setup model according to current relationship_class selected in combobox.
     """
     self.class_name, self.object_class_name_list = self.relationship_class_keys[
         index]
     object_class_name_list = self.object_class_name_list.split(",")
     self.model.set_horizontal_header_labels(object_class_name_list)
     self.existing_items_model.set_horizontal_header_labels(
         object_class_name_list)
     self.new_items_model.set_horizontal_header_labels(
         object_class_name_list)
     self.relationship_ids.clear()
     for db_map in self.db_maps:
         relationship_classes = self.db_map_rel_cls_lookup[db_map]
         rel_cls = relationship_classes.get(
             (self.class_name, self.object_class_name_list), None)
         if rel_cls is None:
             continue
         for relationship in self.db_mngr.get_items_by_field(
                 db_map, "relationship", "class_id", rel_cls["id"]):
             key = tuple(relationship["object_name_list"].split(","))
             self.relationship_ids[key] = relationship["id"]
     existing_items = list(self.relationship_ids)
     self.existing_items_model.reset_model(existing_items)
     self.model.refresh()
     self.model.modelReset.emit()
     for wg in self.splitter_widgets():
         wg.deleteLater()
     for name in object_class_name_list:
         tree_widget = QTreeWidget(self)
         tree_widget.setSelectionMode(QAbstractItemView.ExtendedSelection)
         tree_widget.setColumnCount(1)
         tree_widget.setIndentation(0)
         header_item = QTreeWidgetItem([name])
         header_item.setTextAlignment(0, Qt.AlignHCenter)
         tree_widget.setHeaderItem(header_item)
         objects = self.db_mngr.get_items_by_field(self.db_map, "object",
                                                   "class_name", name)
         items = [QTreeWidgetItem([obj["name"]]) for obj in objects]
         tree_widget.addTopLevelItems(items)
         tree_widget.resizeColumnToContents(0)
         self.splitter.addWidget(tree_widget)
     sizes = [wg.columnWidth(0) for wg in self.splitter_widgets()]
     self.splitter.setSizes(sizes)
     for widget in self.hidable_widgets:
         widget.show()
Esempio n. 3
0
    def add_product(self):
        f = QTreeWidgetItem(self.parent.ui.treeProducts, [
            '15012',
            self.ui.txtQuantity.text(),
            'Unidades',
            self.ui.txtDescription.text(),
            self.ui.txtUnitPrice.text(),
            self.ui.txtTotal.text(),
        ])

        f.setTextAlignment(1, Qt.AlignRight)
        f.setTextAlignment(4, Qt.AlignRight)
        f.setTextAlignment(5, Qt.AlignRight)

        self.set_others_values()

        self.close()
Esempio n. 4
0
 def handle_dict_to_tree(self, root):
     """ change json dict to item """
     if self.tree_top_item:
         root_item = self.window.treeWidget.invisibleRootItem()
         root_item.removeChild(self.tree_top_item)
         self.tree_top_item = None
     stack = []
     item_stack = []
     current_stack = 0
     stack.append(root)
     self.total_time = root["total_time"]
     while stack:
         current = stack.pop()
         if current is None:
             current_stack = current_stack - 1
             continue
         while len(item_stack) > current_stack:
             item_stack.pop()
         item = QTreeWidgetItem(None, [
             current["function_name"],
             str(current["count"]),
             str(current["total_time"]),
             str(current["self_time"]),
             str(current["children_time"])
         ])
         current_total_time = current["total_time"]
         brush = get_brush(current_total_time, self.total_time)
         item.setBackground(0, brush)
         for column_index in [1, 2, 3, 4]:
             item.setTextAlignment(column_index, Qt.AlignRight)
             item.setBackground(column_index, brush)
             item.setFont(column_index, self.mono_space_font)
         if current_stack == 0:
             self.window.treeWidget.addTopLevelItem(item)
             self.tree_top_item = item
         else:
             item_stack[-1].addChild(item)
         item_stack.append(item)
         if "children" not in current:
             continue
         stack.append(None)
         current_stack = current_stack + 1
         for child in current["children"][::-1]:
             stack.append(child)
    def __init__(self, title: str, data: Dict[str, str]):
        """
        Init self with a title and a dictionnary of keys and values (see
        self docstring).

        :param title: The title of the disclosure tree (e.g. 'Details'
            in dEAduction's course and exercise choosers.
        :param data: The data to be displayed in the disclosure
            triangle.
        """

        super().__init__()

        # ─────────────────── Add content ────────────────── #

        self.setColumnCount(2)
        self.__parent_item = QTreeWidgetItem(self, [f'{title} : '])
        self.__parent_item.set_selectable(False)
        self.addTopLevelItem(self.__parent_item)

        for key, val in data.items():
            item = QTreeWidgetItem(self.__parent_item, [f'{key} : ', val])
            self.__parent_item.addChild(item)

            # Cosmetics
            item.set_selectable(False)
            item.setTextAlignment(0, Qt.AlignRight)

        # ──────────────────── Cosmetics ─────────────────── #

        # Hide header
        self.header().hide()

        # No background
        self.setStyleSheet('background-color: transparent;')

        # Dynamically change height when widget is collapsed or expanded
        # You have to update the maximum height of the widget, based on
        # its contents. For each top item you need to get the height for
        # that row using rowHeight() and do the same recursively for
        # child items whenever the item is expanded. Also, you need to
        # overwrite the sizeHint and minimumSizeHint.
        self.expanded.connect(self.update_height)
        self.collapsed.connect(self.update_height)
Esempio n. 6
0
 def add_list_to_view(self):
     """ add list to view """
     self.window.listWidget.invisibleRootItem().takeChildren()
     list_data = []
     for value in self.list_dict.values():
         list_data.append(value)
     for data in list_data:
         item_data = [
             data["function_name"], (data["count"]), (data["total_time"]),
             (data["self_time"]), (data["children_time"])
         ]
         item = QTreeWidgetItem(None, item_data)
         for column_index in [1, 2, 3, 4]:
             item.setTextAlignment(column_index, Qt.AlignRight)
             item.setBackground(
                 column_index,
                 get_brush(item_data[column_index], self.total_time))
             item.setFont(column_index, self.mono_space_font)
             item.setData(column_index, Qt.DisplayRole,
                          item_data[column_index])
         self.window.listWidget.addTopLevelItem(item)
     self.window.listWidget.sortItems(2, Qt.DescendingOrder)
Esempio n. 7
0
    def __init__(self):
        super(TreeWidget, self).__init__()
        self.setColumnCount(3)
        self.setColumnWidth(0, 80)
        self.setColumnWidth(1, 80)
        self.setColumnWidth(2, 80)
        self.setIndentation(0)
        self.setHeaderHidden(True)
        self.foreground_font = QFont()
        self.foreground_font.setBold(True)
        self.normal_font = QFont()
        self.normal_font.setBold(False)
        self.setExpandsOnDoubleClick(False)
        p = QTreeWidgetItem(self)
        font = QFont()
        font.setPointSize(10)
        font.setBold(True)
        p.setFont(0, font)
        p.setText(0, "父级1父级1父级1父级1父级1父级1")
        p.setIcon(0, QIcon("icons/arrow_right.png"))
        p.setFirstColumnSpanned(True)

        c = QTreeWidgetItem(p)

        c.setText(0, "子级1")
        c.setText(1, "子级2")
        c.setText(2, "子级3")
        c.setTextAlignment(0, Qt.AlignCenter)
        c.setTextAlignment(1, Qt.AlignCenter)
        c.setTextAlignment(2, Qt.AlignCenter)
        c.setData(0, Qt.UserRole, "c_00")
        c.setData(1, Qt.UserRole, "c_01")
        c.setData(2, Qt.UserRole, "c_02")

        c = QTreeWidgetItem(p)

        c.setText(0, "子级1")
        c.setText(1, "子级2")
        c.setTextAlignment(0, Qt.AlignCenter)
        c.setTextAlignment(1, Qt.AlignCenter)
        c.setData(0, Qt.UserRole, "c_03")
        c.setData(1, Qt.UserRole, "c_04")

        p.addChild(c)

        p = QTreeWidgetItem(self)
        p.setText(0, "父级2父级2父级2父级2父级2父级2")
        p.setIcon(0, QIcon("icons/arrow_right.png"))
        p.setFirstColumnSpanned(True)

        p.setFont(0, font)
        c = QTreeWidgetItem(p)

        c.setText(0, "子级2")
        c.setText(1, "子级22")
        c.setText(2, "子级23")
        c.setTextAlignment(0, Qt.AlignCenter)
        c.setTextAlignment(1, Qt.AlignCenter)
        c.setTextAlignment(2, Qt.AlignCenter)
        c.setData(0, Qt.UserRole, "c_10")
        c.setData(1, Qt.UserRole, "c_11")
        c.setData(2, Qt.UserRole, "c_12")

        p.addChild(c)
        self.itemClicked.connect(self.click)
        self.setFocusPolicy(Qt.NoFocus)
        self.setObjectName("tree")
        self.setStyleSheet(
            "#tree::item:selected{background-color:rgb(255,255,255);color:rgb(180,12,34);}"
            "#tree::item:hover{background-color:rgb(255,255,255);color:rgb(10,160,10)}"
        )
        self.setAnimated(True)
        self.setSelectionBehavior(QAbstractItemView.SelectItems)
        self.setSelectionMode(QAbstractItemView.SingleSelection)