Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions source/_magnifier/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from . import changeMagnifiedView, getMagnifier, start, stop
from .config import (
setMagnifiedView,
getFollowState,
getTrackingState,
setFilter,
setFollowState,
setFullscreenMode,
toggleAllFollowStates,
setTrackingState,
setFullscreenTrackingMode,
toggleAllTrackingStates,
ZoomLevel,
)
from .magnifier import Magnifier
Expand All @@ -26,7 +26,7 @@
Filter,
Direction,
MagnifiedView,
FullScreenMode,
FullScreenTrackingMode,
MagnifierAction,
MagnifierTrackingType,
)
Expand Down Expand Up @@ -199,67 +199,67 @@ def cycleMagnifiedView() -> None:
)


def toggleFollow(focusType: MagnifierTrackingType) -> None:
def toggleTracking() -> None:
"""
Toggle the specified follow mode setting.
Toggle the specified tracking mode setting.

:param focusType: The follow mode to toggle (mouse, system focus, review cursor, navigator object)
:param MagnifierTrackingType: The tracking mode to toggle (mouse, system focus, review cursor, navigator object)
"""
magnifier: Magnifier = getMagnifier()
if magnifierIsActiveVerify(
magnifier,
MagnifierAction.TOGGLE_FOLLOW_SETTINGS,
MagnifierAction.TOGGLE_TRACKING_SETTINGS,
):
state = not getFollowState(focusType)
setFollowState(focusType, state)
state = not getTrackingState(MagnifierTrackingType)
setTrackingState(MagnifierTrackingType, state)

ui.message(
pgettext(
"magnifier",
# Translators: Message announced when toggling a follow setting with {setting} being the name of the setting and {state} being either "enabled" or "disabled".
# Translators: Message announced when toggling a tracking setting with {setting} being the name of the setting and {state} being either "enabled" or "disabled".
"{setting} {state}",
).format(
setting=focusType.displayString,
setting=MagnifierTrackingType.displayString,
state=pgettext(
"magnifier",
# Translators: State of the follow setting being toggled enabled.
# Translators: State of the tracking setting being toggled enabled.
"enabled",
)
if state
else pgettext(
"magnifier",
# Translators: State of the follow setting being toggled disabled.
# Translators: State of the tracking setting being toggled disabled.
"disabled",
),
),
)


def toggleAllFollow() -> None:
"""Toggle all follow settings at once."""
def toggleAllTracking() -> None:
"""Toggle all tracking settings at once."""
magnifier: Magnifier = getMagnifier()
if magnifierIsActiveVerify(
magnifier,
MagnifierAction.TOGGLE_FOLLOW_SETTINGS,
MagnifierAction.TOGGLE_TRACKING_SETTINGS,
):
isDisabledNow = toggleAllFollowStates()
isDisabledNow = toggleAllTrackingStates()
if isDisabledNow:
stateMessage = pgettext(
"magnifier",
# Translators: State of all follow settings being toggled disabled.
# Translators: State of all tracking settings being toggled disabled.
"All tracking settings disabled",
)
else:
stateMessage = pgettext(
"magnifier",
# Translators: State of all follow settings being restored.
# Translators: State of all tracking settings being restored.
"Tracking settings restored",
)
ui.message(stateMessage)


def toggleFullscreenMode() -> None:
"""Cycle through full-screen focus modes (center, border, relative)"""
def cycleFullscreenTrackingMode() -> None:
"""Cycle through full-screen tracking modes (center, border, relative)"""
magnifier: Magnifier = getMagnifier()
if magnifierIsActiveVerify(
magnifier,
Expand All @@ -270,13 +270,13 @@ def toggleFullscreenMode() -> None:
MagnifierAction.CHANGE_FULLSCREEN_MODE,
):
fullscreenMagnifier: FullScreenMagnifier = magnifier
modes = list(FullScreenMode)
currentMode = fullscreenMagnifier._fullscreenMode
modes = list(FullScreenTrackingMode)
currentMode = fullscreenMagnifier._trackingMode
idx = modes.index(currentMode)
newMode = modes[(idx + 1) % len(modes)]
log.debug(f"Changing full-screen mode from {currentMode} to {newMode}")
fullscreenMagnifier._fullscreenMode = newMode
setFullscreenMode(newMode)
fullscreenMagnifier._trackingMode = newMode
setFullscreenTrackingMode(newMode)
ui.message(
pgettext(
"magnifier",
Expand Down
42 changes: 21 additions & 21 deletions source/_magnifier/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import config
from dataclasses import dataclass, field
from .utils.types import Filter, FullScreenMode, MagnifierTrackingType, MagnifiedView
from .utils.types import Filter, FullScreenTrackingMode, MagnifierTrackingType, MagnifiedView


def setEnabled(enable: bool) -> None:
Expand Down Expand Up @@ -179,47 +179,47 @@ def _ensureSavedStatesInitialized() -> None:
saveFollowStates()


def getFollowState(focusType: MagnifierTrackingType) -> bool:
def getTrackingState(trackingType: MagnifierTrackingType) -> bool:
"""
Get the current follow state for a given focus type.
Get the current follow state for a given tracking type.

:param focusType: The focus type to query.
:return: True if the magnifier follows the given focus type, False otherwise.
:param trackingType: The tracking type to query.
:return: True if the magnifier follows the given tracking type, False otherwise.
"""
return config.conf["magnifier"][_FOLLOW_CONFIG_KEYS[focusType]]
return config.conf["magnifier"][_FOLLOW_CONFIG_KEYS[trackingType]]


def setFollowState(focusType: MagnifierTrackingType, state: bool) -> None:
def setTrackingState(trackingType: MagnifierTrackingType, state: bool) -> None:
"""
Set the follow state for a given focus type.
Set the follow state for a given tracking type.

:param focusType: The focus type to update.
:param trackingType: The tracking type to update.
:param state: True to enable following, False to disable.
"""
config.conf["magnifier"][_FOLLOW_CONFIG_KEYS[focusType]] = state
config.conf["magnifier"][_FOLLOW_CONFIG_KEYS[trackingType]] = state


def saveFollowStates() -> None:
"""Save current follow states so they can be restored later."""
for focusType in _FOLLOW_CONFIG_KEYS:
_followStateOverride.savedStates[focusType] = getFollowState(focusType)
for trackingType in _FOLLOW_CONFIG_KEYS:
_followStateOverride.savedStates[trackingType] = getTrackingState(trackingType)


def toggleAllFollowStates() -> bool:
def toggleAllTrackingStates() -> bool:
"""
Toggle all follow states between forced-disabled and previously saved states.

:return: True when all follow states are forced disabled after the call, False when restored.
"""
_ensureSavedStatesInitialized()
if _followStateOverride.isActive:
for focusType, state in _followStateOverride.savedStates.items():
setFollowState(focusType, state)
for trackingType, state in _followStateOverride.savedStates.items():
setTrackingState(trackingType, state)
_followStateOverride.isActive = False
else:
saveFollowStates()
for focusType in _FOLLOW_CONFIG_KEYS:
setFollowState(focusType, False)
for trackingType in _FOLLOW_CONFIG_KEYS:
setTrackingState(trackingType, False)
_followStateOverride.isActive = True
return _followStateOverride.isActive

Expand All @@ -233,19 +233,19 @@ def isTrueCentered() -> bool:
return config.conf["magnifier"]["isTrueCentered"]


def getFullscreenMode() -> FullScreenMode:
def getFullscreenTrackingMode() -> FullScreenTrackingMode:
"""
Get full-screen mode from config.

:return: The full-screen mode.
"""
return FullScreenMode(config.conf["magnifier"]["fullscreenMode"])
return FullScreenTrackingMode(config.conf["magnifier"]["fullscreenTrackingMode"])


def setFullscreenMode(mode: FullScreenMode) -> None:
def setFullscreenTrackingMode(mode: FullScreenTrackingMode) -> None:
"""
Set full-screen mode from settings.

:param mode: The full-screen mode to set.
"""
config.conf["magnifier"]["fullscreenMode"] = mode.value
config.conf["magnifier"]["fullscreenTrackingMode"] = mode.value
18 changes: 9 additions & 9 deletions source/_magnifier/fullscreenMagnifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
from .utils.types import (
Filter,
MagnifiedView,
FullScreenMode,
FullScreenTrackingMode,
Size,
MagnifierParameters,
Coordinates,
)
from .config import getFullscreenMode, isTrueCentered
from .config import isTrueCentered, getFullscreenTrackingMode
from .utils.errorHandling import trackNativeMagnifierErrors


Expand All @@ -36,7 +36,7 @@ class FullScreenMagnifier(Magnifier):

def __init__(self):
super().__init__()
self._fullscreenMode = getFullscreenMode()
self._trackingMode = getFullscreenTrackingMode()
self.currentCoordinates = Coordinates(0, 0)
self._spotlightManager = SpotlightManager(self)
self._displaySize = Size(self._displayOrientation.width, self._displayOrientation.height)
Expand All @@ -62,7 +62,7 @@ def _startMagnifier(self) -> None:
"""
super()._startMagnifier()
log.debug(
f"Starting magnifier with zoom level {self.zoomLevel} and filter {self.filterType} and full-screen mode {self._fullscreenMode}",
f"Starting magnifier with zoom level {self.zoomLevel} and filter {self.filterType} and full-screen mode {self._trackingMode}",
)
try:
self._initializeNativeMagnification()
Expand Down Expand Up @@ -265,12 +265,12 @@ def _getCoordinatesForMode(
:return: Adjusted coordinates according to full-screen mode
"""

match self._fullscreenMode:
case FullScreenMode.RELATIVE:
match self._trackingMode:
case FullScreenTrackingMode.RELATIVE:
return self._relativePos(coordinates)
case FullScreenMode.BORDER:
case FullScreenTrackingMode.BORDER:
return self._borderPos(coordinates)
case FullScreenMode.CENTER:
case FullScreenTrackingMode.CENTER:
return coordinates

def _borderPos(
Expand Down Expand Up @@ -356,7 +356,7 @@ def _startSpotlight(self) -> None:
Launch Spotlight from Full-screen class
"""
log.debug(
f"Launching spotlight mode from full-screen magnifier with mode {self._fullscreenMode}",
f"Launching spotlight mode from full-screen magnifier with mode {self._trackingMode}",
)
self._stopTimer()
self._spotlightManager._startSpotlight()
Expand Down
10 changes: 5 additions & 5 deletions source/_magnifier/magnifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
setZoomLevel,
ZoomLevel,
)
from .utils.focusManager import FocusManager
from .utils.trackingManager import TrackingManager


class Magnifier:
Expand All @@ -48,7 +48,7 @@ def __init__(self):
self._zoomLevel: float = getZoomLevel()
self._panStep: int = getPanStep()
self._timer: None | wx.Timer = None
self._focusManager = FocusManager()
self._trackingManager = TrackingManager()
self._lastScreenPosition = Coordinates(0, 0)
self._currentCoordinates = Coordinates(0, 0)
self._lastFocusCoordinates = Coordinates(0, 0)
Expand Down Expand Up @@ -182,7 +182,7 @@ def _startMagnifier(self) -> None:
return

self._isActive = True
self.currentCoordinates = self._focusManager.getCurrentFocusCoordinates()
self.currentCoordinates = self._trackingManager.getCurrentTrackedCoordinates()

def _updateMagnifier(self) -> None:
"""
Expand All @@ -196,7 +196,7 @@ def _updateMagnifier(self) -> None:
try:
self._managePanning()
if not self._isManualPanning:
self.currentCoordinates = self._focusManager.getCurrentFocusCoordinates()
self.currentCoordinates = self._trackingManager.getCurrentTrackedCoordinates()
self._doUpdate()
self._consecutiveErrors = 0
self._recoveryAttempts = 0
Expand Down Expand Up @@ -350,7 +350,7 @@ def _managePanning(self) -> None:
"""
Ensure that manual panning mode (self._isManualPanning) is set to False when focus coordinates change.
"""
focusCoordinates = self._focusManager.getCurrentFocusCoordinates()
focusCoordinates = self._trackingManager.getCurrentTrackedCoordinates()
if self._isManualPanning:
if focusCoordinates != self._lastFocusCoordinates:
self._isManualPanning = False
Expand Down
16 changes: 9 additions & 7 deletions source/_magnifier/utils/spotlightManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from typing import TYPE_CHECKING, Callable
import ui
from .types import Coordinates, ZoomHistory, FullScreenMode
from .types import Coordinates, ZoomHistory, FullScreenTrackingMode
import wx
from logHandler import log

Expand All @@ -29,10 +29,12 @@ def __init__(
self._timer: wx.CallLater | None = None
self._animationSteps: int = 40
self._animationStepDelay: int = 12
self._currentCoordinates: Coordinates = fullscreenMagnifier._focusManager.getCurrentFocusCoordinates()
self._currentCoordinates: Coordinates = (
fullscreenMagnifier._trackingManager.getCurrentTrackedCoordinates()
)
self._originalZoomLevel: int = 0
self._currentZoomLevel: float = 0.0
self._originalMode: FullScreenMode | None = None
self._originalMode: FullScreenTrackingMode | None = None

def _startSpotlight(self) -> None:
"""
Expand All @@ -45,15 +47,15 @@ def _startSpotlight(self) -> None:

self._spotlightIsActive = True

startCoords = self._fullscreenMagnifier._focusManager.getCurrentFocusCoordinates()
startCoords = self._fullscreenMagnifier._trackingManager.getCurrentTrackedCoordinates()
startCoords = self._fullscreenMagnifier._getCoordinatesForMode(startCoords)
centerScreen = Coordinates(
self._fullscreenMagnifier._displayOrientation.width // 2,
self._fullscreenMagnifier._displayOrientation.height // 2,
)

# Save the current mode for zoom back
self._originalMode = self._fullscreenMagnifier._fullscreenMode
self._originalMode = self._fullscreenMagnifier._trackingMode
self._currentCoordinates = startCoords
self._animateZoom(ZoomHistory(1.0, centerScreen), self._startMouseMonitoring)

Expand Down Expand Up @@ -160,9 +162,9 @@ def zoomBack(self) -> None:
f"zoom back with original zoom level {self._originalZoomLevel} and current zoom level {self._currentZoomLevel}",
)

focus = self._fullscreenMagnifier._focusManager.getCurrentFocusCoordinates()
focus = self._fullscreenMagnifier._trackingManager.getCurrentTrackedCoordinates()

if self._originalMode == FullScreenMode.RELATIVE:
if self._originalMode == FullScreenTrackingMode.RELATIVE:
savedZoom = self._fullscreenMagnifier.zoomLevel
self._fullscreenMagnifier.zoomLevel = self._originalZoomLevel
endCoordinates = self._fullscreenMagnifier._relativePos(focus)
Expand Down
Loading
Loading