Ejemplo n.º 1
0
    def _map_treeitems(self, rootnode):
        """ rootnode: yorick_service.Nodes.Node """

        # PyQt4 is designed to add top level item alone
        rootitem = QTreeWidgetItem(self.widget)
        rootitem.setText(0, rootnode.node_name)
        self.widget.addTopLevelItem(rootitem)

        # add children widget items recursively
        def gen_child(parent, node):
            child = QTreeWidgetItem(parent)
            child.setText(0, node.node_name)

            self.item_to_node[child] = node
            node.listitem = child

            # partial to generate gen_child recurse
            list(map(partial(gen_child, child), node.children))
            return child

        # ignite recursion
        self.item_to_node.clear()
        self.item_to_node[rootitem] = rootnode

        rootitem.addChildren(
            list(map(partial(gen_child, rootitem), rootnode.children)))
Ejemplo n.º 2
0
    def add_childs_to_item(self, toplevel_item: QtWidgets.QTreeWidgetItem,
                           path: str) -> None:
        """Adds directory children to toplevel item."""
        children = []
        for fname in os.listdir(path):
            fpath = os.path.join(path, fname)
            item = QtWidgets.QTreeWidgetItem([fname])

            # Icon
            fileinfo = QtCore.QFileInfo(fpath)
            item.setIcon(0, ICON_PROVIDER.icon(fileinfo))

            if os.path.isdir(fpath):
                self.add_childs_to_item(item, fpath)

            children.append(item)

        toplevel_item.addChildren(children)
Ejemplo n.º 3
0
    def add_pak_content_to_item(self, item: QtWidgets.QTreeWidgetItem,
                                column: int) -> None:
        """Adds content of pak file to treeview."""
        fpath = self.get_path_for_item(item)

        # Add .pak file content as childs
        if fpath.endswith(".pak") and item.childCount() == 0:
            reader = PakReader(fpath)

            children = []
            for fname in reader.filenames:
                child_item = QtWidgets.QTreeWidgetItem([fname])
                fileinfo = QtCore.QFileInfo(os.path.join(fpath, fname))
                child_item.setIcon(0, ICON_PROVIDER.icon(fileinfo))

                children.append(child_item)

            item.addChildren(children)
Ejemplo n.º 4
0
Archivo: qt.py Proyecto: Qyriad/ViewSB
    def update_detail_fields(self, detail_fields):
        """ Populates the detail view with the relevant fields for the selected packet. """

        # Each table will have a root item in the details view.
        root_items = []

        for table in detail_fields:
            title = table[0]

            root = QTreeWidgetItem([title])
            children = []

            fields = table[1]

            # The usual case: a str:str dict.
            if isinstance(fields, dict):
                for key, value in fields.items():
                    children.append(
                        QTreeWidgetItem(self._stringify_list([key, value])))

            # Sometimes it'll just be a 1-column list.
            elif isinstance(fields, list):
                for item in fields:
                    children.append(
                        QTreeWidgetItem(self._stringify_list([item])))

            # Sometimes it'll just be a string, or a `bytes` instance.
            else:
                children.append(QTreeWidgetItem(self._stringify_list([fields
                                                                      ])))

            root.addChildren(children)

            # Add an empty "item" between each table.
            root_items.extend([root, QTreeWidgetItem([])])

        self.window.usb_details_tree_widget.addTopLevelItems(root_items)

        self.window.usb_details_tree_widget.expandAll()

        self.window.usb_details_tree_widget.resizeColumnToContents(0)
        self.window.usb_details_tree_widget.resizeColumnToContents(1)
Ejemplo n.º 5
0
def parse(context, xml):
    content = ET.fromstring(xml)

    for elem in content.findall('.//page_contents/'):
        # Add to element view
        elementview_item = QTreeWidgetItem()
        elementview_item.setText(0, elem.tag)

        if elem.tag == "heading":
            # Error Handling
            try:
                elem.attrib["bold"]
            except KeyError:
                elem.attrib["bold"] = False
            try:
                elem.attrib["size"]
            except KeyError:
                elem.attrib["size"] = "20"
            try:
                elem.attrib["alignment"]
            except KeyError:
                elem.attrib["alignment"] = "left"

            # Add heading
            add_heading(context,
                        text=elem.text,
                        size=elem.attrib["size"],
                        bold=elem.attrib["bold"],
                        alignment=elem.attrib["alignment"])

            # Add info to element list
            text_child = QTreeWidgetItem()
            text_child.setText(0, f'"{elem.text}"')
            text_child.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/type/text.png")))

            bold_child = QTreeWidgetItem()
            bold_child.setText(0, f"Bold: {str(elem.attrib['bold'])}")
            bold_child.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/type/bold.png")))

            size_child = QTreeWidgetItem()
            size_child.setText(0, f"Size: {str(elem.attrib['size'])}")
            size_child.setIcon(
                0,
                QIcon(
                    resource_path("./gui/assets/elements/type/font_size.png")))

            alignment_child = QTreeWidgetItem()
            alignment_child.setText(
                0, f"Alignment: {str(elem.attrib['alignment'])}")
            alignment_child.setIcon(
                0,
                QIcon(
                    resource_path("./gui/assets/elements/type/alignment.png")))

            elementview_item.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/heading.png")))
            elementview_item.addChildren(
                [text_child, bold_child, size_child, alignment_child])

        if elem.tag == "label":
            # Error Handling
            try:
                elem.attrib["bold"]
            except KeyError:
                elem.attrib["bold"] = False
            try:
                elem.attrib["size"]
            except KeyError:
                elem.attrib["size"] = "12"
            try:
                elem.attrib["alignment"]
            except KeyError:
                elem.attrib["alignment"] = "left"

            # Add Label
            add_label(context,
                      text=elem.text,
                      size=elem.attrib["size"],
                      bold=elem.attrib["bold"],
                      alignment=elem.attrib["alignment"])

            # Add info to element list
            text_child = QTreeWidgetItem()
            text_child.setText(0, f'"{elem.text}"')
            text_child.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/type/text.png")))

            bold_child = QTreeWidgetItem()
            bold_child.setText(0, f"Bold: {str(elem.attrib['bold'])}")
            bold_child.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/type/bold.png")))

            size_child = QTreeWidgetItem()
            size_child.setText(0, f"Size: {str(elem.attrib['size'])}")
            size_child.setIcon(
                0,
                QIcon(
                    resource_path("./gui/assets/elements/type/font_size.png")))

            alignment_child = QTreeWidgetItem()
            alignment_child.setText(
                0, f"Alignment: {str(elem.attrib['alignment'])}")
            alignment_child.setIcon(
                0,
                QIcon(
                    resource_path("./gui/assets/elements/type/alignment.png")))

            elementview_item.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/label.png")))
            elementview_item.addChildren(
                [text_child, bold_child, size_child, alignment_child])

        if elem.tag == "link":
            # Error Handling
            try:
                elem.attrib["href"]
            except KeyError:
                elem.attrib["href"] = ""
            try:
                elem.attrib["alignment"]
            except KeyError:
                elem.attrib["alignment"] = "left"

            # Add link
            add_link(context,
                     text=elem.text,
                     location=elem.attrib["href"],
                     alignment=elem.attrib["alignment"])

            # Add info to element list
            location_child = QTreeWidgetItem()
            location_child.setText(0, f"Location: {str(elem.attrib['href'])}")
            location_child.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/type/link.png")))

            alignment_child = QTreeWidgetItem()
            alignment_child.setText(
                0, f"Alignment: {str(elem.attrib['alignment'])}")
            alignment_child.setIcon(
                0,
                QIcon(
                    resource_path("./gui/assets/elements/type/alignment.png")))

            elementview_item.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/link.png")))
            elementview_item.addChildren([location_child, alignment_child])

        if elem.tag == "horizontal_line":
            # Add horizontal line
            add_horizontal_line(context)
            elementview_item.setIcon(
                0,
                QIcon(
                    resource_path(
                        "./gui/assets/elements/horizontal_line.png")))

        if elem.tag == "spacer":
            # Error Handling
            try:
                elem.attrib["height"]
            except KeyError:
                elem.attrib["height"] = "20"

            # Add Spacer
            add_spacer(context, height=elem.attrib["height"])

            # Add info to element view
            elementview_item.setIcon(
                0, QIcon(resource_path("./gui/assets/elements/spacer.png")))
            height_child = QTreeWidgetItem()
            height_child.setText(0, f"Height: {str(elem.attrib['height'])}")
            height_child.setIcon(
                0,
                QIcon(resource_path("./gui/assets/elements/type/height.png")))

            elementview_item.addChildren([height_child])

        context.ui.ElementList.addTopLevelItem(elementview_item)

    # print(elem)
    # print(content.find("page_header"))
    context.ui.statusbar.showMessage(f"Done!")