Generators

Generators are subclasses of

class boxes.Boxes[source]

Main class – Generator should subclass this

Most code is directly in this class. Subclass are supposed to over write the .__init__() and .render() method.

The Boxes class keeps a canvas object (self.ctx) that all drawing is made on. In addition it keeps a couple of global settings used for various drawing operations. See the .__init__() method for the details.

For implementing a new generator forking an existing one or using the boxes/generators/_template.py is probably easier than starting from scratch.

Many methods and attributes are for use of the subclasses. These methods are the interface for the user interfaces to interact with the generators:

Boxes.__init__() None[source]
Boxes.parseArgs(args=None)[source]

Parse command line parameters

Parameters:

args – (Default value = None) parameters, None for using sys.argv

Boxes.render()[source]

Implement this method in your subclass.

You will typically need to call .parseArgs() before calling this one

Boxes.open()[source]

Prepare for rendering

Create canvas and edge and other objects Call this before .render()

Boxes.close()[source]

Finish rendering

Flush canvas to disk and convert output to requested format if needed. Call after .render()

Handling Generators

To handle the generators there is code in the boxes.generators package.

class boxes.generators.UIGroup(name: str, title: str | None = None, description: str = '', image: str = '')[source]
add(box) None[source]
property image: str
property thumbnail: str
boxes.generators.getAllBoxGenerators() dict[str, type[Boxes]][source]
boxes.generators.getAllGeneratorModules() dict[str, ModuleType][source]

This adds generators to the user interfaces automatically. For this to work it is important that the class names are unique. So whenever you start a new generator please change the class name right away.