Example #1
0
def _fill_panel(panel, content, ui, item_handler=None):
    """ Fill a page based container panel with content.
    """
    active = 0

    for index, item in enumerate(content):
        page_name = item.get_label(ui)
        if page_name == "":
            page_name = "Page %d" % index

        if isinstance(item, Group):
            if item.selected:
                active = index

            gp = _GroupPanel(item, ui, suppress_label=True)
            page = gp.control
            sub_page = gp.sub_control

            # If the result is the same type with only one page, collapse it
            # down into just the page.
            if type(sub_page) is type(panel) and sub_page.count() == 1:
                new = sub_page.getWidget(0)
                if isinstance(panel, TabPanel):
                    sub_page.remove(sub_page.getWidget(0))
                else:
                    sub_page.remove(sub_page.getWidget(0))
            elif isinstance(page, Widget):
                new = page
            else:
                new = Widget()
                new.setLayoutData(page)

            layout = new.getLayoutData()
#            if layout is not None:
#                layout.setAlignment(QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)

        else:
            new = Widget()
            layout = VerticalPanel()
            layout.setBorderWidth(0)
            item_handler(item, layout)

        # Add the content.
        if isinstance(panel, TabPanel):
            panel.add(new, page_name)
        else:
            panel.add(new)

    panel.selectTab( active )