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-click selects the nearest already-placed vertex (PointPickerCompanion only)

  • Ctrl+Z undoes the last vertex (PointPickerCompanion only)

  • comp.stop() deactivates the action; collected data is preserved

  • comp.destroy() deactivates + unregisters all handlers

Module Contents

class wolfhece.plugins.factory.PointPickerCompanion[source]

Bases: wolfhece.plugins.abc.AbstractUICompanion

Inheritance diagram of wolfhece.plugins.factory.PointPickerCompanion

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

points[source]

Collected world-coordinate pairs (snapped).

Type:

list[tuple[float, float]]

selected[source]

Index of the highlighted point (-1 = none).

Type:

int

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

COLOR_NORMAL: tuple = (1.0, 0.0, 0.0, 1.0)[source]
COLOR_SELECTED: tuple = (1.0, 0.8, 0.0, 1.0)[source]
CROSS_FRACTION: float = 0.01[source]
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.

property points: list[tuple[float, float]][source]
property selected: int[source]
actions_spec()[source]

Declare interactive handlers to register with the viewer.

Override this method declaratively by returning ActionSpec and/or MultiStepSpec rows. 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 return StepTransition values (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 point-picker action.

_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]
_paint() None[source]
class wolfhece.plugins.factory.PolylineCompanion[source]

Bases: wolfhece.plugins.abc.AbstractUICompanion

Inheritance diagram of wolfhece.plugins.factory.PolylineCompanion

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]]

finished[source]

True once Enter has been pressed with ≥ 2 vertices.

Type:

bool

Customisation
-------------
Override ``COLOR_LINE``, ``COLOR_VERTEX``, ``CROSS_FRACTION``,
``LINE_WIDTH`` at the class level.
COLOR_LINE: tuple = (0.0, 0.5, 1.0, 1.0)[source]
COLOR_VERTEX: tuple = (1.0, 1.0, 1.0, 1.0)[source]
CROSS_FRACTION: float = 0.008[source]
LINE_WIDTH: float = 2.0[source]
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.

property vertices: list[tuple[float, float]][source]
property finished: bool[source]
actions_spec()[source]

Declare interactive handlers to register with the viewer.

Override this method declaratively by returning ActionSpec and/or MultiStepSpec rows. 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 return StepTransition values (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]

Reset state and activate the polyline-recording action.

_rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
_key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
_paint() None[source]
class wolfhece.plugins.factory.MultiPolylineCompanion[source]

Bases: wolfhece.plugins.abc.AbstractUICompanion

Inheritance diagram of wolfhece.plugins.factory.MultiPolylineCompanion

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

polylines[source]

All finalised polylines.

Type:

list[list[tuple[float, float]]]

current[source]

Vertices of the line currently being drawn.

Type:

list[tuple[float, float]]

COLOR_DONE: tuple = (0.2, 0.6, 1.0, 1.0)[source]
COLOR_CURRENT: tuple = (1.0, 0.5, 0.0, 1.0)[source]
COLOR_VERTEX: tuple = (1.0, 1.0, 1.0, 0.8)[source]
CROSS_FRACTION: float = 0.007[source]
LINE_WIDTH: float = 1.5[source]
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.

property polylines: list[list[tuple[float, float]]][source]
property current: list[tuple[float, float]][source]
actions_spec()[source]

Declare interactive handlers to register with the viewer.

Override this method declaratively by returning ActionSpec and/or MultiStepSpec rows. 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 return StepTransition values (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]

Reset state and activate the multi-polyline recording action.

_rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
_key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
_paint() None[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

Inheritance diagram of wolfhece.plugins.factory.MultiPolylineZonesCompanion

Record multiple polylines and store them in a Zones object.

Behaves like MultiPolylineCompanion for the interaction, but instead of keeping the results in a plain Python list each accepted polyline is immediately written into a Zoneszonevector hierarchy 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 zones object as a new zone

  • Esc — discard the current in-progress vertices and stop the action; already-finalised lines in zones are preserved

zones[source]

The backing Zones object. None until the first line is accepted. Once created it is the same object that is attached to the viewer (when auto_attach is True).

Type:

Zones | None

current[source]

Vertices of the line currently being digitised.

Type:

list[tuple[float, float]]

param zones_id:

Identifier string for the Zones object. Defaults to 'multi_polyline'.

type zones_id:

str

param auto_attach:

When True (default) the Zones object is added to the viewer via viewer.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)

COLOR_DONE: tuple = (0.2, 0.6, 1.0, 1.0)[source]
COLOR_CURRENT: tuple = (1.0, 0.5, 0.0, 1.0)[source]
COLOR_VERTEX: tuple = (1.0, 1.0, 1.0, 0.8)[source]
CROSS_FRACTION: float = 0.007[source]
LINE_WIDTH: float = 1.5[source]
_zones_id = 'multi_polyline'[source]
_auto_attach = True[source]
_zone_name_prefix = 'zone'[source]
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.

property zones: Zones | None[source]
property current: list[tuple[float, float]][source]
actions_spec()[source]

Declare interactive handlers to register with the viewer.

Override this method declaratively by returning ActionSpec and/or MultiStepSpec rows. 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 return StepTransition values (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 zones are preserved so that the session can be resumed.

attach_zones(id: str | None = None) Zones | None[source]

Manually add zones to the viewer.

This is a no-op when auto_attach is True (attachment already happened) or when zones is None (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 Zones object, or None if nothing has been digitised yet.

clear_zones() None[source]

Discard all accepted lines and reset zones to None.

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.

_finalise_current() None[source]

Move current vertices into a new zone+vector inside zones.

_rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
_key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
_paint() None[source]
class wolfhece.plugins.factory.PolygonCompanion[source]

Bases: wolfhece.plugins.abc.AbstractUICompanion

Inheritance diagram of wolfhece.plugins.factory.PolygonCompanion

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]]]

current[source]

Vertices of the polygon currently being drawn.

Type:

list[tuple[float, float]]

COLOR_DONE: tuple = (0.0, 0.8, 0.2, 1.0)[source]
COLOR_CURRENT: tuple = (1.0, 0.5, 0.0, 1.0)[source]
COLOR_VERTEX: tuple = (1.0, 1.0, 1.0, 0.8)[source]
CROSS_FRACTION: float = 0.007[source]
LINE_WIDTH: float = 1.5[source]
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.

property polygons: list[list[tuple[float, float]]][source]
property current: list[tuple[float, float]][source]
actions_spec()[source]

Declare interactive handlers to register with the viewer.

Override this method declaratively by returning ActionSpec and/or MultiStepSpec rows. 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 return StepTransition values (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]

Reset state and activate the polygon-recording action.

_rdown(ctx: wolfhece._viewer_plugin_handlers.MouseContext) None[source]
_key(kb: wolfhece._viewer_plugin_handlers.KeyboardSnapshot) bool[source]
_paint() None[source]
wolfhece.plugins.factory.point_picker(viewer: wolfhece.PyDraw.WolfMapViewer, **kwargs) PointPickerCompanion[source]

Create, register and activate a PointPickerCompanion.

Parameters:
Returns:

The activated companion.

wolfhece.plugins.factory.polyline(viewer: wolfhece.PyDraw.WolfMapViewer, **kwargs) PolylineCompanion[source]

Create, register and activate a PolylineCompanion.

Parameters:
  • viewer – The WolfMapViewer instance.

  • 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 WolfMapViewer instance.

  • 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 WolfMapViewer instance.

  • zones_id – Identifier of the Zones object that will be added to the viewer.

  • auto_attach – When True (default) the Zones object 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 WolfMapViewer instance.

  • kwargs – Forwarded to the constructor.

Returns:

The activated companion.