Package gPy :: Module IO :: Class GraphCanvas
[hide private]
[frames] | no frames]

Class GraphCanvas

source code


Class for drawing graphs

Nested Classes [hide private]

Inherited from Tkinter.Misc: getdouble, getint

Instance Methods [hide private]
 
__init__(self, graph, parent=None, edit=True, colour_user_actions=True, pp_vertex=None, **config)
Initialises a GraphCanvas to be a TKinter Canvas with extras.
source code
 
arc_config(self, vertex1, vertex2, **config)
Alter an arc/edge by named Tkinter options
source code
 
drawarc_vertices(self, vertex1, vertex2, **config)
Draw a line or arrow between two named vertices
source code
Tuple
graph(self)
Return the displayed graph as a tuple
source code
 
vertex_config(self, vertex, **config)
Alter a vertex by named Tkinter options
source code
 
original_state(self)
Revert Canvas to its state when originally created
source code
 
_drawarc(self, **config)
Draws a line or arrow from current node under pointer to selected node.
source code
 
_drawarc2(self, node_id1, node_id2, **config)
Draw a line or arrow between two vertices
source code
 
_drawarrow(self, event)
Draw an arrow from current node under pointer to selected node.
source code
 
_drawline(self, event)
Draw a line from current node under pointer to selected node.
source code
Tuple
_ends(self, ends)
Given two nodes, finds co-ords for an arc between them.
source code
 
_movenode(self, event)
Moves the selected node to a new position on the Canvas.
source code
 
_newnode(self, event)
Creates a node
source code
 
_select(self, ident)
Selects a Canvas object using its id.
source code
 
_sel_current(self, event)
Selects a node.
source code
 
_sel_or_new(self, event)
Selects or creates a node.
source code
 
zap(self)
Delete the selected node or arc.
source code

Inherited from Tkinter.Canvas: addtag, addtag_above, addtag_all, addtag_below, addtag_closest, addtag_enclosed, addtag_overlapping, addtag_withtag, bbox, canvasx, canvasy, coords, create_arc, create_bitmap, create_image, create_line, create_oval, create_polygon, create_rectangle, create_text, create_window, dchars, delete, dtag, find, find_above, find_all, find_below, find_closest, find_enclosed, find_overlapping, find_withtag, focus, gettags, icursor, index, insert, itemcget, itemconfig, itemconfigure, lift, lower, move, postscript, scale, scan_dragto, scan_mark, select_adjust, select_clear, select_from, select_item, select_to, tag_bind, tag_lower, tag_raise, tag_unbind, tkraise, type, xview, xview_moveto, xview_scroll, yview, yview_moveto, yview_scroll

Inherited from Tkinter.Canvas (private): _create

Inherited from Tkinter.BaseWidget: destroy

Inherited from Tkinter.BaseWidget (private): _do, _setup

Inherited from Tkinter.Misc: __getitem__, __setitem__, __str__, after, after_cancel, after_idle, bell, bind, bind_all, bind_class, bindtags, cget, clipboard_append, clipboard_clear, clipboard_get, colormodel, columnconfigure, config, configure, deletecommand, event_add, event_delete, event_generate, event_info, focus_displayof, focus_force, focus_get, focus_lastfor, focus_set, getboolean, getvar, grab_current, grab_release, grab_set, grab_set_global, grab_status, grid_bbox, grid_columnconfigure, grid_location, grid_propagate, grid_rowconfigure, grid_size, grid_slaves, image_names, image_types, keys, mainloop, nametowidget, option_add, option_clear, option_get, option_readfile, pack_propagate, pack_slaves, place_slaves, propagate, quit, register, rowconfigure, selection_clear, selection_get, selection_handle, selection_own, selection_own_get, send, setvar, size, slaves, tk_bisque, tk_focusFollowsMouse, tk_focusNext, tk_focusPrev, tk_menuBar, tk_setPalette, tk_strictMotif, unbind, unbind_all, unbind_class, update, update_idletasks, wait_variable, wait_visibility, wait_window, waitvar, winfo_atom, winfo_atomname, winfo_cells, winfo_children, winfo_class, winfo_colormapfull, winfo_containing, winfo_depth, winfo_exists, winfo_fpixels, winfo_geometry, winfo_height, winfo_id, winfo_interps, winfo_ismapped, winfo_manager, winfo_name, winfo_parent, winfo_pathname, winfo_pixels, winfo_pointerx, winfo_pointerxy, winfo_pointery, winfo_reqheight, winfo_reqwidth, winfo_rgb, winfo_rootx, winfo_rooty, winfo_screen, winfo_screencells, winfo_screendepth, winfo_screenheight, winfo_screenmmheight, winfo_screenmmwidth, winfo_screenvisual, winfo_screenwidth, winfo_server, winfo_toplevel, winfo_viewable, winfo_visual, winfo_visualid, winfo_visualsavailable, winfo_vrootheight, winfo_vrootwidth, winfo_vrootx, winfo_vrooty, winfo_width, winfo_x, winfo_y

Inherited from Tkinter.Misc (private): _bind, _configure, _displayof, _getboolean, _getdoubles, _getints, _grid_configure, _nametowidget, _options, _register, _report_exception, _root, _substitute

Inherited from Tkinter.Pack: forget, info, pack, pack_configure, pack_forget, pack_info

Inherited from Tkinter.Place: place, place_configure, place_forget, place_info

Inherited from Tkinter.Grid: grid, grid_configure, grid_forget, grid_info, grid_remove, location

Static Methods [hide private]
 
_bbsect(bb, origin)
Gets intersection of bounding box and a line.
source code
String
_id_to_tag(id)
Returns a node's unique tag from its Canvas id.
source code
Tuple
_tags_to_ids(tags)
Returns two node ids given corresponding two node tags.
source code
Class Variables [hide private]

Inherited from Tkinter.Misc: _noarg_

Inherited from Tkinter.Misc (private): _subst_format, _subst_format_str, _tclCommands

Instance Variables [hide private]
Boolean _colour_user_actions
Whether to colour vertices as a result of the user selecting them
Boolean _edit
Whether the graph may be edited by the user
Graph _original_graph
The graph at the time the GraphCanvas object is created
Function, returning a string _pp_vertex
A function mapping graph vertices to the string used for the text of the Tkinter.Canvas text object representing it.
int _sel
Id of selected canvas object
Dictionary _vertex_ids
Maps a vertex (string) to the id of the GraphCanvas object displaying it
Method Details [hide private]

__init__(self, graph, parent=None, edit=True, colour_user_actions=True, pp_vertex=None, **config)
(Constructor)

source code 

Initialises a GraphCanvas to be a TKinter Canvas with extras.

graph is not altered by any of this class's methods

Parameters:
  • graph (Graph) - Graph to be edited/displayed
  • parent (Tkinter widget) - The canvas's parent widget
  • edit (Boolean) - Whether to allow the graph to be edited
  • colour_user_actions (Boolean) - Whether to colour user actions
  • pp_vertex (Function, returning a string) - A function mapping graph vertices to the string used for the text of the Tkinter.Canvas text object representing it. If unsupplied the identity function is used
  • config (various) - Any extra configuration parameters
Overrides: Tkinter.BaseWidget.__init__

arc_config(self, vertex1, vertex2, **config)

source code 

Alter an arc/edge by named Tkinter options

Does nothing silently if there is no arc between these vertices

Parameters:
  • vertex1 (Immutable) - A vertex in the graph at one end of the arc
  • vertex2 (Immutable) - A vertex in the graph at the other end of the arc
  • config (Dictionary of keywords) - Configuration options
Raises:
  • KeyError - If either vertex does not exist

drawarc_vertices(self, vertex1, vertex2, **config)

source code 

Draw a line or arrow between two named vertices

Parameters:
  • vertex1 (String) - First vertex
  • vertex2 (String) - Second vertex
  • config (Various) - Options to pass to create_line
Raises:
  • KeyError - If either vertex1 or vertex2 do not name an existing vertex

graph(self)

source code 

Return the displayed graph as a tuple

Suitable for passing to Graphs.Graph.reinit. Note that the vertices will be those displayed. These may have been altered from the vertices originally given at construction time using the pp_vertex option of __init__.

Returns: Tuple
vertices, arrows, lines, vertex_positions of the displayed graph

vertex_config(self, vertex, **config)

source code 

Alter a vertex by named Tkinter options

Parameters:
  • vertex (String) - A vertex in the graph
  • config (Dictionary of keywords) - Configuration options

_bbsect(bb, origin)
Static Method

source code 

Gets intersection of bounding box and a line.

Given a line drawn between the centre of a rectangle and some other point, finds the intersection of that line and the rectangle's boundary. This is used to prevent arcs overwriting the text which represents a node.

Parameters:
  • bb (Tuple) - Bounding box
  • origin (Tuple) - Origin of line

_drawarc(self, **config)

source code 

Draws a line or arrow from current node under pointer to selected node.

Does various tedious checks and then draws arc. The arc is tagged with the tags of the nodes it connects. This is the only place parent-child relations are stored.

Parameters:
  • config - Options to pass to _drawarc2
  • config - Various

_drawarc2(self, node_id1, node_id2, **config)

source code 

Draw a line or arrow between two vertices

Parameters:
  • node_id1 (int) - Id of first vertex
  • node_id2 (int) - Id of second vertex
  • config (Various) - Options to pass to create_line

_drawarrow(self, event)

source code 

Draw an arrow from current node under pointer to selected node.

Parameters:
  • event (Tkinter.Event) - Event at time this is called

_drawline(self, event)

source code 

Draw a line from current node under pointer to selected node.

Parameters:
  • event (Tkinter.Event) - Event at time this is called

_ends(self, ends)

source code 

Given two nodes, finds co-ords for an arc between them.

Arc will not overwrite the node text.

Parameters:
  • ends (Tuple of ints) - The two node ids
Returns: Tuple
The co-ords at the frm end and then the co-ords for the to end

_id_to_tag(id)
Static Method

source code 

Returns a node's unique tag from its Canvas id.

Parameters:
  • id (int) - Id of a node
Returns: String
The unique tag for a node

_movenode(self, event)

source code 

Moves the selected node to a new position on the Canvas.

Parameters:
  • event (Tkinter.Event) - Event at time this is called

_newnode(self, event)

source code 

Creates a node

Note that the node name given by the user is passed through the instance's _pp_vertex function.

Parameters:
  • event (Tkinter.Event) - Event at time this is called

_select(self, ident)

source code 

Selects a Canvas object using its id.

Parameters:
  • ident (int) - Id of object to be selected

_sel_current(self, event)

source code 

Selects a node.

Parameters:
  • event (Tkinter.Event) - Event at time this is called

_sel_or_new(self, event)

source code 

Selects or creates a node.

Parameters:
  • event (Tkinter.Event) - Event at time this is called

_tags_to_ids(tags)
Static Method

source code 

Returns two node ids given corresponding two node tags.

Parameters:
  • tags (Tuple) - Pairs of tags
Returns: Tuple
Ids corresponding to the tags