"""
Companion manager for weir menus and actions.
Extracted from PyDraw.WolfMapViewer.
"""
from __future__ import annotations
import logging
import wx
from typing import TYPE_CHECKING
from .PyTranslate import _
from ._action_kind import ActionKind
if TYPE_CHECKING:
from .PyDraw import WolfMapViewer
[docs]
class WeirManager:
"""Manages the &Weirs menu and its associated actions."""
def __init__(self, viewer: 'WolfMapViewer') -> None:
[docs]
self._item_add: wx.MenuItem | None = None
[docs]
self._item_find: wx.MenuItem | None = None
[docs]
self._item_edit: wx.MenuItem | None = None
# ------------------------------------------------------------------
# Menu build
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# Action handlers
# ------------------------------------------------------------------
[docs]
def on_add(self, e: wx.Event) -> None:
logging.info(_('!! To be implemented !!'))
[docs]
def on_edit(self, e: wx.Event) -> None:
from .PyDraw import draw_type
v = self._viewer
if v.active_weir is None:
logging.warning(_('No active weir to edit !'))
return
keys = v.get_list_keys(drawing_type=draw_type.VECTORS)
newid = v.active_weir.idx
while newid in keys:
newid = newid + '_'
v.add_object('vector', newobj=v.active_weir, id=newid)
[docs]
def on_find(self, e: wx.Event) -> None:
self._viewer.start_action(ActionKind.PICK_WEIR, _('Right click to pick the nearest weir'))
[docs]
def pick(self, x: float, y: float) -> None:
v = self._viewer
if v.active_weirs is None:
logging.warning(_('No weirs to pick !'))
return
v.active_weir = v.active_weirs.find_nearest(x, y)