omnicanvas.graphics (The various Graphics)

This module contains the various Graphics objects which can be painted to the canvas.

class omnicanvas.graphics.Graphic(name=None, line_width=1, line_style='-', line_color='#000000', rotation=(0, 0, 0), data=None)[source]

The base class of all Graphics - it would not orindarily need to be instantiated at this abstract level.

Its properties generally relate to lines, as all Graphics have an edge of some kind.

Parameters:
  • name (str) – An identifable name for the Graphic.
  • line_width – Defaults to 1.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle), in degrees.
  • data (dict) – Any data to be associated with the Graphic.
name(name=None)[source]

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
line_width(line_width=None)[source]

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
line_style(line_style=None)[source]

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_color(line_color=None)[source]

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
rotation()[source]

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple
rotate(x_pivot, y_pivot, angle)[source]

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

data()[source]

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
class omnicanvas.graphics.ShapeGraphic(*args, fill_color='#FFFFFF', opacity=1, **kwargs)[source]

Base class: Graphic

Shapes are Graphics which have an interior space of some kind, which in practice is most Graphics which aren’t just lines.

Its properties relate to the appearence of this interior space. It would not generally be instantiated directly.

Parameters:
  • fill_color (str) – Defaults to ‘#FFFFFF’.
  • opacity – The degree of transparency, from 0 to 1 (0 being invisible).
  • name (str) – An identifable name for the Graphic.
  • line_width – Defaults to 1.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle), in degrees.
  • data (dict) – Any data to be associated with the Graphic.
fill_color(fill_color=None)[source]

The colour of the shape’s interior space. Passing a value will update the fill_color property. All colours must be in the form #RRGGBB.

Parameters:fill_color (str) – If given, the Shape’s fill_color will be set to this.
Return type:str
opacity(opacity=None)[source]

The degree of transparency of the interior space, from 0 to 1 (0 being invisible). Passing a value will update the opacity property.

Parameters:opacity (floar) – If given, the Shape’s opacity will be set to this.
Return type:float
data()

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
line_color(line_color=None)

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
line_style(line_style=None)

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_width(line_width=None)

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
name(name=None)

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
rotate(x_pivot, y_pivot, angle)

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

rotation()

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple
class omnicanvas.graphics.BoxGraphic(x, y, width, height, *args, **kwargs)[source]

Base class: ShapeGraphic

BoxGraphics are shapes which are either a box themselves (such as Rectangle) or are defined by some kind of bounding box. It would not generally be instantiated directly.

Parameters:
  • x – The x-value of the top-left corner.
  • y – The y-value of the top-left corner.
  • width – The Box’s width in pixels.
  • height – The Box’s height in pixels.
  • fill_color (str) – Defaults to ‘#FFFFFF’.
  • opacity – The degree of transparency, from 0 to 1 (0 being invisible).
  • name (str) – An identifable name for the Graphic.
  • line_width – Defaults to 1.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle), in degrees.
  • data (dict) – Any data to be associated with the Box.
x(x=None)[source]

The x value of the Box’s upper-left corner coordinate. Passing a value will update the x property.

Parameters:x – If given, the Box’s x value will be set to this.
Return type:float or int
y(y=None)[source]

The y value of the Box’s upper-left corner coordinate. Passing a value will update the y property.

Parameters:y – If given, the Box’s y value will be set to this.
Return type:float or int
width(width=None)[source]

The width of the Box. Passing a value will update the width.

Parameters:width – If given, the Box’s width will be set to this.
Return type:float or int
height(height=None)[source]

The height of the Box. Passing a value will update the height.

Parameters:height – If given, the Box’s height will be set to this.
Return type:float or int
data()

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
fill_color(fill_color=None)

The colour of the shape’s interior space. Passing a value will update the fill_color property. All colours must be in the form #RRGGBB.

Parameters:fill_color (str) – If given, the Shape’s fill_color will be set to this.
Return type:str
line_color(line_color=None)

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
line_style(line_style=None)

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_width(line_width=None)

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
name(name=None)

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
opacity(opacity=None)

The degree of transparency of the interior space, from 0 to 1 (0 being invisible). Passing a value will update the opacity property.

Parameters:opacity (floar) – If given, the Shape’s opacity will be set to this.
Return type:float
rotate(x_pivot, y_pivot, angle)

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

rotation()

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple
class omnicanvas.graphics.Rectangle(*args, **kwargs)[source]

Base class: BoxGraphic

A rectangular graphic, represented as a Rectangle on screen.

Parameters:
  • x – The x-value of the top-left corner.
  • y – The y-value of the top-left corner.
  • width – The Rectangle’s width in pixels.
  • height – The Rectangle’s height in pixels.
  • fill_color (str) – Defaults to ‘#FFFFFF’.
  • opacity – The degree of transparency, from 0 to 1 (0 being invisible).
  • name (str) – An identifable name for the Graphic.
  • line_width – Defaults to 1.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle).
  • data (dict) – Any data to be associated with the Shape.
data()

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
fill_color(fill_color=None)

The colour of the shape’s interior space. Passing a value will update the fill_color property. All colours must be in the form #RRGGBB.

Parameters:fill_color (str) – If given, the Shape’s fill_color will be set to this.
Return type:str
height(height=None)

The height of the Box. Passing a value will update the height.

Parameters:height – If given, the Box’s height will be set to this.
Return type:float or int
line_color(line_color=None)

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
line_style(line_style=None)

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_width(line_width=None)

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
name(name=None)

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
opacity(opacity=None)

The degree of transparency of the interior space, from 0 to 1 (0 being invisible). Passing a value will update the opacity property.

Parameters:opacity (floar) – If given, the Shape’s opacity will be set to this.
Return type:float
rotate(x_pivot, y_pivot, angle)

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

rotation()

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple
width(width=None)

The width of the Box. Passing a value will update the width.

Parameters:width – If given, the Box’s width will be set to this.
Return type:float or int
x(x=None)

The x value of the Box’s upper-left corner coordinate. Passing a value will update the x property.

Parameters:x – If given, the Box’s x value will be set to this.
Return type:float or int
y(y=None)

The y value of the Box’s upper-left corner coordinate. Passing a value will update the y property.

Parameters:y – If given, the Box’s y value will be set to this.
Return type:float or int
class omnicanvas.graphics.Line(x1, y1, x2, y2, *args, **kwargs)[source]

Base class: Graphic

A straight line between two points.

Parameters:
  • x1 – The x-value of the start point.
  • y1 – The y-value of the start point.
  • x2 – The x-value of the end point.
  • y2 – The y-value of the end point.
  • name (str) – An identifable name for the Graphic.
  • line_width – Defaults to 1.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle), in degrees.
  • data (dict) – Any data to be associated with the Graphic.
x1(x1=None)[source]

The x value of the Line’s start point coordinate. Passing a value will update the x1 property.

Parameters:x1 – If given, the Line’s x1 value will be set to this.
Return type:float or int
y1(y1=None)[source]

The y value of the Line’s start point coordinate. Passing a value will update the y1 property.

Parameters:y1 – If given, the Line’s y1 value will be set to this.
Return type:float or int
x2(x2=None)[source]

The x value of the Line’s end point coordinate. Passing a value will update the x2 property.

Parameters:x2 – If given, the Line’s x2 value will be set to this.
Return type:float or int
y2(y2=None)[source]

The y value of the Line’s end point coordinate. Passing a value will update the y2 property.

Parameters:y2 – If given, the Line’s y2 value will be set to this.
Return type:float or int
data()

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
line_color(line_color=None)

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
line_style(line_style=None)

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_width(line_width=None)

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
name(name=None)

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
rotate(x_pivot, y_pivot, angle)

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

rotation()

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple
class omnicanvas.graphics.Polygon(*coordinates, **kwargs)[source]

Base class: ShapeGraphic

Polygons are shapes with an arbitrary number of vertices.

Parameters:
  • *coordinates – The coordinates as a sequence of alternating x and y values.
  • fill_color (str) – Defaults to ‘#FFFFFF’.
  • opacity – The degree of transparency, from 0 to 1 (0 being invisible).
  • name (str) – An identifable name for the Graphic.
  • line_width – Defaults to 1.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle), in degrees.
  • data (dict) – Any data to be associated with the Polygon.
Raises:
  • ValueError – if an odd number of coordinate values are given.
  • GeometryError – if there are fewer than three vertices.
coordinates(xy_pairs=False)[source]

Returns the coordinates of the Polygon. By default they will be returned as a single tuple of alternating x and y values.

(x1, y1, x2, y2, x3, y3...)

However, you can optionally have it return them as a tuple of xy two-tuple pairs with the xy_pairs argument.

((x1, y1), (x2, y2), (x3, y3)...)

Parameters:xy_pairs (bool) – if True, the coordinates will be returned as xy pairs (see above).
Return type:tuple
add_vertex(x, y)[source]

Adds a vertex to the Polygon. The vertex will be added at the end of the list of vertices.

Parameters:
  • x – The x-value of the new vertex’s coordinate.
  • y – The y-value of the new vertex’s coordinate.
remove_vertex(index)[source]

Removes a the vertex at the specified index from the Polygon.

Parameters:index (int) – The index of the vertex to be removed.
Raises:GeometryError – if removing a vertex would leave the Polygon with fewer than three vertices.
data()

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
fill_color(fill_color=None)

The colour of the shape’s interior space. Passing a value will update the fill_color property. All colours must be in the form #RRGGBB.

Parameters:fill_color (str) – If given, the Shape’s fill_color will be set to this.
Return type:str
line_color(line_color=None)

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
line_style(line_style=None)

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_width(line_width=None)

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
name(name=None)

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
opacity(opacity=None)

The degree of transparency of the interior space, from 0 to 1 (0 being invisible). Passing a value will update the opacity property.

Parameters:opacity (floar) – If given, the Shape’s opacity will be set to this.
Return type:float
rotate(x_pivot, y_pivot, angle)

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

rotation()

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple
class omnicanvas.graphics.Text(x, y, text, *args, font_size=18, fill_color='#000000', line_width=0, horizontal_align='center', vertical_align='center', **kwargs)[source]

Base class: ShapeGraphic

Graphics of textual information.

Parameters:
  • x – The Text’s x location.
  • y – The Text’s y location.
  • text (str) – The text to display.
  • font_size – The font size of the Text when displayed.
  • horizontal_align – The horizontal alignment of the Text. Acceptable values are left, center (default) and right.
  • vertical_align – The vertical alignment of the Text. Acceptable values are top, center (default) and bottom.
  • fill_color (str) – Defaults to ‘#FFFFFF’.
  • opacity – The degree of transparency, from 0 to 1 (0 being invisible).
  • name (str) – An identifable name for the Graphic.
  • line_width – Defaults to 0.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle), in degrees.
  • data (dict) – Any data to be associated with the Text.
x(x=None)[source]

The x-value of the Text’s location. How this point relates to the Text’s location is determined by horizontal_align and vertical_align. Passing a value will update the x property.

Parameters:x – If given, the Text’s x value will be set to this.
Return type:float or int
y(y=None)[source]

The y-value of the Text’s location. How this point relates to the Text’s location is determined by horizontal_align and vertical_align. Passing a value will update the y property.

Parameters:y – If given, the Text’s y value will be set to this.
Return type:float or int
text(text=None)[source]

The text that the the Graphic displays. If something other than a string is passed, the __str__ representation of that object will be used. Passing a value will update the text property.

Parameters:text – If given, the Text’s text value will be set to this.
Return type:str
font_size(font_size=None)[source]

The text’s font size, in pt. Passing a value will update the font_size.

Parameters:font_size – If given, the font_size value will be set to this.
Return type:int or float
horizontal_align(horizontal_align=None)[source]

The horizontal alignment of the text. If center the coordinate will represent the center of the Text. If left the Text will be to the left of the coordinate and if right the Text will be to the right. Passing a value will update the horizontal_align.

Parameters:horizontal_align (str) – If given, the horizontal_align value will be set to this.
Raises:ValueError – if you try to set horizontal_align to something other than the three allowed values.
Return type:str
vertical_align(vertical_align=None)[source]

The vertical alignment of the text. If center the coordinate will represent the center of the Text. If top the Text will be to the abovef the coordinate and if bottom the Text will be below. Passing a value will update the vertical_align.

Parameters:vertical_align (str) – If given, the vertical_align value will be set to this.
Raises:ValueError – if you try to set vertical_align to something other than the three allowed values.
Return type:str
data()

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
fill_color(fill_color=None)

The colour of the shape’s interior space. Passing a value will update the fill_color property. All colours must be in the form #RRGGBB.

Parameters:fill_color (str) – If given, the Shape’s fill_color will be set to this.
Return type:str
line_color(line_color=None)

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
line_style(line_style=None)

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_width(line_width=None)

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
name(name=None)

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
opacity(opacity=None)

The degree of transparency of the interior space, from 0 to 1 (0 being invisible). Passing a value will update the opacity property.

Parameters:opacity (floar) – If given, the Shape’s opacity will be set to this.
Return type:float
rotate(x_pivot, y_pivot, angle)

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

rotation()

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple
class omnicanvas.graphics.Polyline(*coordinates, **kwargs)[source]

Base class: Graphic

Polylines are lines with an arbitrary number of vertices. Unlike Polygons, the last vertex is not joined to the first one, and so they have no interior space.

Parameters:
  • *coordinates – The coordinates as a sequence of alternating x and y values.
  • line_width – Defaults to 1.
  • name (str) – An identifable name for the Graphic.
  • line_style (str) – The line pattern. Acceptable values are - (default), .. (dotted) or -- (dashed).
  • line_color (str) – Defaults to ‘#000000’.
  • rotation (tuple) – Any rotation to be applied, in the format (x of rotation point, y of rotation point, angle), in degrees.
  • data (dict) – Any data to be associated with the Polygon.
Raises:
  • ValueError – if an odd number of coordinate values are given.
  • GeometryError – if there are fewer than two vertices.
coordinates(xy_pairs=False)[source]

Returns the coordinates of the Polyline. By default they will be returned as a single tuple of alternating x and y values.

(x1, y1, x2, y2, x3, y3...)

However, you can optionally have it return them as a tuple of xy two-tuple pairs with the xy_pairs argument.

((x1, y1), (x2, y2), (x3, y3)...)

Parameters:xy_pairs (bool) – if True, the coordinates will be returned as xy pairs (see above).
Return type:tuple
add_vertex(x, y)[source]

Adds a vertex to the Polyline. The vertex will be added at the end of the list of vertices.

Parameters:
  • x – The x-value of the new vertex’s coordinate.
  • y – The y-value of the new vertex’s coordinate.
remove_vertex(index)[source]

Removes a the vertex at the specified index from the Polyline.

Parameters:index (int) – The index of the vertex to be removed.
Raises:GeometryError – if removing a vertex would leave the Polyline with fewer than two vertices.
data()

Returns any data associated with the Graphic as a dict. This dict is modifiable.

When rendered as SVG, the data will be turned into attribute="value" pairs in the SVG element, and is useful in, among other things, assigning JavaScript events to individual elements.

Return type:dict
line_color(line_color=None)

The colur of the Graphic’s edge. Passing a value will update the line_color property. All colours must be in the form #RRGGBB.

Parameters:line_color (str) – If given, the Graphic’s line_color will be set to this.
Return type:str
line_style(line_style=None)

The line pattern of the Graphic’s edge. Passing a value will update the line_style property. Acceptable values are - (default), .. (dotted) or -- (dashed).

Parameters:line_style (str) – If given, the Graphic’s line_style will be set to this.
Return type:str
line_width(line_width=None)

The width of the Graphic’s edge in pixels. Passing a value will update the line_width property.

Parameters:line_width – If given, the Graphic’s line_width will be set to this.
Return type:int
name(name=None)

An identifable name for the Graphic. Passing a value will update the name property.

Parameters:name – If given, the Graphic’s name will be set to this.
Return type:str
rotate(x_pivot, y_pivot, angle)

Rotates the Graphic about a point. The rotation will be clockwise, and the angle given must be between 0 and 360.

Note: rotations do not sum. If you rotate a Graphic once by 30° and then again by 100° about the same point, the end result will just be a rotation of 100° around that point, not 130°. This is because the method just sets the Graphic’s rotation property to whatever is given.

Parameters:
  • x_pivot (str) – The x value of the pivot point.
  • y_pivot (str) – The y value of the pivot point.
  • angle (str) – The (clockwise) angle of rotation, in degrees.
Raises:

ValueError – if the angle is not between 0 and 360.

rotation()

The rotation applied to the Graphic. It takes the form of a three number tuple - (pivot_x_coordinate, pivot_y_coordinate, angle). The angle is in degrees, and works clockwise.

Return type:tuple