Skip to content
Open
58 changes: 58 additions & 0 deletions source/_magnifier/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
getDefaultFilter,
getDefaultFullscreenMode,
ZoomLevel,
getFollowMouse,
getFollowSystemFocus,
getFollowReviewCursor,
getFollowNavigatorObject,
setFollowMouse,
setFollowSystemFocus,
setFollowReviewCursor,
setFollowNavigatorObject,
)
from .magnifier import Magnifier
from .fullscreenMagnifier import FullScreenMagnifier
Expand All @@ -25,6 +33,7 @@
MagnifierType,
FullScreenMode,
MagnifierAction,
MagnifierFollowFocusType,
)
from logHandler import log

Expand Down Expand Up @@ -175,6 +184,55 @@ def toggleFilter() -> None:
)


def toggleFollow(focusType: MagnifierFollowFocusType) -> None:
"""
Toggle the specified follow mode setting and update focus immediately.

:param focusType: The follow mode to toggle (mouse, system focus, review cursor, navigator object)
"""
magnifier: Magnifier = getMagnifier()
if magnifierIsActiveVerify(
magnifier,
MagnifierAction.TOGGLE_FOLLOW_SETTINGS,
):
match focusType:
case MagnifierFollowFocusType.MOUSE:
state = not getFollowMouse()
setFollowMouse(state)
case MagnifierFollowFocusType.SYSTEM_FOCUS:
state = not getFollowSystemFocus()
setFollowSystemFocus(state)
case MagnifierFollowFocusType.REVIEW:
state = not getFollowReviewCursor()
setFollowReviewCursor(state)
case MagnifierFollowFocusType.NAVIGATOR_OBJECT:
state = not getFollowNavigatorObject()
setFollowNavigatorObject(state)

magnifier._focusManager.updateFollowedFocus()

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".
"{setting} {state}",
).format(
setting=focusType.displayString,
state=pgettext(
"magnifier",
# Translators: State of the follow setting being toggled enabled.
"enabled",
)
if state
else pgettext(
"magnifier",
# Translators: State of the follow setting being toggled disabled.
"disabled",
),
),
)


def toggleFullscreenMode() -> None:
"""Cycle through full-screen focus modes (center, border, relative)"""
magnifier: Magnifier = getMagnifier()
Expand Down
77 changes: 71 additions & 6 deletions source/_magnifier/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ def setDefaultZoomLevel(zoomLevel: float) -> None:

:param zoomLevel: The zoom level to set.
"""

if "magnifier" not in config.conf:
config.conf["magnifier"] = {}
config.conf["magnifier"]["defaultZoomLevel"] = zoomLevel


Expand All @@ -99,9 +96,6 @@ def setDefaultPanStep(panStep: int) -> None:

:param panStep: The pan value to set.
"""

if "magnifier" not in config.conf:
config.conf["magnifier"] = {}
config.conf["magnifier"]["defaultPanStep"] = panStep


Expand All @@ -123,6 +117,77 @@ def setDefaultFilter(filter: Filter) -> None:
config.conf["magnifier"]["defaultFilter"] = filter.value


def setFollowMouse(value: bool) -> None:
"""
Set whether the magnifier should follow the mouse pointer.

:param value: True to follow mouse, False otherwise.
"""
config.conf["magnifier"]["followMouse"] = value


def getFollowMouse() -> bool:
"""
Check if magnifier should follow mouse pointer.

:return: True if magnifier should follow mouse, False otherwise.
"""
return config.conf["magnifier"]["followMouse"]


def setFollowSystemFocus(value: bool) -> None:
"""
Set whether the magnifier should follow system focus.

:param value: True to follow system focus, False otherwise.
"""
config.conf["magnifier"]["followSystemFocus"] = value


def getFollowSystemFocus() -> bool:
"""
Check if magnifier should follow system focus.

:return: True if magnifier should follow system focus, False otherwise.
"""
return config.conf["magnifier"]["followSystemFocus"]


def setFollowReviewCursor(value: bool) -> None:
"""
Set whether the magnifier should follow the review cursor.

:param value: True to follow review cursor, False otherwise.
"""
config.conf["magnifier"]["followReviewCursor"] = value


def getFollowReviewCursor() -> bool:
"""
Check if magnifier should follow review cursor.

:return: True if magnifier should follow review cursor, False otherwise.
"""
return config.conf["magnifier"]["followReviewCursor"]


def setFollowNavigatorObject(value: bool) -> None:
"""
Set whether the magnifier should follow the navigator object.
:param value: True to follow navigator object, False otherwise.
"""
config.conf["magnifier"]["followNavigatorObject"] = value


def getFollowNavigatorObject() -> bool:
"""
Check if magnifier should follow navigator object.

:return: True if magnifier should follow navigator object, False otherwise.
"""
return config.conf["magnifier"]["followNavigatorObject"]


def getDefaultFullscreenMode() -> FullScreenMode:
"""
Get default full-screen mode from config.
Expand Down
1 change: 0 additions & 1 deletion source/_magnifier/magnifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ def _pan(self, action: MagnifierAction) -> bool:
self._isManualPanning = True
self._currentCoordinates = Coordinates(x, y)
winUser.setCursorPos(x, y)
self._lastMousePosition = Coordinates(x, y)
Comment thread
Boumtchack marked this conversation as resolved.
Outdated
self._doUpdate()

return (x, y) != (originalX, originalY)
Expand Down
Loading
Loading