canvascli package

Submodules

canvascli.canvas module

Drawing Canvas.

class canvascli.canvas.Canvas(width=None, height=None)[source]

Bases: object

Drawing Canvas.

An empty canvas can be defined but it needs to be created to allow drawing.

The canvas is based on 1-indexing, so all coordinates (x, y points) for drawing must be greater than 1.

The internal representation of the canvas is based on 0-indexing like all python containers and uses a list of lists.

  • This canvas currently only support an integer coordinate system.
  • Currently only horizontal or vertical lines are supported.
  • Horizontal and vertical lines will be drawn using ‘x’
  • The horizontal and vertical border of the canvas will be drawn using ‘-‘ and ‘|’ respectively.
DEFAULT_COLOR = 'o'
HBORDER = '-'
MARKER = 'x'
VBORDER = '|'
create(width, height)[source]

Create the canvas with a given width and height.

data

Return the list of list holding the canvas data values..

draw_line(x1, y1, x2, y2)[source]

Draw horizontal or vertical line on canvas on 1-based indexing.

draw_rectangle(x1, y1, x2, y2)[source]

Draw rectangle on canvas on 1-based indexing.

erase()[source]

Erase the contents of the canvas.

fill(x, y, color='o')[source]

Fill the entire area connected to x and y with color.

  • This method uses the “Forest Fire” algorithm. Could be improved, but should suffice for this application.
height

Return the current height of the canvas, or None if not set.

width

Return the current width of the canvas, or None if not set.

canvascli.cli module

Console script for canvascli.

canvascli.cli.main(commands_list=None, print_help=True)[source]

Main entry fucntion.

commands_list and print_help are useful for debugging and testing.

canvascli.parser module

CLI handler for canvas program based on a custom argparser.

exception canvascli.parser.ArgumentParserError(message)[source]

Bases: exceptions.Exception

Custom exception for ThrowingArgumentParser.

class canvascli.parser.CommandParserHandler[source]

Bases: object

CLI handler for canvas program based on argparse.

HELP = "Type 'H' for help"
create_canvas(width, height)[source]

Create a new canvas of given size.

create_parser()[source]

Create the custom parser to evaluate canvas CLI commands.

format_help()[source]

Format help for the cli canvas program.

This is based on argparse to reuse all the logic that takes care of validating input.

parse_args(args)[source]

Convenience method for calling the argument parser.

print_canvas()[source]

Convenience method for printing the Canvas.

print_help(args=None)[source]

Print help for the cli canvas program.

class canvascli.parser.ThrowingArgumentParser(prog=None, usage=None, description=None, epilog=None, version=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True)[source]

Bases: argparse.ArgumentParser

Custom argument parser that avoids exit on errors.

error(message)[source]

Override method to prevent SystemExit and raise custom exception.

canvascli.utils module

Test cases.

canvascli.utils.check_color(color)[source]

Check color and return cleansed value.

canvascli.utils.positive_int(value)[source]

Check positive integer value types.

Module contents

Top-level package for CanvasCLI.