untdl._MetaConsole

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

# Class _MetaConsole

source code

    object --+
             |
            _MetaConsole

Known Subclasses:
  - Console
  - , Window

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
__init__(self) x.__init__(...) initializes x; see help(type(x)) for signature | source code
iter((x, y), ...) |
__iter__(self) Return an iterator with every possible (x, y) value for this console. | source code
blit(self, source, x=0, y=0, width=None, height=None, src_x=0, src_y=0) Blit another console or Window onto the current console. | source code
draw_char(self, x, y, char, fgcolor=`(`255`,` 255`,` 255`)`, bgcolor=`(`0`,` 0`,` 0`)`) Draws a single character. | source code
draw_frame(self, x, y, width, height, string, fgcolor=`(`255`,` 255`,` 255`)`, bgcolor=`(`0`,` 0`,` 0`)`) Similar to draw_rect but only draws the outline of the rectangle. | source code
draw_rect(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
draw_str(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)) |
get_char(self, x, y) Return the character and colors of a tile as (ch, fg, bg) | source code
(x, y) |
get_cursor(self) Return the virtual cursor position. | source code
(width, height) |
get_size(self) Return the size of the console as (width, height) | source code
move(self, x, y) Move the virtual cursor. | source code
print_str(self, string) Print a string at the virtual cursor. | source code
iter((x, y), ...) |
scroll(self, x, y) Scroll the contents of the console in the direction of x,y. | source code
set_colors(self, fg=None, bg=None) Sets the colors to be used with the print_str function. | source code
set_mode(self, mode) Configure how this console will react to the cursor writing past the end if the console. | source code
write(self, string) This method mimics basic file-like behaviour. | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
| console
| height
| width
Inherited from `object`: `__class__`

Method Details

### __init__(self) (Constructor) | source code
x.__init__(...) initializes x; see help(type(x)) for signature Overrides: object.__init__ (inherited documentation)

### __iter__(self) | source code
Return an iterator with every possible (x, y) value for this console. It goes without saying that working on the console this way is a slow process, especially for Python, and should be minimized. Returns: iter((x, y), ...)

### blit(self, source, x=0, y=0, width=None, height=None, src_x=0, src_y=0) | source code
Blit another console or Window onto the current console. By default it blits the entire source to the top left 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 relative to the total size of the destination console. `height` (int or None) - Height of the rectangle. See width. `src_x` (int) - The source consoles x coordinate to blit from. `src_y` (int) - The source consoles y coordinate to blit from.

### draw_char(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.

### draw_frame(self, x, y, width, height, string, fgcolor=`(`255`,` 255`,` 255`)`, bgcolor=`(`0`,` 0`,` 0`)`) | source code
Similar to draw_rect 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 relative 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.

### draw_rect(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 relative 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.

### draw_str(self, x, y, string, fgcolor=`(`255`,` 255`,` 255`)`, bgcolor=`(`0`,` 0`,` 0`)`) | source code
Draws a string starting at x and y. Optionally colored. A string that goes past the right side will wrap around. A string wrapping 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 partially 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.

### get_char(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.

### get_cursor(self) | source code
Return the virtual cursor position. Returns: (x, y) Returns (x, y) a 2-integer tuple containing where the next `addChar` or `addStr` will start at. This can be changed with the move method.

### move(self, x, y) | source code
Move the virtual cursor. Parameters: `x` (int) - X position to place the cursor. `y` (int) - Y position to place the cursor.

### print_str(self, string) | source code
Print a string at the virtual cursor. Handles special characters such as '\n' and '\r'. Printing past the bottom of the console will scroll everything upwards. Colors can be set with set_colors and the virtual cursor can be moved with move. Parameters: `string` (string)

### scroll(self, x, y) | source code
Scroll the contents of the console in the direction of x,y. Uncovered areas will be cleared. Does not move the virtual cursor. Parameters: `x` (int) - Distance to scroll along x-axis `y` (int) - Distance to scroll along y-axis Returns: iter((x, y), ...) Iterates over the (x, y) of any tile uncovered after scrolling.

### set_colors(self, fg=None, bg=None) | source code
Sets the colors to be used with the print_str function. Values of None will only leave the current values unchanged.

### set_mode(self, mode) | source code
Configure how this console will react to the cursor writing past the end if the console. This is for methods that use the virtual cursor, such as print_str. Parameters: `mode` (string) - Possible settings are: 'error' - A TDLError will be raised once the cursor reaches the end of the console. Everything up until the error will still be drawn. This is the default setting. 'scroll' - The console will scroll up as stuff is written to the end. You can restrict the region with untdl.Window when doing this.

### write(self, string) | source code
This method mimics basic file-like behaviour. Because of this method you can replace sys.stdout or sys.stderr with a `Typewriter` instance. This is a convoluted process and behaviour seen now can be excepted to change on later versions. Parameters: `string` (string)