Source code for wolfhece._builtin_plugins.dot_picker.companion

"""
Dot Picker — example companion plugin.

Demonstrates the minimal pattern:
  * right-click adds a point
  * Ctrl+Z removes the last point
  * Esc deactivates

This file is a simplified wrapper around
:class:`wolfhece._companion_factory.PointPickerCompanion`.
Import the factory class directly in your own code if you only need the
behaviour without the plugin infrastructure.
"""
from wolfhece._companion_factory import PointPickerCompanion
from wolfhece._menu_companion_abc import ActionItem


[docs] class DotPickerCompanion(PointPickerCompanion): """Point-picker companion exposed as a plugin. Adds a *"Dot Picker"* entry to the viewer's menu bar. Inherits all interaction logic from :class:`PointPickerCompanion`. """
[docs] def menu_build(self) -> None: self._build_menu('Dot Picker', [ ActionItem('Pick points…', self._on_pick, 'Right-click to collect points'), ActionItem('Clear points', self._on_clear, 'Remove all collected points'), ]) # Register the action (inherited from PointPickerCompanion.start, but we # want it wired to the menu, so register once here and reuse later). self._register_action( self._action_id('pick'), rdown=self._rdown, ldown=self._ldown, key=self._key, paint=self._paint, )
[docs] def start(self) -> None: """Activate the pick action (called by the plugin manager).""" self._start_action( self._action_id('pick'), 'Right-click: add | Left-click: select | Ctrl+Z: undo | Esc: stop', )
# -- menu handlers -------------------------------------------------------
[docs] def _on_pick(self, event) -> None: self.start()
[docs] def _on_clear(self, event) -> None: self.points.clear() self.selected = -1 self._force_redraw() self._set_status('Dot Picker: all points cleared.')