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

Source Code for Module pyffi.qskope.detail_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 DetailNode, EdgeType, EdgeFilter 
43 44 -class DetailTreeItemData(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 :ivar name: The name of the node (this is usually not stored in the node). 50 :type name: ``str`` 51 """
52 - def __init__(self, node=None, name=None):
53 if not isinstance(node, DetailNode): 54 raise TypeError("node must be DetailNode instance") 55 if not isinstance(name, (type(None), basestring)): 56 raise TypeError("name must be None or string instance") 57 self.node = node 58 self.name = name
59 60 # convenience functions, these are used internally by QSkope 61 62 @property
63 - def display(self):
64 return self.node.get_detail_display()
65 66 @property
67 - def typename(self):
68 return self.node.__class__.__name__
69
70 -class DetailTreeItem(object):
71 """Stores all internal information to vizualize :class:`DetailNode`\ s in a 72 tree view. 73 74 :ivar data: The item data. 75 :type data: :class:`DetailTreeItemData` 76 :ivar parent: The parent of the node. 77 :type parent: ``type(None)`` or :class:`DetailTreeItem` 78 :ivar children: The children of the node. 79 :type children: ``list`` of :class:`DetailTreeItem` 80 :ivar row: The row number of this node, as child. 81 :type row: ``int`` 82 :ivar edge_type: The type of edge from the parent of this node to itself. 83 :type edge_type: :class:`EdgeType` 84 """
85 - def __init__(self, data=None, parent=None, row=0, edge_type=EdgeType(), 86 edge_filter=EdgeFilter()):
87 """Initialize the node tree hierarchy from the given data.""" 88 if not isinstance(data, DetailTreeItemData): 89 raise TypeError( 90 "data must be a DetailTreeItemData instance") 91 if not isinstance(parent, (type(None), DetailTreeItem)): 92 raise TypeError( 93 "parent must be either None or a DetailTreeItem instance") 94 if not isinstance(edge_type, EdgeType): 95 raise TypeError("edge_type must be EdgeType instance") 96 self.data = data 97 self.parent = parent 98 self.row = row 99 self.edge_type = edge_type 100 self.children = [ 101 DetailTreeItem( 102 data=DetailTreeItemData(node=childnode, name=childname), 103 parent=self, 104 row=childrow, 105 edge_type=child_edge_type) 106 for (childrow, (childnode, childname, child_edge_type)) 107 in enumerate(izip( 108 data.node.get_detail_child_nodes(edge_filter=edge_filter), 109 data.node.get_detail_child_names(edge_filter=edge_filter), 110 data.node.get_detail_child_edge_types(edge_filter=edge_filter)))]
111