Package nltk_lite :: Package contrib :: Package fst :: Module draw_graph :: Class GraphWidget
[hide private]
[frames] | no frames]

Class GraphWidget

source code

       object --+    
                |    
draw.CanvasWidget --+
                    |
                   GraphWidget
Known Subclasses:
fst.FSTWidget

A canvas widget used to display directed graphs. This container widget contains zero or more 'node widgets', which are connected by zero or more GraphEdgeWidgets. The GraphWidget is responsible for updating the edge widgets when nodes move; and for initially arranging the nodes.

Instance Methods [hide private]
 
__init__(self, canvas, nodes, edges, **attrs)
Create a new canvas widget.
source code
 
add_node(self, node)
Add a new node to the graph.
source code
 
add_edge(self, start, end, edgewidget)
Add a new edge to the graph.
source code
 
remove_edge(self, edge)
Remove an edge from the graph (but don't destroy it).
source code
 
remove_node(self, node)
Remove a node from the graph (but don't destroy it).
source code
 
destroy_edge(self, edge)
Remove an edge from the graph, and destroy the edge.
source code
 
destroy_node(self, node)
Remove a node from the graph, and destroy the node.
source code
list of int
_tags(self)
Returns: a list of canvas tags for all graphical elements managed by this canvas widget, not including graphical elements managed by its child widgets.
source code
None
_update(self, child)
Make sure all edges/nodes are connected correctly.
source code
 
_update_edge(self, edge) source code
 
_node_port(self, node, src_x, src_y, curve) source code
 
_node_center(self, node) source code
None
_manage(self)
Arrange the child widgets of this canvas widget.
source code
 
arrange(self, arrange_algorithm=None, toplevel=None)
Set the node positions.
source code
 
_arrange_levels(self)
Re-arrange each level to (locally) minimize the number of crossing edges.
source code
 
_arrange_level(self, levelnum)
Arrange a given level..
source code
 
_arrange_into_levels(self, toplevel)
Assign a level to each node.
source code
 
_reachable(self, node, reached=None)
How many *unexpanded* nodes can be reached from the given node?
source code
 
_add_descendants(self, parent_level, levelnum)
Add all the descendants of the nodes in the list parent_level to the structures self._level and self._nodelevel.
source code
 
_add_descendants_dfs(self, parent_level, levelnum) source code
 
_add_descendants_bfs(self, parent_level, levelnum) source code
 
_add_descendants_bfs2(self, parent_level, levelnum) source code

Inherited from draw.CanvasWidget: __getitem__, __repr__, __setitem__, bbox, bind_click, bind_drag, canvas, child_widgets, destroy, height, hidden, hide, manage, move, moveto, parent, show, tags, unbind_click, unbind_drag, update, width

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, canvas, nodes, edges, **attrs)
(Constructor)

source code 

Create a new canvas widget. This constructor should only be called by subclass constructors; and it should be called only after the subclass has constructed all graphical canvas objects and registered all child widgets.

Parameters:
  • edges - A list of tuples (n1, n2, e), where n1 is a CanvasWidget in nodes; n2 is a CanvasWidget in nodes; and e is a GraphEdgeWidget.
Overrides: draw.CanvasWidget.__init__

add_edge(self, start, end, edgewidget)

source code 

Add a new edge to the graph.

Parameters:
  • start (CanvasWidget) - The start node
  • end (CanvasWidget) - The end node
  • edgewidget (GraphEdgeWidget) - The edge

remove_edge(self, edge)

source code 

Remove an edge from the graph (but don't destroy it).

remove_node(self, node)

source code 

Remove a node from the graph (but don't destroy it).

Returns:
A list of widgets that were removed from the graph. Note that this will include any edges that connected to node.

_tags(self)

source code 
Returns: list of int
a list of canvas tags for all graphical elements managed by this canvas widget, not including graphical elements managed by its child widgets.
Overrides: draw.CanvasWidget._tags
(inherited documentation)

_update(self, child)

source code 

Make sure all edges/nodes are connected correctly.

Returns: None
Overrides: draw.CanvasWidget._update

_manage(self)

source code 

Arrange the child widgets of this canvas widget. This method is called when the canvas widget is initially created. It is also called if the user calls the manage method on this canvas widget or any of its ancestors.

Returns: None
Overrides: draw.CanvasWidget._manage
(inherited documentation)

arrange(self, arrange_algorithm=None, toplevel=None)

source code 

Set the node positions. This routine should attempt to minimize the number of crossing edges, in order to make the graph easier to read.

_arrange_level(self, levelnum)

source code 

Arrange a given level.. This algorithm is simple and pretty heuristic..