Package pyffi :: Package qskope :: Module global_tree
[hide private]
[frames] | no frames]

Source Code for Module pyffi.qskope.global_tree

  1  # -------------------------------------------------------------------------- 
  2  # ***** BEGIN LICENSE BLOCK ***** 
  3  # 
  4  # Copyright (c) 2007-2011, Python File Format Interface 
  5  # All rights reserved. 
  6  # 
  7  # Redistribution and use in source and binary forms, with or without 
  8  # modification, are permitted provided that the following conditions 
  9  # are met: 
 10  # 
 11  #    * Redistributions of source code must retain the above copyright 
 12  #      notice, this list of conditions and the following disclaimer. 
 13  # 
 14  #    * Redistributions in binary form must reproduce the above 
 15  #      copyright notice, this list of conditions and the following 
 16  #      disclaimer in the documentation and/or other materials provided 
 17  #      with the distribution. 
 18  # 
 19  #    * Neither the name of the Python File Format Interface 
 20  #      project nor the names of its contributors may be used to endorse 
 21  #      or promote products derived from this software without specific 
 22  #      prior written permission. 
 23  # 
 24  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 25  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 26  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 27  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 28  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 29  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 30  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 31  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 32  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 33  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 34  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 35  # POSSIBILITY OF SUCH DAMAGE. 
 36  # 
 37  # ***** END LICENSE BLOCK ***** 
 38  # -------------------------------------------------------------------------- 
 39   
 40  from itertools import izip 
 41   
 42  from pyffi.utils.graph import GlobalNode, EdgeType, EdgeFilter 
43 44 -class GlobalTreeItemData(object):
45 """Stores all data used in the detail view. 46 47 :ivar node: The node of the item. 48 :type node: :class:`DetailNode` 49 """
50 - def __init__(self, node=None):
51 if not isinstance(node, GlobalNode): 52 raise TypeError("node must be GlobalNode instance") 53 self.node = node
54 55 # convenience functions, these are used internally by QSkope 56 57 @property
58 - def display(self):
59 return self.node.get_global_display()
60 61 @property
62 - def typename(self):
63 return self.node.__class__.__name__
64
65 -class GlobalTreeItem(object):
66 """Stores all internal information to vizualize L{GlobalNode}s in a 67 tree view. 68 69 :ivar data: The item data. 70 :type data: L{GlobalDetailTreeItemData} 71 :ivar parent: The parent of the node. 72 :type parent: ``type(None)`` or :class:`DetailTreeItem` 73 :ivar children: The children of the node. 74 :type children: ``list`` of :class:`GlobalTreeItem` 75 :ivar row: The row number of this node, as child. 76 :type row: ``int`` 77 :ivar edge_type: The type of edge from the parent. Default is 0. The 0 78 edges must form a spanning directed acyclic graph. Other numbers 79 may form cycles (or not, this is format dependent). 80 :type edge_type: ``int`` 81 """
82 - def __init__(self, data=None, parent=None, row=0, edge_type=EdgeType(), 83 edge_filter=EdgeFilter()):
84 """Initialize the node tree hierarchy from the given data.""" 85 if not isinstance(data, GlobalTreeItemData): 86 raise TypeError( 87 "data must be a GlobalTreeItemData instance") 88 if not isinstance(parent, (type(None), GlobalTreeItem)): 89 raise TypeError( 90 "parent must be either None or a GlobalTreeItem instance") 91 if not isinstance(edge_type, EdgeType): 92 raise TypeError("edge_type must be EdgeType instance") 93 self.data = data 94 self.parent = parent 95 self.row = row 96 self.edge_type = edge_type 97 self.children = [ 98 GlobalTreeItem( 99 data=GlobalTreeItemData(node=child_node), 100 parent=self, 101 row=child_row, 102 edge_type=child_edge_type) 103 for (child_row, (child_node, child_edge_type)) 104 in enumerate(izip( 105 data.node.get_global_child_nodes(edge_filter=edge_filter), 106 data.node.get_global_child_edge_types(edge_filter=edge_filter)))]
107