wolfhece.plugins.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._plugin_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.plugins.factory.PointPickerCompanion[source]
Bases:
wolfhece.plugins.abc.AbstractUICompanion
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
- create_model() PointPickerModel[source]
Create the companion’s optional pure business model.
Override this to keep domain logic independent from UI concerns while staying in the same plugin module (companion + model in one file).
Default implementation returns
None.
- actions_spec()[source]
Declare interactive handlers to register with the viewer.
Override this method declaratively by returning
ActionSpecand/orMultiStepSpecrows. The proxy performs registration and handler adaptation:def actions_spec(self): return [ ActionSpec(self._pick.action_id, ldown=self._ldown, key=self._key), MultiStepSpec( 'wall', steps=[ StepSpec(hint='Pick first point', ldown=self._step1), StepSpec(hint='Pick second point', ldown=self._step2), ], ), ]
For
MultiStepSpec, handlers can returnStepTransitionvalues (or equivalent strings) to drive the runtime state machine.Return
None(or an empty iterable) when there is no action to register.Called automatically by
build(). Do not call directly.
- _rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _ldown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece.plugins.factory.PolylineCompanion[source]
Bases:
wolfhece.plugins.abc.AbstractUICompanion
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.
- create_model() PolylineModel[source]
Create the companion’s optional pure business model.
Override this to keep domain logic independent from UI concerns while staying in the same plugin module (companion + model in one file).
Default implementation returns
None.
- actions_spec()[source]
Declare interactive handlers to register with the viewer.
Override this method declaratively by returning
ActionSpecand/orMultiStepSpecrows. The proxy performs registration and handler adaptation:def actions_spec(self): return [ ActionSpec(self._pick.action_id, ldown=self._ldown, key=self._key), MultiStepSpec( 'wall', steps=[ StepSpec(hint='Pick first point', ldown=self._step1), StepSpec(hint='Pick second point', ldown=self._step2), ], ), ]
For
MultiStepSpec, handlers can returnStepTransitionvalues (or equivalent strings) to drive the runtime state machine.Return
None(or an empty iterable) when there is no action to register.Called automatically by
build(). Do not call directly.
- _rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece.plugins.factory.MultiPolylineCompanion[source]
Bases:
wolfhece.plugins.abc.AbstractUICompanion
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
- create_model() MultiPolylineModel[source]
Create the companion’s optional pure business model.
Override this to keep domain logic independent from UI concerns while staying in the same plugin module (companion + model in one file).
Default implementation returns
None.
- actions_spec()[source]
Declare interactive handlers to register with the viewer.
Override this method declaratively by returning
ActionSpecand/orMultiStepSpecrows. The proxy performs registration and handler adaptation:def actions_spec(self): return [ ActionSpec(self._pick.action_id, ldown=self._ldown, key=self._key), MultiStepSpec( 'wall', steps=[ StepSpec(hint='Pick first point', ldown=self._step1), StepSpec(hint='Pick second point', ldown=self._step2), ], ), ]
For
MultiStepSpec, handlers can returnStepTransitionvalues (or equivalent strings) to drive the runtime state machine.Return
None(or an empty iterable) when there is no action to register.Called automatically by
build(). Do not call directly.
- _rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece.plugins.factory.MultiPolylineZonesCompanion(*, zones_id: str = 'multi_polyline', auto_attach: bool = True, zone_name_prefix: str = 'zone')[source]
Bases:
wolfhece.plugins.abc.AbstractUICompanion
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 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)
- create_model() MultiPolylineZonesModel[source]
Create the companion’s optional pure business model.
Override this to keep domain logic independent from UI concerns while staying in the same plugin module (companion + model in one file).
Default implementation returns
None.
- actions_spec()[source]
Declare interactive handlers to register with the viewer.
Override this method declaratively by returning
ActionSpecand/orMultiStepSpecrows. The proxy performs registration and handler adaptation:def actions_spec(self): return [ ActionSpec(self._pick.action_id, ldown=self._ldown, key=self._key), MultiStepSpec( 'wall', steps=[ StepSpec(hint='Pick first point', ldown=self._step1), StepSpec(hint='Pick second point', ldown=self._step2), ], ), ]
For
MultiStepSpec, handlers can returnStepTransitionvalues (or equivalent strings) to drive the runtime state machine.Return
None(or an empty iterable) when there is no action to register.Called automatically by
build(). Do not call directly.
- 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(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- class wolfhece.plugins.factory.PolygonCompanion[source]
Bases:
wolfhece.plugins.abc.AbstractUICompanion
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]]]
- create_model() PolygonModel[source]
Create the companion’s optional pure business model.
Override this to keep domain logic independent from UI concerns while staying in the same plugin module (companion + model in one file).
Default implementation returns
None.
- actions_spec()[source]
Declare interactive handlers to register with the viewer.
Override this method declaratively by returning
ActionSpecand/orMultiStepSpecrows. The proxy performs registration and handler adaptation:def actions_spec(self): return [ ActionSpec(self._pick.action_id, ldown=self._ldown, key=self._key), MultiStepSpec( 'wall', steps=[ StepSpec(hint='Pick first point', ldown=self._step1), StepSpec(hint='Pick second point', ldown=self._step2), ], ), ]
For
MultiStepSpec, handlers can returnStepTransitionvalues (or equivalent strings) to drive the runtime state machine.Return
None(or an empty iterable) when there is no action to register.Called automatically by
build(). Do not call directly.
- _rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
- _key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
- wolfhece.plugins.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.plugins.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.plugins.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.plugins.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.plugins.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.