Source code for wolfhece._pictcollection_manager

"""Picture collection companion for WolfMapViewer.

All picture-collection-related menu and command logic lives here.
``WolfMapViewer`` holds a single instance as ``self._pictcollection`` 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__ = ['PictureCollectionManager']


[docs] class PictureCollectionManager: """Companion object that owns picture-collection 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 Pictures 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, _('&Pictures')) scaleall = self._menu.Append(wx.ID_ANY, _('Scale all pictures'), _('Scale all pictures in the collection')) pick = self._menu.Append(wx.ID_ANY, _('Pick a picture'), _('Right click to pick a picture')) hide = self._menu.Append(wx.ID_ANY, _('Hide all pictures'), _('Reset the picture collection')) allvisible= self._menu.Append(wx.ID_ANY, _('Show all pictures'), _('Set all pictures in the collection visible')) extract = self._menu.Append(wx.ID_ANY, _('Extract pictures'), _('Extract all visible pictures from the collection')) v.Bind(wx.EVT_MENU, self._on_scale_all, scaleall) v.Bind(wx.EVT_MENU, self._on_pick, pick) v.Bind(wx.EVT_MENU, self._on_hide_all, hide) v.Bind(wx.EVT_MENU, self._on_show_all, allvisible) v.Bind(wx.EVT_MENU, self._on_extract, extract)
[docs] def _on_pick(self, event: wx.Event) -> None: v = self._viewer if v.active_picturecollection is None: logging.warning(_('No active picture collection -- Please load data first')) return v.start_action('pick a picture', _('Pick a picture from the collection'))
[docs] def _on_scale_all(self, event: wx.Event) -> None: v = self._viewer if v.active_picturecollection is None: logging.warning(_('No active picture collection -- Please load data first')) return scalefactor = wx.GetTextFromUser( _('Enter the scale factor (default is 1.0)'), _('Scale factor'), '1.0', v ) if scalefactor == '': scalefactor = '1.0' try: scalefactor = float(scalefactor) except ValueError: logging.error(_('Invalid scale factor: {}').format(scalefactor)) wx.MessageBox(_('Invalid scale factor: {}').format(scalefactor), _('Error'), wx.OK | wx.ICON_ERROR) return v.active_picturecollection.scale_all_pictures(scalefactor) v.Refresh()
[docs] def _on_hide_all(self, event: wx.Event) -> None: v = self._viewer if v.active_picturecollection is None: logging.warning(_('No active picture collection -- Please load data first')) return v.active_picturecollection.hide_all_pictures() v.Refresh()
[docs] def _on_show_all(self, event: wx.Event) -> None: v = self._viewer if v.active_picturecollection is None: logging.warning(_('No active picture collection -- Please load data first')) return v.active_picturecollection.show_all_pictures() v.Refresh()
[docs] def _on_extract(self, event: wx.Event) -> None: v = self._viewer if v.active_picturecollection is None: logging.warning(_('No active picture collection -- Please load data first')) return dlg = wx.DirDialog(v, _('Choose directory to extract picture collection'), style=wx.DD_DEFAULT_STYLE) if dlg.ShowModal() == wx.ID_CANCEL: dlg.Destroy() else: dirpath = dlg.GetPath() dlg.Destroy() v.active_picturecollection.extract_pictures(dirpath) logging.info(_('Pictures extracted to {}').format(dirpath))