Generator Arguments

Boxes.py uses the argparse standard library for handling the arguments for the generators. It is used directly for the boxes command line tool. But it also handles – with some additional code – the web interface and the Inkscape extensions. To make this work one has to limit the kind of parameters used. Boxes.py supports the following types:

  • int

  • float

  • str

  • boxes.boolarg – an alternative to bool that works with the web interface

  • boxes.argparseSections – multiple lengths e.g. for dividing up a box in one direction

and

class boxes.ArgparseEdgeType(edges: str | None = None)[source]

argparse type to select from a set of edge types

For the standard types there is code to create HTML and Inkscape extensions. The other types can have .html() and .inx() methods.

The argument parser need to be built in the .__init__() method after calling the method of the super class. Have a look at

BOX.__init__() None[source]

As many arguments are used over and over there is a function that can add the most common ones:

Boxes.buildArgParser(*l, **kw)[source]

Add commonly used arguments

Parameters:
  • l – parameter names

  • kw – parameters with new default values

Supported parameters are

  • floats: x, y, h, hi

  • argparseSections: sx, sy, sh

  • ArgparseEdgeType: bottom_edge, top_edge

  • boolarg: outside

  • str (selection): nema_mount

Check the source for details about the single arguments.

Other arguments can be added with the normal argparser API - namely

ArgumentParser.add_argument(dest, ..., name=value, ...)
ArgumentParser.add_argument(option_string, option_string, ..., name=value, ...) None

of the Boxes.argparser attribute.

Edge style arguments

Edges that work together share a Settings class (and object). These classes can create argparse groups:

classmethod Settings.parserArguments(parser, prefix=None, **defaults)[source]

See

BOX.__init__() None[source]

for a list of possible edge settings. These regular settings are used in the standard edge instances used everywhere. For special edge instances you can call them with a prefix parameter. But you then need to deal with the results on your own.

Default Arguments

The Default arguments get added automatically by the super class’s constructor.

Accessing the Arguments

For convenience content of the arguments are written to attributes of the Boxes instance before .render() is called. This is done by Boxes.parseArgs. But most people won’t need to care as this is handled by the framework. Be careful to not overwrite important methods or attributes by using conflicting argument names.