Package nltk :: Package draw :: Module chart :: Class ChartView
[hide private]
[frames] | no frames]

Class ChartView

source code

object --+
         |
        ChartView

A component for viewing charts. This is used by ChartDemo to allow students to interactively experiment with various chart parsing techniques. It is also used by Chart.draw().

Instance Methods [hide private]
 
__init__(self, chart, root=None, **kw)
Construct a new Chart display.
source code
 
_init_fonts(self, root) source code
 
_sb_canvas(self, root, expand='y', fill='both', side='bottom')
Helper for __init__: construct a canvas with a scrollbar.
source code
 
scroll_up(self, *e) source code
 
scroll_down(self, *e) source code
 
page_up(self, *e) source code
 
page_down(self, *e) source code
 
_grow(self)
Grow the window, if necessary
source code
 
set_font_size(self, size) source code
 
get_font_size(self) source code
 
_configure(self, e)
The configure callback.
source code
 
update(self, chart=None)
Draw any edges that have not been drawn.
source code
 
_edge_conflict(self, edge, lvl)
Return 1 if the given edge overlaps with any edge on the given level.
source code
 
_analyze_edge(self, edge)
Given a new edge, recalculate:
source code
 
_add_edge(self, edge, minlvl=0)
Add a single edge to the ChartView:
source code
 
view_edge(self, edge) source code
 
_draw_edge(self, edge, lvl)
Draw a single edge on the ChartView.
source code
 
_color_edge(self, edge, linecolor=None, textcolor=None)
Color in an edge with the given colors.
source code
 
mark_edge(self, edge, mark='#0df')
Mark an edge
source code
 
unmark_edge(self, edge=None)
Unmark an edge (or all edges)
source code
 
markonly_edge(self, edge, mark='#0df') source code
 
_analyze(self)
Analyze the sentence string, to figure out how big a unit needs to be, How big the tree should be, etc.
source code
 
_resize(self)
Update the scroll-regions for each canvas.
source code
 
_draw_loclines(self)
Draw location lines.
source code
 
_draw_sentence(self)
Draw the sentence string.
source code
 
erase_tree(self) source code
 
draw_tree(self, edge=None) source code
 
cycle_tree(self) source code
 
_draw_treecycle(self) source code
 
_draw_treetok(self, treetok, index, depth=0)
Returns: The index of the first leaf after the tree.
source code
 
draw(self)
Draw everything (from scratch).
source code
 
add_callback(self, event, func) source code
 
remove_callback(self, event, func=None) source code
 
_fire_callbacks(self, event, *args) source code

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

Class Variables [hide private]
  _LEAF_SPACING = 10
  _MARGIN = 10
  _TREE_LEVEL_SIZE = 12
  _CHART_LEVEL_SIZE = 40
Instance Variables [hide private]
  _chart
The chart that we are giving a view of.
  _chart_canvas
The canvas we're using to display the chart itself.
  _chart_height
The height of the chart canvas.
  _edgelevels
A list of edges at each level of the chart (the top level is the 0th element).
  _edgetags
A dictionary mapping from edges to the tags of the canvas elements (lines, etc) used to display that edge.
  _fontsize
The current font size
  _marks
A dictionary from edges to marks.
  _root
The root window.
  _sentence
The list of tokens that the chart spans.
  _sentence_canvas
The canvas we're using to display the sentence text.
  _sentence_height
The height of the sentence canvas.
  _text_height
The height of a text string (in the normal font).
  _tree_canvas
The canvas we're using to display the tree that each edge spans.
  _tree_height
The height of the tree
  _treetags
A list of all the tags that make up the tree; used to erase the tree (without erasing the loclines).
  _unitsize
Pixel size of one unit (from the location).
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, chart, root=None, **kw)
(Constructor)

source code 

Construct a new Chart display.

Overrides: object.__init__

_configure(self, e)

source code 

The configure callback. This is called whenever the window is resized. It is also called when the window is first mapped. It figures out the unit size, and redraws the contents of each canvas.

update(self, chart=None)

source code 

Draw any edges that have not been drawn. This is typically called when a after modifies the canvas that a CanvasView is displaying. update will cause any edges that have been added to the chart to be drawn.

If update is given a chart argument, then it will replace the current chart with the given chart.

_edge_conflict(self, edge, lvl)

source code 

Return 1 if the given edge overlaps with any edge on the given level. This is used by _add_edge to figure out what level a new edge should be added to.

_analyze_edge(self, edge)

source code 

Given a new edge, recalculate:

  • _text_height
  • _unitsize (if the edge text is too big for the current _unitsize, then increase _unitsize)

_add_edge(self, edge, minlvl=0)

source code 

Add a single edge to the ChartView:

  • Call analyze_edge to recalculate display parameters
  • Find an available level
  • Call _draw_edge

_color_edge(self, edge, linecolor=None, textcolor=None)

source code 

Color in an edge with the given colors. If no colors are specified, use intelligent defaults (dependant on selection, etc.)

_resize(self)

source code 

Update the scroll-regions for each canvas. This ensures that everything is within a scroll-region, so the user can use the scrollbars to view the entire display. This does not resize the window.

_draw_loclines(self)

source code 

Draw location lines. These are vertical gridlines used to show where each location unit is.

_draw_treetok(self, treetok, index, depth=0)

source code 
Parameters:
  • index - The index of the first leaf in the tree.
Returns:
The index of the first leaf after the tree.

Instance Variable Details [hide private]

_chart

The chart that we are giving a view of. This chart may be modified; after it is modified, you should call update.

_edgelevels

A list of edges at each level of the chart (the top level is the 0th element). This list is used to remember where edges should be drawn; and to make sure that no edges are overlapping on the chart view.

_edgetags

A dictionary mapping from edges to the tags of the canvas elements (lines, etc) used to display that edge. The values of this dictionary have the form (linetag, rhstag1, dottag, rhstag2, lhstag).

_marks

A dictionary from edges to marks. Marks are strings, specifying colors (e.g. 'green').

_sentence_canvas

The canvas we're using to display the sentence text. May be None, if we're not displaying the sentence text.

_tree_canvas

The canvas we're using to display the tree that each edge spans. May be None, if we're not displaying trees.

_unitsize

Pixel size of one unit (from the location). This is determined by the span of the chart's location, and the width of the chart display canvas.