wolfhece._companion_factory
Pre-built companion classes for common interactive-selection patterns.
All four classes are ready to use as-is or to subclass. Override the
COLOR_* / *_FRACTION class attributes to change the visual style
without writing any method code.
Quick-start
from wolfhece._companion_factory import point_picker, polyline, multi_polyline, polygon
# One-liner: create + register + activate
comp = point_picker(viewer)
# … right-click on the map …
print(comp.points)
comp.destroy()
Interaction summary
Companion |
Add vertex |
Finish / accept |
Cancel / stop |
|---|---|---|---|
PointPickerCompanion |
Right-click |
(already done) |
Esc or stop() |
PolylineCompanion |
Right-click |
Enter (≥ 2 pts) |
Esc (discard) |
MultiPolylineCompanion |
Right-click |
Enter (≥ 2 pts) |
Esc stops action |
PolygonCompanion |
Right-click |
Enter (≥ 3 pts) |
Esc (discard) |
All companions:
left-clickselects the nearest already-placed vertex (PointPickerCompanion only)Ctrl+Zundoes the last vertex (PointPickerCompanion only)comp.stop()deactivates the action; collected data is preservedcomp.destroy()deactivates + unregisters all handlers
Module Contents
- class wolfhece._companion_factory.PointPickerCompanion(viewer: wolfhece.PyDraw.WolfMapViewer)[source]
Bases:
wolfhece._menu_companion_abc.AbstractCompanion
Collect isolated (x, y) points via right-click.
Interaction
Right-click — add a point at the snapped cursor position
Left-click — select the nearest point (highlighted in gold)
Ctrl+Z — remove the last point
Esc — deactivate the action; collected points are preserved
- Customisation
- -------------
- Override the class attributes to change colours/size without subclassing::
- class MyPicker(PointPickerCompanion):
COLOR_NORMAL = (0.0, 0.6, 1.0, 1.0) # blue COLOR_SELECTED = (1.0, 1.0, 0.0, 1.0) # yellow CROSS_FRACTION = 0.015
- _rdown(viewer, ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _ldown(viewer, ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(viewer, kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece._companion_factory.PolylineCompanion(viewer: wolfhece.PyDraw.WolfMapViewer)[source]
Bases:
wolfhece._menu_companion_abc.AbstractCompanion
Record a single polyline vertex by vertex.
Interaction
Right-click — append a vertex
Enter / Return — finalise the polyline (requires ≥ 2 vertices)
Esc — discard all vertices and deactivate
- vertices[source]
Ordered vertices of the recorded polyline. Empty after a cancelled interaction, populated after a successful Enter.
- Type:
list[tuple[float, float]]
- Customisation
- -------------
- Override ``COLOR_LINE``, ``COLOR_VERTEX``, ``CROSS_FRACTION``,
- ``LINE_WIDTH`` at the class level.
- _rdown(viewer, ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(viewer, kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece._companion_factory.MultiPolylineCompanion(viewer: wolfhece.PyDraw.WolfMapViewer)[source]
Bases:
wolfhece._menu_companion_abc.AbstractCompanion
Record multiple polylines in a single session.
Interaction
Right-click — append a vertex to the current in-progress line
Enter / Return — finalise the current line (≥ 2 vertices) and start a new one
Esc — discard the current in-progress line and deactivate; already-finalised lines are preserved
- _rdown(viewer, ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(viewer, kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece._companion_factory.MultiPolylineZonesCompanion(viewer: wolfhece.PyDraw.WolfMapViewer, *, zones_id: str = 'multi_polyline', auto_attach: bool = True, zone_name_prefix: str = 'zone')[source]
Bases:
wolfhece._menu_companion_abc.AbstractCompanion
Record multiple polylines and store them in a
Zonesobject.Behaves like
MultiPolylineCompanionfor the interaction, but instead of keeping the results in a plain Python list each accepted polyline is immediately written into aZones→zone→vectorhierarchy and — when auto_attach is enabled — added to the viewer so that it appears in the layers panel and can be exported.Interaction
Right-click — append a vertex to the current in-progress line
Enter / Return — finalise the current line (≥ 2 vertices); it is added to the
zonesobject as a newzoneEsc — discard the current in-progress vertices and stop the action; already-finalised lines in
zonesare preserved
- zones[source]
The backing
Zonesobject.Noneuntil the first line is accepted. Once created it is the same object that is attached to the viewer (when auto_attach isTrue).- Type:
Zones | None
- param viewer:
The map viewer.
- param zones_id:
Identifier string for the
Zonesobject. Defaults to'multi_polyline'.- type zones_id:
str
- param auto_attach:
When
True(default) theZonesobject is added to the viewer viaviewer.add_object('vector', …)on the first accepted polyline.- type auto_attach:
bool
- param zone_name_prefix:
Prefix for the generated zone names (
zone_001,zone_002, …).- type zone_name_prefix:
str
- param Customisation:
- param ————-:
- param Override the class attributes to change colours/line width:::
- class MyZonesCompanion(MultiPolylineZonesCompanion):
COLOR_DONE = (0.9, 0.2, 0.2, 1.0) COLOR_CURRENT = (1.0, 0.8, 0.0, 1.0)
- start() None[source]
Activate the multi-polyline action.
Only current is cleared; any already-accepted lines in
zonesare preserved so that the session can be resumed.
- attach_zones(id: str | None = None) Zones | None[source]
Manually add
zonesto the viewer.This is a no-op when auto_attach is
True(attachment already happened) or whenzonesisNone(no line accepted yet).- Parameters:
id – Override the id used when registering with the viewer (defaults to the zones_id given at construction time).
- Returns:
The
Zonesobject, orNoneif nothing has been digitised yet.
- clear_zones() None[source]
Discard all accepted lines and reset
zonestoNone.This does not remove the object from the viewer if it was already attached — call
viewer.get_obj_from_id(…)and remove it manually if needed.
- _ensure_zones() wolfhece.pyvertexvectors.Zones[source]
Return the Zones object, creating (and optionally attaching) it on the first call.
- _rdown(viewer, ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(viewer, kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece._companion_factory.PolygonCompanion(viewer: wolfhece.PyDraw.WolfMapViewer)[source]
Bases:
wolfhece._menu_companion_abc.AbstractCompanion
Record one or more closed polygons.
Interaction
Right-click — append a vertex to the current polygon
Enter / Return — close and finalise the current polygon (≥ 3 vertices)
Esc — discard the current in-progress polygon; finalised polygons are kept
- polygons[source]
All finalised polygons. The closing segment (last → first vertex) is implicit — it is drawn but not stored as a duplicate vertex.
- Type:
list[list[tuple[float, float]]]
- _rdown(viewer, ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(viewer, kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- wolfhece._companion_factory.point_picker(viewer: wolfhece.PyDraw.WolfMapViewer, **kwargs) PointPickerCompanion[source]
Create, register and activate a
PointPickerCompanion.- Parameters:
viewer – The
WolfMapViewerinstance.kwargs – Forwarded to
PointPickerCompanionconstructor (e.g.namespace=,dialogs=).
- Returns:
The activated companion.
- wolfhece._companion_factory.polyline(viewer: wolfhece.PyDraw.WolfMapViewer, **kwargs) PolylineCompanion[source]
Create, register and activate a
PolylineCompanion.- Parameters:
viewer – The
WolfMapViewerinstance.kwargs – Forwarded to the constructor.
- Returns:
The activated companion.
- wolfhece._companion_factory.multi_polyline(viewer: wolfhece.PyDraw.WolfMapViewer, **kwargs) MultiPolylineCompanion[source]
Create, register and activate a
MultiPolylineCompanion.- Parameters:
viewer – The
WolfMapViewerinstance.kwargs – Forwarded to the constructor.
- Returns:
The activated companion.
- wolfhece._companion_factory.multi_polyline_zones(viewer: wolfhece.PyDraw.WolfMapViewer, zones_id: str = 'multi_polyline', auto_attach: bool = True, **kwargs) MultiPolylineZonesCompanion[source]
Create, register and activate a
MultiPolylineZonesCompanion.- Parameters:
viewer – The
WolfMapViewerinstance.zones_id – Identifier of the
Zonesobject that will be added to the viewer.auto_attach – When
True(default) theZonesobject is added to the viewer automatically on the first accepted polyline.kwargs – Forwarded to the constructor.
- Returns:
The activated companion.
- wolfhece._companion_factory.polygon(viewer: wolfhece.PyDraw.WolfMapViewer, **kwargs) PolygonCompanion[source]
Create, register and activate a
PolygonCompanion.- Parameters:
viewer – The
WolfMapViewerinstance.kwargs – Forwarded to the constructor.
- Returns:
The activated companion.