Beispiel #1
0
 def updateMap(self, directory, resetMap=True):
     '''Rebuild the Treemap at the specified directory and clear the map
     iff resetMap is True.'''
     # Clear the map if reset is True
     if resetMap:
         self.clearMap()
     # Build a new Treemap
     self.__treemap = Treemap()
     self.__treemap.build(directory)
Beispiel #2
0
def example():    
    """
    Treemap demo!
    
    This shows an example of creating a treemap  of nested tuples, random colours.
    Node size is sum of leaf elements.
    """ 
    
    size_cache = {}
    
    def size(thing):
        """sum size of child nodes"""
        if isinstance(thing, int) or isinstance(thing, float):
            return thing
        if thing in size_cache:
            return size_cache[thing]
        else:
            size_cache[thing] = reduce(operator.add, [size(x) for x in thing])
            return size_cache[thing]
    
    def random_color(thing):
        """just return a random color"""
        return colorsys.hsv_to_rgb(random.random(), 0.5, 1)
    
    tree = ((5, (3, 5, 2, (0.1, 0.1, 0.6), 1)), 4, 
            (5, 2, (2, 3, (3, 2, (2, 5, 2), 2)), 
             (3, 3)), (3, 2, (0.2, 0.2, 0.2)))
    

    tm = Treemap(tree, size, random_color)    
    pylab.show()
Beispiel #3
0
 def updateMap(self, directory, resetMap=True):
     '''Rebuild the Treemap at the specified directory and clear the map
     iff resetMap is True.'''
     # Clear the map if reset is True
     if resetMap:
         self.clearMap()
     # Build a new Treemap
     self.__treemap = Treemap()
     self.__treemap.build(directory)
Beispiel #4
0
def test_coverage():
    """Treemap visualisation of coverage information.
    
    This script will visually display a coverage file generated by Ned
    Batchelders statment coverage module, coverage.py (available from 
    http://www.nedbatchelder.com/code/modules/coverage.html).  Each node
    in the treemap is a python module with size is given by the number 
    of lines of code and colour of the by the coverage. Red is no coverage, 
    green is full coverage.  Mouse hovering will show the name of the file.
    
    The script automatically looks in the current directory for a 
    .coverage file to display.  Else you can specify a file using the first
    argument.  e.g.
    
        treemap_coverage /path/to/.coverage
    
    You can include or exclude modules using --include or --exclude.  For 
    example, to exclude all files in the treemap package:
    
        treemap_coverage --exclude treemap /path/to/.coverage
    """
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hi:ve:v", ["help", "include=", "exclude="])
    except getopt.GetoptError:
        print test_coverage.__doc__
        sys.exit(2)
        
    coverage_file = ".coverage"
    include = None
    exclude = "Test"
    
    for o, a in opts:
        if o in ("-h", "--help"):
            print test_coverage.__doc__
            sys.exit()
        if o in ("-i", "--include"):
            include = a
        if o in ("-e", "--exclude"):
            exclude = a    
            
    if len(args) > 0:
        coverage_file = args[0]
    
    if not os.path.exists(coverage_file):
        print "%s: file does not exist (try --help)" % coverage_file
        sys.exit(2)

    coverage.the_coverage.cache = coverage_file
    try:
        coverage.the_coverage.restore()
    except:
        print "Error loading coverage, is %s a valid coverage file?" % coverage_file
    
    wanted = coverage.the_coverage.cexecuted.keys()
    
    if include:    
        wanted = [x for x in wanted if x.count(include)]
    if exclude:
        wanted = [x for x in wanted if not x.count(exclude)]
    wanted = [coverage.the_coverage.canonical_filename(x) for x in wanted]
    
    
    code = CoveredCode(wanted)
    root = code.root_module()
    
    Treemap( root,  code.size, code.color, iter_method=code.child_modules )
    pylab.show()
Beispiel #5
0
def start():
	##initializing scene -------------------
	graph = avango.gua.nodes.SceneGraph(
		Name = "scenegraph"
	)

	## Viewing Setup
	screen = avango.gua.nodes.ScreenNode(
		Name = "screen",
		Width = 1.6,
		Height = 0.9,
		Transform = avango.gua.make_trans_mat(0.0, 0.0, -2.5)
	)

	eye = avango.gua.nodes.TransformNode(
		Name = "eye",
		Transform = avango.gua.make_trans_mat(0.0, 0.0, 7.5)
	)

	eye.Children.value = [screen]

	graph.Root.value.Children.value.append(eye)

	camera = avango.gua.nodes.Camera(
		LeftEye = "/eye",
		RightEye = "/eye",
		LeftScreen = "/eye/screen",
		RightScreen = "/eye/screen",
		SceneGraph = "scenegraph"
	)

	window = avango.gua.nodes.Window(
		Size = size,
		LeftResolution = size
	)


	pipe = avango.gua.nodes.Pipeline(
		Camera = camera,
		Window = window,
		EnableSsao = False,
		SsaoIntensity = 0.5,
		LeftResolution = size,
		EnableRayDisplay = False,
		EnableFPSDisplay = False,
		EnableBackfaceCulling = False,
		NearClip = 0.0001
	)
	# pipe.BackgroundTexture.value = "data/textures/skymap.jpg"
	# pipe.BackgroundMode.value = avango.gua.BackgroundMode.SKYMAP_TEXTURE

	# ## Transform Test
	# TMtest = avango.gua.nodes.TransformNode(Name = "Test")
	# TMtest.Transform.value = avango.gua.make_scale_mat(0.1)
	# graph.Root.value.Children.value.append(TMtest)

	## Setup visualization-------------------
	print treemap_tutorial.create_tutorial()
	root = filesystemloader.load(sys.argv[1])
	TM = Treemap()
	TM.my_constructor(root)
	TM.create_scenegraph_structure()
	graph.Root.value.Children.value.append(TM.root_node)
	graph.update_cache()
	TM.layout()

	## Setup Text
	text = TextField()
	text_transform = avango.gua.nodes.TransformNode( Name = "text_transform",
												 # Transform = avango.gua.make_trans_mat(0.1 * (-0.8 / 2.5), 0.1 *(-0.4 / 2.5), -0.1) * avango.gua.make_scale_mat(0.03 * 0.1/2.5))
												 Transform = avango.gua.make_trans_mat(0.01 * (-0.8 / 2.5),  0.01 *(-0.42 / 2.5), -0.0101) * avango.gua.make_scale_mat(0.002 * 0.1/2.5) )
	eye.Children.value.append(text_transform)
	text.my_constructor(text_transform)
	text.sf_text.connect_from(TM.Focuspath)

	## Setup Controllers
	keyController = KeyController()
	keyController.setTreeMap(TM)

	navigator = Navigator()
	eye.Transform.connect_from(navigator.OutTransform)
	navigator.setTreeMap(TM)

	TM_Picker = Picker()
	TM_Picker.PickedSceneGraph.value = graph
	pick_ray = avango.gua.nodes.RayNode(Name = "pick_ray")
	pick_ray.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, 0.0) * \
														 avango.gua.make_scale_mat(0.00001, 0.00001, 5)
	eye.Children.value.append(pick_ray)
	TM_Picker.Ray.value = pick_ray


	loader = avango.gua.nodes.TriMeshLoader()
	crosshair = loader.create_geometry_from_file(
		"crosshair",
		"data/objects/cube.obj",
		"data/materials/Grey_bright.gmd",
		avango.gua.LoaderFlags.DEFAULTS,
	)
	crosshair.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, -0.005) * \
														 avango.gua.make_scale_mat(0.00001)
	eye.Children.value.append(crosshair)

	navigator.setPicker(TM_Picker)

	## Focus Updater
	focuser = FocusUpdater()
	focuser.setTreeMap(TM)
	focuser.Results.connect_from(TM_Picker.Results)

	Down_Picker = Picker()
	Down_Picker.PickedSceneGraph.value = graph
	pick_ray = avango.gua.nodes.RayNode(Name = "down_pick_ray")
	pick_ray.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, 0.0) * \
														 avango.gua.make_rot_mat(-10, 1.0, 0.0, 0.0) * \
														 avango.gua.make_scale_mat(0.00001, 0.00001, 5)
	graph.Root.value.Children.value.append(pick_ray)
	Down_Picker.Ray.value = pick_ray

	navigator.controller3D.setDown_Picker(Down_Picker)

	Move_Picker = Picker()
	Move_Picker.PickedSceneGraph.value = graph
	pick_ray = avango.gua.nodes.RayNode(Name = "move_pick_ray")
	pick_ray.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, 0.0) * \
														 avango.gua.make_rot_mat(0, 0.0, 1.0, 0.0) * \
														 avango.gua.make_scale_mat(0.00001, 0.00001, 5)
	graph.Root.value.Children.value.append(pick_ray)
	Move_Picker.Ray.value = pick_ray

	navigator.controller3D.setMove_Picker(Move_Picker)

	# # setup Reference
	# loader = avango.gua.nodes.TriMeshLoader()
	# reference_cubes = []
	# for i in range(4):
	# 	reference_cubes.append( loader.create_geometry_from_file(
	# 		"reference_cube",
	# 		"data/objects/cube.obj",
	# 		"data/materials/Red.gmd",
	# 		avango.gua.LoaderFlags.DEFAULTS,
	# 	))

	# reference_cubes[0].Transform.value = avango.gua.make_trans_mat(-0.5, 0 , -0.5) * avango.gua.make_scale_mat(0.11)
	# reference_cubes[1].Transform.value = avango.gua.make_trans_mat( 0.5, 0 , -0.5) * avango.gua.make_scale_mat(0.11)
	# reference_cubes[2].Transform.value = avango.gua.make_trans_mat(-0.5, 0 ,  0.5) * avango.gua.make_scale_mat(0.11)
	# reference_cubes[3].Transform.value = avango.gua.make_trans_mat( 0.5, 0 ,  0.5) * avango.gua.make_scale_mat(0.11)
	# graph.Root.value.Children.value.append(reference_cubes[0])
	# graph.Root.value.Children.value.append(reference_cubes[1])
	# graph.Root.value.Children.value.append(reference_cubes[2])
	# graph.Root.value.Children.value.append(reference_cubes[3])

	# Light for the Treemap
	# sun = avango.gua.nodes.SunLightNode(
	# 	Name = "sun",
	# 	Color = avango.gua.Color(1, 1, 1),
	# 	Transform = avango.gua.make_rot_mat(-45, 1, 0, 0),
	# 	EnableShadows = True
	# )

	# graph.Root.value.Children.value.append(sun)

	light = avango.gua.nodes.PointLightNode(
		Name = "light",
		Color = avango.gua.Color(1,1,1),
		Transform = avango.gua.make_trans_mat(0, 3, 0) * avango.gua.make_scale_mat(5),
		# EnableSpecularShading = False,
		EnableShadows = False
	)
	graph.Root.value.Children.value.append(light)

	guaVE = GuaVE()
	guaVE.start(locals(), globals())

	viewer = avango.gua.nodes.Viewer()

	viewer.Pipelines.value = [pipe]
	viewer.SceneGraphs.value = [graph]

	viewer.run()
Beispiel #6
0
class TileFrame(QtGui.QFrame):
    '''TileFrame extends the QtGui.QFrame class. It is used to render the
    Treemap data structure, each node in the Treemap is rendered as
    rectanglular tiles with a fixed colour or gradient colours. Hovered tiles
    are rendered using a lighter fixed colour.'''

    def __init__(self, parentWindow):
        '''Create a new TileFrame.'''
        super(TileFrame, self).__init__(parentWindow)
        # TileFrame variables
        self.__treemap = None
        self.__isBorders = True
        self.__isGradient = False
        self.__rectNodes = []
        self.__selectedNode = None
        self.__borderCol = QtGui.QColor(0, 0, 0)
        self.__bgCol = QtGui.QColor(64, 64, 64)
        self.__txtCol = QtGui.QColor(38, 38, 38)
        self.__txtFont = QtGui.QFont('CopperBlack', 60, QtGui.QFont.Bold)
        self.__txt = "Visualizer"
        # Set strong policy for focusing keyboard events to Tileframe
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setMouseTracking(True)

    def __buildTiles(self, painter, node, size, location):
        '''Render the Treemap Node by Node. Render the DirNode as borders
        with the border colour and render the FileNodes as rectangular tiles.
        Render the FileNodes with gradient colours iff gradients are enabled
        and render with a fixed colour otherwise.'''
        borderRect = QtCore.QRect(location[0], location[1], size[0], size[1])
        # If rendering borders is enabled
        if self.__isBorders:
            # Shift the dimensions of the rectangle
            location[0] += 1
            location[1] += 1
            size[0] -= 2
            size[1] -= 2
        totalSize = max(node.getSize(), 1)  # Prevent ZeroDivisionError
        for item in node.getChildren():
            percent = item.getSize() / totalSize
            itemArea = (size[0] * size[1]) * percent
            # Calculate dimensions of the rectangle
            if size[1] > size[0]:
                width = size[0]
                height = itemArea / width
                # Draw rectangle
                if self.__isGradient:
                    self.__drawGradientRectangle(painter, item, [width,
                                                                 height],
                                                 location)
                else:
                    self.__drawRectangle(painter, item, [width, height],
                                         location)
                location[1] += height
            else:
                height = size[1]
                width = itemArea / height
                # Draw rectangle
                if self.__isGradient:
                    self.__drawGradientRectangle(painter, item, [width,
                                                                 height],
                                                 location)
                else:
                    self.__drawRectangle(painter, item, [width, height],
                                         location)
                location[0] += width
        # If rendering borders is enabled
        if self.__isBorders:
            # Draw the border around the rectangle
            painter.setBrush(QtCore.Qt.NoBrush)
            painter.setPen(self.__borderCol)
            painter.drawRect(borderRect)

    def __drawGradientRectangle(self, painter, node, size, location):
        '''Render a Node of type FileNode as a rectangular gradient
        proportional to the size of the file represented by FileNode. Render
        the FileNode with its hover colour iff it's mouse hovered, otherwise
        render the FileNode with the top and bottom gradient colours.'''
        if isinstance(node, FileNode):
            # Obtain the components of a rectangle
            x1 = location[0]
            y1 = location[1]
            x2 = size[0] + 1
            y2 = size[1] + 1
            # Store a map of the file nodes and their display rectangle tiles
            rect = QtCore.QRect(x1, y1, x2, y2)
            self.__rectNodes.append((rect, node))
            # Set the top and bottom gradient colours to the Node's hover
            # colours if the file's node is selected, otherwise obtain the top
            # and bottom gradient colours from node
            if self.__selectedNode == node:
                topCol = botCol = node.getHColour()
            else:
                topCol = node.getTColour()
                botCol = node.getBColour()
            # Obtain the components of rectanglular gradient
            gradX1 = location[0]
            gradY1 = location[1] + size[0]
            gradX2 = (location[0] + size[0]) - size[0]
            gradY2 = location[1] + size[1]
            # Render the tile as a gradient
            grad = QtGui.QLinearGradient(gradX1, gradY1, gradX2, gradY2)
            grad.setColorAt(0.0, QtGui.QColor(topCol[0], topCol[1], topCol[2]))
            grad.setColorAt(1.0, QtGui.QColor(botCol[0], botCol[1], botCol[2]))
            painter.setPen(QtCore.Qt.NoPen)
            painter.setBrush(QtGui.QBrush(grad))
            painter.drawRect(rect)
        # Recursively render the next tile in the Treemap
        self.__buildTiles(painter, node, size, location[:])

    def __drawRectangle(self, painter, node, size, location):
        '''Render a Node of type FileNode as a rectangular tile proportional to
        the size of file represented by the FileNode. Render the FileNode with
        its hover colour iff it's mouse hovered, otherwise render the FileNode
        with the top gradient colour.'''
        if isinstance(node, FileNode):
            # Obtain the components of a rectangle
            x1 = location[0]
            x2 = location[1]
            y1 = size[0] + 1
            y2 = size[1] + 1
            # Store a map of the file nodes and their display rectangle tiles
            rect = QtCore.QRect(x1, x2, y1, y2)
            self.__rectNodes.append((rect, node))
            # Obtain the file's hover colour if it is selected otherwise obtain
            # it's regular top gradient colour
            if self.__selectedNode == node:
                col = node.getHColour()
            else:
                col = node.getTColour()
            painter.fillRect(rect, QtGui.QColor(col[0], col[1], col[2]))
        # Recursively render the next tile in the Treemap
        self.__buildTiles(painter, node, size, location[:])

    def getHoveredNodePath(self, mousePos):
        '''Return the path of a file, as a string, from a Node that is mouse
        hovered.'''
        mX = mousePos.x()
        mY = mousePos.y() - self.y()  # Account for location of widget
        # Iterate through all the rectangles
        for item in self.__rectNodes:
            rX = item[0].x()
            rY = item[0].y()
            rW = item[0].width()
            rH = item[0].height()
            if (mX >= rX and mX <= (rX + rW)) and (mY >= rY and mY <= (rY +
                                                                       rH)):
                # Store the hovered node as the selected node and update
                self.__selectedNode = item[1]
                self.update()
                # Return the path of the file represented by the FileNode
                return item[1].getPath()

    def isMapped(self):
        '''Return true if Treemap exists, False otherwise.'''
        return self.__treemap

    def toggleBorders(self):
        '''Enable drawing of borders if drawing borders was dissabled and
        dissable drawing of borders if it was previously enabled.'''
        if self.isMapped():
            # Toggle borders and update the tile rendering
            self.__isBorders = not self.__isBorders
            self.update()

    def toggleGradient(self):
        '''Enable drawing of gradients if drawing gradients was dissabled and
        dissable drawing of gradients if they were previously enabled.'''
        if self.isMapped():
            # Toggle gradient and update the tile rendering
            self.__isGradient = not self.__isGradient
            self.update()

    def screenshot(self, filename):
        '''Obtain a pixel map of the current window and save it as a .PNG
        file with the name specified by filename.'''
        QtGui.QPixmap.grabWindow(self.winId()).save(filename, 'png')

    def clearMap(self):
        '''Reset the visual map variables and clear the Treemap.'''
        # Reset the toggle variables
        self.__isBorders = True
        self.__isGradient = False
        # Clear the node rectangles
        self.__rectNodes = {}
        # Clear the Treemap
        self.__treemap = None

    def updateMap(self, directory, resetMap=True):
        '''Rebuild the Treemap at the specified directory and clear the map
        iff resetMap is True.'''
        # Clear the map if reset is True
        if resetMap:
            self.clearMap()
        # Build a new Treemap
        self.__treemap = Treemap()
        self.__treemap.build(directory)

    def paintEvent(self, event):
        '''Handle and process all of the drawing for the Treemap. Render the
        Treemap if it's loaded, otherwise render a grey background with darker
        grey text centered on the window.'''
        self.__rectNodes = []  # Clear all the rectangle node list
        painter = QtGui.QPainter(self)  # Used to draw on the frame
        # Clear all drawings on the TileFrame
        painter.eraseRect(0, 0, self.width(), self.height())
        if self.isMapped():
            # Set the initial conditions and render the Treemap
            size = [self.width(), self.height()]
            location = [0, 0]
            self.__buildTiles(painter, self.__treemap.getRoot(), size,
                              location)
        else:
            # Draw the default background
            painter.fillRect(0, 0, self.width(), self.height(), self.__bgCol)
            # Draw the default text
            painter.setPen(self.__txtCol)
            painter.setFont(self.__txtFont)
            painter.drawText(event.rect(), QtCore.Qt.AlignCenter, self.__txt)
Beispiel #7
0
class TileFrame(QtWidgets.QFrame):
    '''TileFrame extends the QtGui.QFrame class. It is used to render the
    Treemap data structure, each node in the Treemap is rendered as
    rectanglular tiles with a fixed colour or gradient colours. Hovered tiles
    are rendered using a lighter fixed colour.'''

    def __init__(self, parentWindow):
        '''Create a new TileFrame.'''
        super(TileFrame, self).__init__(parentWindow)
        # TileFrame variables
        self.__treemap = None
        self.__isBorders = True
        self.__isGradient = False
        self.__rectNodes = []
        self.__selectedNode = None
        self.__borderCol = QtGui.QColor(0, 0, 0)
        self.__bgCol = QtGui.QColor(64, 64, 64)
        self.__txtCol = QtGui.QColor(38, 38, 38)
        self.__txtFont = QtGui.QFont('CopperBlack', 60, QtGui.QFont.Bold)
        self.__txt = "Visualizer"
        # Set strong policy for focusing keyboard events to Tileframe
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setMouseTracking(True)

    def __buildTiles(self, painter, node, size, location):
        '''Render the Treemap Node by Node. Render the DirNode as borders
        with the border colour and render the FileNodes as rectangular tiles.
        Render the FileNodes with gradient colours iff gradients are enabled
        and render with a fixed colour otherwise.'''
        borderRect = QtCore.QRect(location[0], location[1], size[0], size[1])
        # If rendering borders is enabled
        if self.__isBorders:
            # Shift the dimensions of the rectangle
            location[0] += 1
            location[1] += 1
            size[0] -= 2
            size[1] -= 2
        totalSize = max(node.getSize(), 1)  # Prevent ZeroDivisionError
        for item in node.getChildren():
            percent = item.getSize() / totalSize
            itemArea = (size[0] * size[1]) * percent
            # Calculate dimensions of the rectangle
            if size[1] > size[0]:
                width = size[0]
                height = itemArea / width
                # Draw rectangle
                if self.__isGradient:
                    self.__drawGradientRectangle(painter,
                                                 item,
                                                 [width, height],
                                                 location)
                else:
                    self.__drawRectangle(painter,
                                         item,
                                         [width, height],
                                         location)
                location[1] += height
            else:
                height = size[1]
                width = itemArea / height
                # Draw rectangle
                if self.__isGradient:
                    self.__drawGradientRectangle(painter,
                                                 item,
                                                 [width, height],
                                                 location)
                else:
                    self.__drawRectangle(painter,
                                         item,
                                         [width, height],
                                         location)
                location[0] += width
        # If rendering borders is enabled
        if self.__isBorders:
            # Draw the border around the rectangle
            painter.setBrush(QtCore.Qt.NoBrush)
            painter.setPen(self.__borderCol)
            painter.drawRect(borderRect)

    def __drawGradientRectangle(self, painter, node, size, location):
        '''Render a Node of type FileNode as a rectangular gradient
        proportional to the size of the file represented by FileNode. Render
        the FileNode with its hover colour iff it's mouse hovered, otherwise
        render the FileNode with the top and bottom gradient colours.'''
        if isinstance(node, FileNode):
            # Obtain the components of a rectangle
            x1 = location[0]
            y1 = location[1]
            x2 = size[0] + 1
            y2 = size[1] + 1
            # Store a map of the file nodes and their display rectangle tiles
            rect = QtCore.QRect(x1, y1, x2, y2)
            self.__rectNodes.append((rect, node))
            # Set the top and bottom gradient colours to the Node's hover
            # colours if the file's node is selected, otherwise obtain the top
            # and bottom gradient colours from node
            if self.__selectedNode == node:
                topCol = botCol = node.getHColour()
            else:
                topCol = node.getTColour()
                botCol = node.getBColour()
            # Obtain the components of rectanglular gradient
            gradX1 = location[0]
            gradY1 = location[1] + size[0]
            gradX2 = (location[0] + size[0]) - size[0]
            gradY2 = location[1] + size[1]
            # Render the tile as a gradient
            grad = QtGui.QLinearGradient(gradX1, gradY1, gradX2, gradY2)
            grad.setColorAt(0.0, QtGui.QColor(topCol[0], topCol[1], topCol[2]))
            grad.setColorAt(1.0, QtGui.QColor(botCol[0], botCol[1], botCol[2]))
            painter.setPen(QtCore.Qt.NoPen)
            painter.setBrush(QtGui.QBrush(grad))
            painter.drawRect(rect)
        # Recursively render the next tile in the Treemap
        self.__buildTiles(painter, node, size, location[:])

    def __drawRectangle(self, painter, node, size, location):
        '''Render a Node of type FileNode as a rectangular tile proportional to
        the size of file represented by the FileNode. Render the FileNode with
        its hover colour iff it's mouse hovered, otherwise render the FileNode
        with the top gradient colour.'''
        if isinstance(node, FileNode):
            # Obtain the components of a rectangle
            x1 = location[0]
            x2 = location[1]
            y1 = size[0] + 1
            y2 = size[1] + 1
            # Store a map of the file nodes and their display rectangle tiles
            rect = QtCore.QRect(x1, x2, y1, y2)
            self.__rectNodes.append((rect, node))
            # Obtain the file's hover colour if it is selected otherwise obtain
            # it's regular top gradient colour
            if self.__selectedNode == node:
                col = node.getHColour()
            else:
                col = node.getTColour()
            painter.fillRect(rect, QtGui.QColor(col[0], col[1], col[2]))
        # Recursively render the next tile in the Treemap
        self.__buildTiles(painter, node, size, location[:])

    def getHoveredNodePath(self, mousePos):
        '''Return the path of a file, as a string, from a Node that is mouse
        hovered.'''
        mX = mousePos.x()
        mY = mousePos.y() - self.y()  # Account for location of widget
        # Iterate through all the rectangles
        for item in self.__rectNodes:
            rX = item[0].x()
            rY = item[0].y()
            rW = item[0].width()
            rH = item[0].height()
            if (mX >= rX and mX <= (rX + rW)) and (mY >= rY and mY <= (rY +
                                                                       rH)):
                # Store the hovered node as the selected node and update
                self.__selectedNode = item[1]
                self.update()
                # Return the path of the file represented by the FileNode
                return item[1].getPath()

    def isMapped(self):
        '''Return true if Treemap exists, False otherwise.'''
        return self.__treemap

    def toggleBorders(self):
        '''Enable drawing of borders if drawing borders was dissabled and
        dissable drawing of borders if it was previously enabled.'''
        if self.isMapped():
            # Toggle borders and update the tile rendering
            self.__isBorders = not self.__isBorders
            self.update()

    def toggleGradient(self):
        '''Enable drawing of gradients if drawing gradients was dissabled and
        dissable drawing of gradients if they were previously enabled.'''
        if self.isMapped():
            # Toggle gradient and update the tile rendering
            self.__isGradient = not self.__isGradient
            self.update()

    def screenshot(self, filename):
        '''Obtain a pixel map of the current window and save it as a .PNG
        file with the name specified by filename.'''
        QtGui.QPixmap.grabWindow(self.winId()).save(filename, 'png')

    def clearMap(self):
        '''Reset the visual map variables and clear the Treemap.'''
        # Reset the toggle variables
        self.__isBorders = True
        self.__isGradient = False
        # Clear the node rectangles
        self.__rectNodes = {}
        # Clear the Treemap
        self.__treemap = None

    def updateMap(self, directory, resetMap=True):
        '''Rebuild the Treemap at the specified directory and clear the map
        iff resetMap is True.'''
        # Clear the map if reset is True
        if resetMap:
            self.clearMap()
        # Build a new Treemap
        self.__treemap = Treemap()
        self.__treemap.build(directory)

    def paintEvent(self, event):
        '''Handle and process all of the drawing for the Treemap. Render the
        Treemap if it's loaded, otherwise render a grey background with darker
        grey text centered on the window.'''
        self.__rectNodes = []  # Clear all the rectangle node list
        painter = QtGui.QPainter(self)  # Used to draw on the frame
        # Clear all drawings on the TileFrame
        painter.eraseRect(0, 0, self.width(), self.height())
        if self.isMapped():
            # Set the initial conditions and render the Treemap
            size = [self.width(), self.height()]
            location = [0, 0]
            self.__buildTiles(painter,
                              self.__treemap.getRoot(),
                              size,
                              location)
        else:
            # Draw the default background
            painter.fillRect(0, 0, self.width(), self.height(), self.__bgCol)
            # Draw the default text
            painter.setPen(self.__txtCol)
            painter.setFont(self.__txtFont)
            painter.drawText(event.rect(), QtCore.Qt.AlignCenter, self.__txt)