Package tdl :: Class _MetaConsole
[frames] | no frames]

Class _MetaConsole

source code

object --+
         |
        _MetaConsole
Known Subclasses:

Contains methods shared by both the Console and Window classes.

Instance Methods
 
__contains__(self, position)
Use ((x, y) in console) to check if a position is drawable on this console.
source code
 
blit(self, source, x=0, y=0, width=None, height=None, srcX=0, srcY=0)
Blit another console or Window onto the current console.
source code
 
drawChar(self, x, y, char, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))
Draws a single character.
source code
 
drawFrame(self, x, y, width, height, string, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))
Similar to drawRect but only draws the outline of the rectangle.
source code
 
drawRect(self, x, y, width, height, string, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))
Draws a rectangle starting from x and y and extending to width and height.
source code
 
drawStr(self, x, y, string, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))
Draws a string starting at x and y.
source code
(int, (r, g, b), (r, g, b))
getChar(self, x, y)
Return the character and colors of a tile as (ch, fg, bg)
source code
(int, int)
getSize(self)
Return the size of the console as (width, height)
source code
 
scroll(self, x, y)
Scroll the contents of the console in the direction of x,y.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties
  console
  height
  width

Inherited from object: __class__

Method Details

blit(self, source, x=0, y=0, width=None, height=None, srcX=0, srcY=0)

source code 

Blit another console or Window onto the current console.

By default it blits the entire source to the topleft corner.

Parameters:
  • source (Console or Window) - Source window can be a Console or Window instance. It can even blit to itself without any problems.
  • x (int) - X coordinate to blit to.
  • y (int) - Y coordinate to blit to.
  • width (int or None) - Width of the rectangle.

    Can be None to extend as far as possible to the bottom right corner of the blit area or can be a negative number to be sized reltive to the total size of the destination console.

  • height (int or None) - Height of the rectangle. See width.
  • srcX (int) - The source consoles x coordinate to blit from.
  • srcY (int) - The source consoles y coordinate to blit from.

drawChar(self, x, y, char, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))

source code 

Draws a single character.

Parameters:
  • x (int) - X coordinate to draw at.
  • y (int) - Y coordinate to draw at.
  • char (int, string, or None) - Should be an integer, single character string, or None.

    You can set the char parameter as None if you only want to change the colors of the tile.

  • fgcolor ((r, g, b) or None) - For fgcolor and bgcolor you use a 3 item list with integers ranging 0-255 or None.

    None will keep the current color at this position unchanged.

  • bgcolor ((r, g, b) or None) - Background color. See fgcolor
Raises:
  • AssertionError - Having x or y values that can't be placed inside of the console will raise an AssertionError. You can use always use ((x, y) in console) to check if a tile is drawable.

drawFrame(self, x, y, width, height, string, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))

source code 

Similar to drawRect but only draws the outline of the rectangle.

Parameters:
  • x (int) - x coordinate to draw at.
  • y (int) - y coordinate to draw at.
  • width (int or None) - Width of the rectangle.

    Can be None to extend to the bottom right of the console or can be a negative number to be sized reltive to the total size of the console.

  • height (int or None) - Height of the rectangle. See width.
  • string (int, string, or None) - Should be an integer, single character string, or None.

    You can set the char parameter as None if you only want to change the colors of an area.

  • fgcolor ((r, g, b) or None) - For fgcolor and bgcolor you use a 3 item list with integers ranging 0-255 or None.

    None will keep the current color at this position unchanged.

  • bgcolor ((r, g, b) or None) - Background color. See fgcolor
Raises:
  • AssertionError - Having x or y values that can't be placed inside of the console will raise an AssertionError.

    You can use always use ((x, y) in console) to check if a tile is drawable.

drawRect(self, x, y, width, height, string, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))

source code 

Draws a rectangle starting from x and y and extending to width and height.

If width or height are None then it will extend to the edge of the console.

Parameters:
  • x (int) - x coordinate to draw at.
  • y (int) - y coordinate to draw at.
  • width (int or None) - Width of the rectangle.

    Can be None to extend to the bottom right of the console or can be a negative number to be sized reltive to the total size of the console.

  • height (int or None) - Height of the rectangle. See width.
  • string (int, string, or None) - Should be an integer, single character string, or None.

    You can set the char parameter as None if you only want to change the colors of an area.

  • fgcolor ((r, g, b) or None) - For fgcolor and bgcolor you use a 3 item list with integers ranging 0-255 or None.

    None will keep the current color at this position unchanged.

  • bgcolor ((r, g, b) or None) - Background color. See fgcolor
Raises:
  • AssertionError - Having x or y values that can't be placed inside of the console will raise an AssertionError.

    You can use always use ((x, y) in console) to check if a tile is drawable.

drawStr(self, x, y, string, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0))

source code 

Draws a string starting at x and y. Optinally colored.

A string that goes past the right side will wrap around. A string wraping to below the console will raise a TDLError but will still be written out. This means you can safely ignore the errors with a try... except block if you're fine with partily written strings.

\r and \n are drawn on the console as normal character tiles. No special encoding is done and any string will translate to the character table as is.

For a string drawing operation that respects special characters see the Typewriter class.

Parameters:
  • x (int) - X coordinate to draw at.
  • y (int) - Y coordinate to draw at.
  • string (string or iterable) - Can be a string or an iterable of numbers.

    Special characters are ignored and rendered as any other character.

  • fgcolor ((r, g, b) or None) - For fgcolor and bgcolor you use a 3 item list with integers ranging 0-255 or None.

    None will keep the current color at this position unchanged.

  • bgcolor ((r, g, b) or None) - Background color. See fgcolor
Raises:
  • AssertionError - Having x or y values that can't be placed inside of the console will raise an AssertionError.

    You can use always use ((x, y) in console) to check if a tile is drawable.

getChar(self, x, y)

source code 

Return the character and colors of a tile as (ch, fg, bg)

This method runs very slowly as is not recommended to be called frequently.

Returns: (int, (r, g, b), (r, g, b))
Returns a 3-item tuple. The first item is an integer of the character at the position (x, y) the second and third are the foreground and background colors respectfully.

scroll(self, x, y)

source code 

Scroll the contents of the console in the direction of x,y.

Uncovered areas will be cleared.

Parameters:
  • x (int) - Distance to scroll along x-axis
  • y (int) - Distance to scroll along y-axis