コード例 #1
0
ファイル: fill_treectrl.py プロジェクト: M40V/capsul
def add_tree_nodes(parent_item, menu, match, parent_module=""):
    """ Add the menu to tree control if match in current module name or
    child modules.

    The match is insensitive to the cast.

    Parameters
    ----------
    parent_item: QTreeWidgetItem (mandatory)
        a tree control item where we want to insert the menu
    menu: hierachic dict (mandatory)
        each key is a sub module of the module. Leafs contain a list with
        the url to the documentation.
    match: str (mandatory)
        the string used to filter the menu items
    parent_module: str (optional)
        the parent module string description ('module.sub_module')
    """
    # Go through the current module sub modules
    for module_name, child_modules in six.iteritems(menu):

        # Filtering: check if we need to add this module in the tree
        if (match == "" or match in module_name.lower()
                or search_in_menu(child_modules, match)):

            # Add the module name to the tree control
            if isinstance(child_modules, dict):
                tree_item = QtGui.QTreeWidgetItem(
                    parent_item, [module_name, "None", "None"])
                if parent_module:
                    current_module = parent_module + "." + module_name
                else:
                    current_module = module_name
                add_tree_nodes(tree_item, child_modules, match, current_module)
            else:
                tree_item = QtGui.QTreeWidgetItem(
                    parent_item,
                    [module_name, parent_module, child_modules[0]])
                tree_item.setFont(0, font)
コード例 #2
0
ファイル: board_widget.py プロジェクト: servoz/capsul
    def _fill_trees(self):
        """ Method to insert processing parameters in the class trees.
        """
        # Generate structures that contain all viewers and all processings
        # status - metainforamtion
        viewers_struct = {}
        processings_struct = []
    
        # Go through all the controller (pipeline) nodes.
        for node_name, node in six.iteritems(self.controller.nodes):

            # If the current node is a processing node
            if node_name != "" and node.node_type != "view_node":

                # First browse the current node to get processings and viewers
                process_nodes = []
                view_nodes = []
                self.browse_node(
                    node, process_nodes, view_nodes, self.controller)

                # Set process logs
                #for process_node in process_nodes:
                #    widget = LogWidget(process_node)
                #    widget.setParent(root.treeWidget())
                #    child.treeWidget().setItemWidget(child, 3, widget)

                # Fill the processing structure
                for processing_node in process_nodes:
                    processings_struct.append({
                        "name": processing_node.name,
                        "log": processing_node.process.log_file or "No log"})

                # Fill the viewer structure
                for viewer_node, pipeline in view_nodes:

                    # Create a viewer widget (a simple press button)
                    widget = ViewerWidget(viewer_node.name, pipeline, None)
                                          #self._study_config)

                    # Store the widget in the corresponding structure
                    title = self._title_for(pipeline.name)
                    if title not in viewers_struct:
                        viewers_struct[title] = []
                    viewers_struct[title].append(widget)


            # If the current node is a viewer node
            elif node.node_type == "view_node":

                # Create a viewer widget (a simple press button)
                widget = ViewerWidget(node_name, self.controller, None)
                                      #self._study_config)

                # Store the widget in the corresponding structure
                title = self._title_for(self.controller.name)
                if title not in viewers_struct:
                    viewers_struct[title] = []
                viewers_struct[title].append(widget)


        # Fill the viewer tree widget
        viewer_parent = self.viewer_tree.invisibleRootItem()
        for pipeline_title, viewer_widgets in six.iteritems(viewers_struct):

            # Create a new tree item
            viewer_child = QtGui.QTreeWidgetItem(viewer_parent)
            viewer_child.setText(0, pipeline_title)

            # Set the viewer widgets in a layout
            widget_layout = QtGui.QHBoxLayout()
            widget_layout.setSpacing(0)
            widget_layout.setSizeConstraint(QtGui.QLayout.SetMinimumSize)
            widget_layout.setContentsMargins(0, 0, 0, 0)
            widget_layout.addStretch(1)
            for widget in viewer_widgets:
                widget = QtGui.QToolButton()
                widget_layout.addWidget(widget)

            # Set the final widget tree item
            widget = QtGui.QWidget(viewer_child.treeWidget())
            widget.setLayout(widget_layout)
            viewer_child.treeWidget().setItemWidget(viewer_child, 1, widget)

        # Fill the pboard tree widget
        board_parent = self.board_tree.invisibleRootItem()
        for process_info in processings_struct:

            # Create a new tree item
            board_child = QtGui.QTreeWidgetItem(board_parent)
            board_child.setText(0, process_info["name"])
            board_child.setText(4, process_info["log"])