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

# Class _BaseConsole

source code

    object --+
             |
            _BaseConsole

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
(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
(width, height) |
get_size(self) Return the size of the console as (width, height) | source code
iter((x, y), ...) |
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__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`
Drawing Methods
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
clear(self, fg=Ellipsis, bg=Ellipsis) Clears the entire Console/Window. | source code
draw_char(self, x, y, char, fg=Ellipsis, bg=Ellipsis) Draws a single character. | source code
draw_frame(self, x, y, width, height, string, fg=Ellipsis, bg=Ellipsis) Similar to draw_rect but only draws the outline of the rectangle. | source code
draw_rect(self, x, y, width, height, string, fg=Ellipsis, bg=Ellipsis) Draws a rectangle starting from x and y and extending to width and height. | source code
draw_str(self, x, y, string, fg=Ellipsis, bg=Ellipsis) Draws a string starting at x and y. | source code
Printing Methods
(x, y) |
get_cursor(self) Return the virtual cursor position. | 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
set_colors(self, fg=None, bg=None) Sets the colors to be used with the print_str and draw_* methods. | 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

Instance Variables
| height The height of this console in tiles.
| width The width of this console in tiles.

Properties
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, 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.

### clear(self, fg=Ellipsis, bg=Ellipsis) | source code
Clears the entire Console/Window. Unlike other drawing functions, fg and bg can not be None. Parameters: `fg` ((r, g, b), int, or Ellipsis) - Can not be None. See Drawing and Colors at the module level docs `bg` ((r, g, b), int, or Ellipsis) - See fg `fg` ((r, g, b), int, or Ellipsis) - Foreground color. Must be a 3-item list with integers that range 0-255. Unlike most other operations you cannot use None here. To clear only the foreground or background use draw_rect. `bg` ((r, g, b), int, or Ellipsis) - Background color. See fg. See Also: draw_rect

### draw_char(self, x, y, char, fg=Ellipsis, bg=Ellipsis) | 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. `fg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs `bg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs 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. See Also: get_char

### draw_frame(self, x, y, width, height, string, fg=Ellipsis, bg=Ellipsis) | 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 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. `fg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs `bg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs 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. See Also: draw_rect, Window

### draw_rect(self, x, y, width, height, string, fg=Ellipsis, bg=Ellipsis) | 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. `fg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs `bg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs 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. See Also: clear, draw_frame

### draw_str(self, x, y, string, fg=Ellipsis, bg=Ellipsis) | source code
Draws a string starting at x and y. 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 print_str. 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. `fg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs `bg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs 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. See Also: print_str

### 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. See Also: draw_char

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

### 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. See Also: get_cursor, print_str, write

### 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 if set_mode is set to 'scroll'. Colors can be set with set_colors and the virtual cursor can be moved with move. Parameters: `string` (string) See Also: draw_str, move, set_colors, set_mode, write, Window

### scroll(self, x, y) | source code
Scroll the contents of the console in the direction of x,y. Uncovered areas will be cleared to the default background color. Does not move the virutal 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. See Also: set_colors

### set_colors(self, fg=None, bg=None) | source code
Sets the colors to be used with the print_str and draw_* methods. Values of None will only leave the current values unchanged. Parameters: `fg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs `bg` ((r, g, b), int, Ellipsis, or None) - See Drawing and Colors at the module level docs See Also: move, print_str

### 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 tdl.Window when doing this. See Also: write, print_str

### 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 Console or Window instance. This is a convoluted process and behaviour seen now can be excepted to change on later versions. Parameters: `string` (string) See Also: set_colors, set_mode, Window

Instance Variable Details

### height The height of this console in tiles. Do not overwrite this.

### width The width of this console in tiles. Do not overwrite this.