示例#1
0
 def get_choice_tree(self):
     '''Get the ImageJ command choices for the TreeChoice control
     
     The menu items are augmented with a third tuple entry which is
     the ModuleInfo for the command.
     '''
     global cached_choice_tree
     global cached_commands
     if cached_choice_tree is not None:
         return cached_choice_tree
     tree = []
     context = get_context()
     module_service = ij2.get_module_service(context)
     
     for module_info in module_service.getModules():
         if module_info.getMenuRoot() != "app":
             continue
         logger.info("Processing module %s" % module_info.getClassName())
         menu_path = module_info.getMenuPath()
         if menu_path is None or J.call(menu_path, "size", "()I") == 0:
             continue
         current_tree = tree
         #
         # The menu path is a collection of MenuEntry
         #
         for item in J.iterate_collection(menu_path):
             menu_entry = ij2.wrap_menu_entry(item)
             name = menu_entry.getName()
             weight = menu_entry.getWeight()
             matches = [node for node in current_tree
                        if node[0] == name]
             if len(matches) > 0:
                 current_node = matches[0]
             else:
                 current_node = [name, [], None, weight]
                 current_tree.append(current_node)
             current_tree = current_node[1]
         # mark the leaf.
         current_node[2] = module_info
         
     def sort_tree(tree):
         '''Recursively sort a tree in-place'''
         for node in tree:
             if node[1] is not None:
                 sort_tree(node[1])
         tree.sort(lambda node1, node2: cmp(node1[-1], node2[-1]))
     sort_tree(tree)
     cached_choice_tree = tree
     return cached_choice_tree
示例#2
0
    def get_choice_tree(self):
        '''Get the ImageJ command choices for the TreeChoice control
        
        The menu items are augmented with a third tuple entry which is
        the ModuleInfo for the command.
        '''
        global cached_choice_tree
        global cached_commands
        if cached_choice_tree is not None:
            return cached_choice_tree
        tree = []
        context = get_context()
        module_service = ij2.get_module_service(context)

        for module_info in module_service.getModules():
            if module_info.getMenuRoot() != "app":
                continue
            logger.info("Processing module %s" % module_info.getClassName())
            menu_path = module_info.getMenuPath()
            if menu_path is None or J.call(menu_path, "size", "()I") == 0:
                continue
            current_tree = tree
            #
            # The menu path is a collection of MenuEntry
            #
            for item in J.iterate_collection(menu_path):
                menu_entry = ij2.wrap_menu_entry(item)
                name = menu_entry.getName()
                weight = menu_entry.getWeight()
                matches = [node for node in current_tree if node[0] == name]
                if len(matches) > 0:
                    current_node = matches[0]
                else:
                    current_node = [name, [], None, weight]
                    current_tree.append(current_node)
                current_tree = current_node[1]
            # mark the leaf.
            current_node[2] = module_info

        def sort_tree(tree):
            '''Recursively sort a tree in-place'''
            for node in tree:
                if node[1] is not None:
                    sort_tree(node[1])
            tree.sort(lambda node1, node2: cmp(node1[-1], node2[-1]))

        sort_tree(tree)
        cached_choice_tree = tree
        return cached_choice_tree
示例#3
0
    def get_choice_tree(self):
        '''Get the ImageJ command choices for the TreeChoice control
        
        The menu items are augmented with a third tuple entry which is
        the ModuleInfo for the command.
        '''
        global cached_choice_tree
        if cached_choice_tree is not None:
            return cached_choice_tree
        context = RunImageJ.get_context()
        ij2_module_service = IJ2.get_module_service(context)
        tree = []

        for module_info in ij2_module_service.getModules():
            menu_path = module_info.getMenuPath()
            items = [
                IJ2.wrap_menu_entry(x) for x in J.iterate_collection(menu_path)
            ]
            if len(items) == 0:
                continue
            current_tree = tree
            for item in items:
                name = item.getName()
                weight = item.getWeight()
                matches = [node for node in current_tree if node[0] == name]
                if len(matches) > 0:
                    current_node = matches[0]
                else:
                    current_node = [name, [], module_info, weight]
                    current_tree.append(current_node)
                current_tree = current_node[1]
            # mark the leaf.
            current_node[1] = None

        def sort_tree(tree):
            '''Recursively sort a tree in-place'''
            for node in tree:
                if node[1] is not None:
                    sort_tree(node[1])
            tree.sort(lambda node1, node2: cmp(node1[-1], node2[-1]))

        sort_tree(tree)
        cached_choice_tree = tree
        return cached_choice_tree
示例#4
0
 def get_choice_tree(self):
     '''Get the ImageJ command choices for the TreeChoice control
     
     The menu items are augmented with a third tuple entry which is
     the ModuleInfo for the command.
     '''
     global cached_choice_tree
     if cached_choice_tree is not None:
         return cached_choice_tree
     context = RunImageJ.get_context()
     ij2_module_service = IJ2.get_module_service(context)
     tree = []
     
     for module_info in ij2_module_service.getModules():
         menu_path = module_info.getMenuPath()
         items = [IJ2.wrap_menu_entry(x)
                  for x in J.iterate_collection(menu_path)]
         if len(items) == 0:
             continue
         current_tree = tree
         for item in items:
             name = item.getName()
             weight = item.getWeight()
             matches = [node for node in current_tree
                        if node[0] == name]
             if len(matches) > 0:
                 current_node = matches[0]
             else:
                 current_node = [name, [], module_info, weight]
                 current_tree.append(current_node)
             current_tree = current_node[1]
         # mark the leaf.
         current_node[1] = None
     def sort_tree(tree):
         '''Recursively sort a tree in-place'''
         for node in tree:
             if node[1] is not None:
                 sort_tree(node[1])
         tree.sort(lambda node1, node2: cmp(node1[-1], node2[-1]))
     sort_tree(tree)
     cached_choice_tree = tree
     return cached_choice_tree
示例#5
0
 def test_02_06_menu_entry(self):
     svc = ij2.get_module_service(self.context)
     module_infos = svc.getModules()
     for module_info in module_infos:
         if module_info.getClassName() == \
            'imagej.core.commands.assign.AddSpecifiedNoiseToDataValues':
             menu_path = module_info.getMenuPath()
             for item in J.iterate_collection(menu_path):
                 menu_entry = ij2.wrap_menu_entry(item)
                 menu_entry.getName()
                 menu_entry.setName("Foo")
                 menu_entry.getWeight()
                 menu_entry.setWeight(5)
                 menu_entry.getMnemonic()
                 menu_entry.setMnemonic("X")
                 menu_entry.getAccelerator()
                 menu_entry.setAccelerator(None)
                 menu_entry.getIconPath()
                 menu_entry.setIconPath(None)
             break
     else:
         raise AssertionError("Could not find target module")