Exemplo n.º 1
0
    def _updateDataTree(self):
        def createClassNode(classObj):
            """ Add the object class to hierarchy and 
            any needed subclass. """
            className = classObj.__name__
            classNode = classesGraph.getNode(className)

            if not classNode:
                classNode = classesGraph.createNode(className)
                if className != 'EMObject' and classObj.__bases__:
                    baseClass = classObj.__bases__[0]
                    for b in classObj.__bases__:
                        if b.__name__ == 'EMObject':
                            baseClass = b
                            break
                    parent = createClassNode(baseClass)
                    parent.addChild(classNode)
                classNode.count = 0

            return classNode

        classesGraph = Graph()

        self.dataTree.clear()
        for node in self._dataGraph.getNodes():
            if node.pointer:
                classNode = createClassNode(node.pointer.get().getClass())
                classNode.count += 1

        populateTree(self.dataTree, classesGraph.getRootNodes())
Exemplo n.º 2
0
 def _updateDataTree(self):
         
     def createClassNode(classObj):
         """ Add the object class to hierarchy and 
         any needed subclass. """
         className = classObj.__name__
         classNode = classesGraph.getNode(className)
         
         if not classNode:
             classNode = classesGraph.createNode(className)
             if className != 'EMObject' and classObj.__bases__:
                 baseClass = classObj.__bases__[0]
                 for b in classObj.__bases__:
                     if b.__name__ == 'EMObject':
                         baseClass = b
                         break
                 parent = createClassNode(baseClass)
                 parent.addChild(classNode)
             classNode.count = 0
             
         return classNode
         
     classesGraph = Graph()
     
     self.dataTree.clear()
     for node in self._dataGraph.getNodes():
         if node.pointer:
             classNode = createClassNode(node.pointer.get().getClass())
             classNode.count += 1
     
     populateTree(self.dataTree, classesGraph.getRootNodes())
Exemplo n.º 3
0
 def example2():
     avg = '%03d@/home/josem/Scipion/projects/analu_MCM/Runs/SpiderProtClassifyWard4236/averages.stk'
     name2 = "class_%03d"
     path = '%d@/home/josem/Scipion/projects/analu_MCM/Runs/XmippProtCL2D4394/extra/level_%02d/classes_sorted.stk'
     name = 'level_%02d_%02d'
     
     def getInfo(level, classNo):
         return name % (level, classNo), path % (classNo, level)
     
     def getInfo2(level, classNo):
         return name2 % classNo, avg % classNo
     
     n, p = getInfo2(0, 1)
     g = Graph(rootName=n)
     a = g.getRoot()
     a.path = p
     
     def addChilds(node, nodeNumber, level):
         imgNo = nodeNumber * 2 
         for off in [0, 1]:
             n, p = getInfo2(level+1, imgNo + off)
             b = g.createNode(n)
             b.path = p
             node.addChild(b)
             if level < maxLevel - 2:
                 addChilds(b, imgNo + off, level + 1)
                     
         
     addChilds(a, 1, 0)
         
     lt = LevelTree(g)
     lt.DY = 135
     lt.setCanvas(canvas)
     lt.paint(createNode)
Exemplo n.º 4
0
 def example1():
     """ Display a very simple graph: A, B and C. """
     g = Graph(rootName='A')
     a = g.getRoot()
     b = g.createNode('B')
     c = g.createNode('C')
     a.addChild(b, c)
     lt = LevelTree(g)
     lt.setCanvas(canvas)
     #lt.paint(createNode, createEdge)
     lt.paint()
Exemplo n.º 5
0
def getGraphClassesNode(project):
    from pyworkflow.utils.graph import Graph
    classesGraph = Graph()
    
    # Method to create class nodes
    def createClassNode(classObj):
        """ Add the object class to hierarchy and 
        any needed subclass. """
        className = classObj.__name__
        classNode = classesGraph.getNode(className)
        
        if not classNode:
            classNode = classesGraph.createNode(className)
            if className != 'EMObject' and classObj.__bases__:
                baseClass = classObj.__bases__[0]
                for b in classObj.__bases__:
                    if b.__name__ == 'EMObject':
                        baseClass = b
                        break
                parent = createClassNode(baseClass)
                parent.addChild(classNode)
            classNode.count = 0
        return classNode
    
    g = project.getSourceGraph()

    for node in g.getNodes():
        id = node.getName()
        if id != 'PROJECT':
            obj = project.mapper.selectById(id)
            classNode = createClassNode(obj.getClass())
            classNode.count += 1
    
    return classesGraph
Exemplo n.º 6
0
 def _createDataTree(self, parent, bgColor):
     """Create a tree on the left panel to store how 
     many object are from each type and the hierarchy.
     """
     self.style.configure("W.Treeview", background=Color.LIGHT_GREY_COLOR, borderwidth=0)
     tree = Tree(parent, show='tree', style='W.Treeview')
     tree.column('#0', minwidth=300)
     tree.tag_configure('protocol', image=self.getImage('python_file.gif'))
     tree.tag_configure('protocol_base', image=self.getImage('class_obj.gif'))
     f = tkFont.Font(family='helvetica', size='10', weight='bold')
     tree.tag_configure('non-empty', font=f)
     tree.grid(row=0, column=0, sticky='news')
     # Populate the tree
     self.protTreeItems = {}
     
     classesGraph = Graph()
     
     def createClassNode(classObj):
         """ Add the object class to hierarchy and 
         any needed subclass. """
         className = classObj.__name__
         classNode = classesGraph.getNode(className)
         
         if not classNode:
             classNode = classesGraph.createNode(className)
             if className != 'EMObject' and classObj.__bases__:
                 baseClass = classObj.__bases__[0]
                 for b in classObj.__bases__:
                     if b.__name__ == 'EMObject':
                         baseClass = b
                         break
                 parent = createClassNode(baseClass)
                 parent.addChild(classNode)
             classNode.count = 0
             
         return classNode
         
     for node in self._dataGraph.getNodes():
         if node.object:
             classNode = createClassNode(node.object.getClass())
             classNode.count += 1
     
     populateTree(tree, classesGraph.getRootNodes())
     return tree
Exemplo n.º 7
0
    def visualizeClasses(self, e=None):
        classTemplate = "class_%03d"
        averages = '%03d@' + self.protocol._getFileName('averages')

        def getInfo2(level, classNo):
            return classTemplate % classNo, averages % classNo

        node = self.protocol.buildDendrogram(writeAverages=False)

        g = Graph(root=node)
        self.graph = g

        self.win = Window("Select classes",
                          self.formWindow,
                          minsize=(1000, 600))
        root = self.win.root
        canvas = Canvas(root)
        canvas.grid(row=0, column=0, sticky='nsew')
        root.grid_columnconfigure(0, weight=1)
        root.grid_rowconfigure(0, weight=1)

        self.buttonframe = tk.Frame(root)
        self.buttonframe.grid(row=2, column=0, columnspan=2)
        self.win.createCloseButton(self.buttonframe).grid(row=0,
                                                          column=0,
                                                          sticky='n',
                                                          padx=5,
                                                          pady=5)
        saveparticlesbtn = HotButton(self.buttonframe,
                                     "Particles",
                                     Icon.PLUS_CIRCLE,
                                     command=self._askCreateParticles)
        saveparticlesbtn.grid(row=0, column=1, sticky='n', padx=5, pady=5)
        btn = HotButton(self.buttonframe,
                        "Classes",
                        Icon.PLUS_CIRCLE,
                        command=self._askCreateClasses)
        btn.grid(row=0, column=2, sticky='n', padx=5, pady=5)

        lt = LevelTree(g)
        lt.DY = 135  # TODO: change in percent of the image size
        lt.setCanvas(canvas)
        lt.paint(self._createNode, maxLevel=self.maxLevel.get() - 1)
        canvas.updateScrollRegion()

        return [self.win]