Source code for wolfhece._landmap_manager

"""Landmap companion for WolfMapViewer.

All PlansTerrier / landmap menu and command logic lives here.
``WolfMapViewer`` holds a single instance as ``self._landmap_mgr`` and
exposes one-line delegators so external callers remain unaffected.
"""
from __future__ import annotations

import logging
from typing import TYPE_CHECKING

import wx

from .PyTranslate import _

if TYPE_CHECKING:
    from .PyDraw import WolfMapViewer

__all__ = ['LandmapManager']


[docs] class LandmapManager: """Companion object that owns landmap menu state and actions.""" def __init__(self, viewer: 'WolfMapViewer') -> None:
[docs] self._viewer = viewer
[docs] self._menu: wx.Menu | None = None
[docs] def menu_build(self) -> None: """Create and append the Landmap menu to the viewer menubar (once only).""" if self._menu is not None: return v = self._viewer self._menu = wx.Menu() v.menubar.Append(self._menu, _('&Landmap')) menupick_full = self._menu.Append(wx.ID_ANY, _('Pick landmap full...'), _('Pick landmap full resolution')) menupick_low = self._menu.Append(wx.ID_ANY, _('Pick landmap low...'), _('Pick landmap low resolution')) self._menu.AppendSeparator() menu_transparent = self._menu.Append(wx.ID_ANY, _('Transparent color '), _('Change transparent color associated to the landmap')) menu_tolerance = self._menu.Append(wx.ID_ANY, _('Set tolerance'), _('Set tolerance for the transparent color landmap')) menu_colors = self._menu.Append(wx.ID_ANY, _('Change colors'), _('Change color map associated to the landmap')) self._menu.Bind(wx.EVT_MENU, self.on_pick_full, menupick_full) self._menu.Bind(wx.EVT_MENU, self.on_pick_low, menupick_low) self._menu.Bind(wx.EVT_MENU, self.on_change_colors, menu_colors) self._menu.Bind(wx.EVT_MENU, self.on_transparent_color,menu_transparent) self._menu.Bind(wx.EVT_MENU, self.on_set_tolerance, menu_tolerance)
# ------------------------------------------------------------------ # Actions # ------------------------------------------------------------------
[docs] def on_pick_full(self, event: wx.Event) -> None: self._viewer.start_action('pick landmap full', _('Pick landmap - Full resolution'))
[docs] def on_pick_low(self, event: wx.Event) -> None: self._viewer.start_action('pick landmap low', _('Pick landmap - Low resolution'))
[docs] def on_transparent_color(self, event: wx.Event) -> None: v = self._viewer if v.active_landmap is None: logging.warning(_('No active landmap -- Please load data first')) return data = wx.ColourData() data.SetColour(v.active_landmap.transparent_color) with wx.ColourDialog(v, data) as dlg: if dlg.ShowModal() == wx.ID_OK: data = dlg.GetColourData() color = data.GetColour() v.active_landmap.set_transparent_color([color.Red(), color.Green(), color.Blue()])
[docs] def on_set_tolerance(self, event: wx.Event) -> None: v = self._viewer if v.active_landmap is None: logging.warning(_('No active landmap -- Please load data first')) return dlg = wx.TextEntryDialog(v, _('Set the tolerance for the transparent color'), _('Tolerance'), str(v.active_landmap.tolerance)) ret = dlg.ShowModal() if ret == wx.ID_CANCEL: dlg.Destroy() return tol = max(0, int(dlg.GetValue())) dlg.Destroy() v.active_landmap.set_tolerance(tol)
[docs] def on_change_colors(self, event: wx.Event) -> None: v = self._viewer if v.active_landmap is None: logging.warning(_('No active landmap -- Please load data first')) return data = wx.ColourData() data.SetColour(v.active_landmap.color) with wx.ColourDialog(v, data) as dlg: if dlg.ShowModal() == wx.ID_OK: data = dlg.GetColourData() color = data.GetColour() v.active_landmap.set_color(color)