"""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]
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()