Extra¶
Arranger¶
- class pdpy_lib.extra.arranger.Arranger(canvas, verbose=False, hstep=1.5, vstep=1, xmargin=10, ymargin=10)[source]¶
Bases:
object
Arranger objects on a 2d surface
This class attempts to arrange objects graphically on the self.canvas. To use, simply import and call the class.
The main algorithm consists of initialization and three steps:
- Parameters
canvas (
pdpy.Canvas
) – The canvas to arrangeverbose (bool) – (optional) set verbosity level (default: False)
hstep (float) –
(optional) set the horizontal step factor for x-increments (default: 1.5)
This factor multiplies the width maxima of all nodes in a canvas.
vstep (float) –
(optional) set the vertical step factor for y-increments (default: 1)
This factor multiplies the height maxima of all nodes in a canvas.
xmargin (int) – (optional) set the initial x margin on the canvas (default: 10)
xmargin – (optional) set the initial x margin on the canvas (default: 10)
- Return type
None
- Raises
Exception – if there were errors during arrangement
ValueError – if the Canvas has no nodes to arrange
Example
Import the PdPy and Arranger classes
>>> from .classes.pdpy import PdPy >>> from .util.arrange import Arranger as arranger
Create the PdPy instance (and add some objects)
>>> pd = PdPy()
Call the function
>>> arranger(p)
- step1()[source]¶
Step 1: Take the object from the object list
This step takes no arguments and performs the following instructions:
take an object from the object list
place the object
pass the object to
step2()
without callback
If there are no objects on the list, it returns
- Return type
None
- step2(obj, relocate=False)[source]¶
Step 2: Take the object’s children from the object list
This step takes performs the following instructions:
return
if the obj has no childrenotherwise, pop all children from the object list
For each child, if the child is not on the object list:
If the child is not placed, place it, otherwise move it
If
relocate
isTrue
, run the relocator on that child
If there are popped children, pass them to
step3()
, otherwisereset y-position
and go back to
step1()
- Parameters
obj (
pdpy.Object
) – A patchable PdPy object based on object with a position attributerelocate (
callback
orNone
) – A callback function to perform object relocation
- Return type
None
- step3(obj, children)[source]¶
Step3: Place every child
For every child in the
children
list:Adjust y-position
Adjust x-position
Place the child
Pass the child to
step2()
withrelocate=True
- Parameters
obj (
pdpy_lib.core.object.Object
) – The PdPy object withposition
attributechildren (
list
) – The list of children whose parent is the passedobj
Translator¶
- class pdpy_lib.extra.translator.Translator(json)[source]¶
Bases:
Base
This class maintains and translates a pdpy Obj in memory.
This class loads a file in .pd or .json formats and keeps an internal mirror (aka, translation) between the two. The direction of the translation depends on the input file type. Use the save_* functions to write translations to disk. Alternatively, you can load a .pkl (aka, pickle) file containing a pdpy object.
- Parameters
json (
dict
) –A dictionary of arguments with the following keys:
to
: the target format. Can be json, xml, pd, or pkl.fro
: the source format. Can be json, xml, pd, or pkl.input
: An input file Path, will be formated using pathlib.Pathoutput
: An output file Path, will be formated using pathlib.Pathencoding
(str, defaults: ‘utf-8’): Encoding of the input filesource
(str, inferred from input_file): Source file typereflect
(bool): If set to True, performs a reflected translation