GraphicalLoader
loader.graphical.GraphicalLoader(metadata=None)
Factory for building GraphicalStore objects.
The loader accumulates sources and segments, then builds a store. This provides a fluent interface for constructing graphical timelines.
Examples
>>> loader = GraphicalLoader()
>>> idx = loader.add_image("score.png")
>>> loader.add_horizontal_segment(idx, x0=10, x1=500, y=100, name="system_1")
>>> loader.add_horizontal_segment(idx, x0=10, x1=500, y=200, name="system_2")
>>> store = loader.store
>>> # From PDF
>>> import pymupdf
>>> doc = pymupdf.open("score.pdf")
>>> loader = GraphicalLoader()
>>> idx = loader.add_pdf_page(doc, 0)
>>> loader.add_horizontal_segment(idx, x0=50, x1=550, y=100, name="page1")
Attributes
| metadata |
dict[str, Any] |
Optional metadata dictionary attached to the store. |
Methods
add_horizontal_segment
loader.graphical.GraphicalLoader.add_horizontal_segment(
source_index,
x0,
x1,
y,
name=None,
offset=None,
tolerance=10.0,
)
Add a horizontal line segment (convenience method).
This is the most common case for musical scores and spectrograms.
Parameters
| source_index |
int |
Index of the source image. |
required |
| x0 |
float |
Starting x coordinate (left edge). |
required |
| x1 |
float |
Ending x coordinate (right edge). |
required |
| y |
float |
Fixed y coordinate (vertical position). |
required |
| name |
str | None |
Optional human-readable name. |
None |
| offset |
float | None |
Timeline offset. If None, appends contiguously. |
None |
| tolerance |
float |
Distance tolerance for coordinate conversion. |
10.0 |
Returns
|
GraphicalSegment |
The created GraphicalSegment. |
add_image
loader.graphical.GraphicalLoader.add_image(path)
Add an image file as a source.
Parameters
| path |
Path | str |
Path to the image file. |
required |
Returns
|
int |
Index of the added source (for use in add_segment). |
Raises
|
FileNotFoundError |
If file doesn’t exist. |
|
ValueError |
If format is not supported. |
add_image_source
loader.graphical.GraphicalLoader.add_image_source(source)
Add a pre-constructed ImageSource.
Parameters
| source |
ImageSource |
The ImageSource to add. |
required |
Returns
|
int |
Index of the added source. |
add_pdf_embedded_image
loader.graphical.GraphicalLoader.add_pdf_embedded_image(doc, xref)
Add an embedded PDF image as a source.
Parameters
| doc |
'pymupdf.Document' |
An open pymupdf Document. |
required |
| xref |
int |
Cross-reference number of the image. |
required |
Returns
|
int |
Index of the added source. |
add_pdf_page
loader.graphical.GraphicalLoader.add_pdf_page(doc, page_index, dpi=150)
Add a PDF page (rendered as image) as a source.
Parameters
| doc |
'pymupdf.Document' |
An open pymupdf Document. |
required |
| page_index |
int |
Zero-based page index. |
required |
| dpi |
int |
Resolution for rendering. |
150 |
Returns
|
int |
Index of the added source. |
add_segment
loader.graphical.GraphicalLoader.add_segment(
source_index,
path,
name=None,
offset=None,
)
Add a segment with arbitrary path.
Parameters
| source_index |
int |
Index of the source image. |
required |
| path |
TimeAxisPath |
TimeAxisPath defining the time axis geometry. |
required |
| name |
str | None |
Optional human-readable name. |
None |
| offset |
float | None |
Timeline offset. If None, appends contiguously. |
None |
Returns
|
GraphicalSegment |
The created GraphicalSegment. |
Raises
|
IndexError |
If source_index is invalid. |
add_vertical_segment
loader.graphical.GraphicalLoader.add_vertical_segment(
source_index,
x,
y0,
y1,
name=None,
offset=None,
tolerance=10.0,
)
Add a vertical line segment (convenience method).
Parameters
| source_index |
int |
Index of the source image. |
required |
| x |
float |
Fixed x coordinate. |
required |
| y0 |
float |
Starting y coordinate (top). |
required |
| y1 |
float |
Ending y coordinate (bottom). |
required |
| name |
str | None |
Optional human-readable name. |
None |
| offset |
float | None |
Timeline offset. If None, appends contiguously. |
None |
| tolerance |
float |
Distance tolerance for coordinate conversion. |
10.0 |
Returns
|
GraphicalSegment |
The created GraphicalSegment. |
build
loader.graphical.GraphicalLoader.build()
Alias for :pyattr:store.
Returns
|
GraphicalStore |
GraphicalStore containing all sources and segments. |
clear
loader.graphical.GraphicalLoader.clear()
Clear all sources and segments.
reset_offset
loader.graphical.GraphicalLoader.reset_offset(offset=0.0)
Reset the current offset for contiguous segment addition.
Parameters
| offset |
float |
New offset value (default 0.0). |
0.0 |