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
9 changes: 5 additions & 4 deletions source/_magnifier/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

from typing import Literal
import ui
from . import getMagnifier, initialize, terminate
from . import getMagnifier, initialize, isActive, terminate
from .config import (
getZoomLevelString,
getFilter,
getFullscreenMode,
ZoomLevel,
getFollowState,
getFullscreenMode,
setEnabled,
setFollowState,
toggleAllFollowStates,
ZoomLevel,
)
from .magnifier import Magnifier
from .fullscreenMagnifier import FullScreenMagnifier
Expand Down Expand Up @@ -100,7 +101,6 @@ def toggleMagnifier() -> None:
"Cannot start magnifier: Screen Curtain is active. Please disable Screen Curtain first.",
),
)
return
else:
initialize()

Expand All @@ -118,6 +118,7 @@ def toggleMagnifier() -> None:
fullscreenMode=fullscreenMode.displayString,
),
)
setEnabled(isActive())


def zoom(direction: Direction) -> None:
Expand Down
20 changes: 19 additions & 1 deletion source/_magnifier/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2025 NV Access Limited, Antoine Haffreingue
# Copyright (C) 2025-2026 NV Access Limited, Antoine Haffreingue
# This file may be used under the terms of the GNU General Public License, version 2 or later, as modified by the NVDA license.
# For full terms and any additional permissions, see the NVDA license file: https://github.com/nvaccess/nvda/blob/master/copying.txt

Expand All @@ -13,6 +13,24 @@
from .utils.types import Filter, FullScreenMode, MagnifierFollowFocusType


def setEnabled(enable: bool) -> None:
"""
Set the config for the magnifier state (enable or disabled).

:param enabled: True if the magnifier is enabled, False if it is disabled.
Comment on lines +18 to +20
"""
config.conf["magnifier"]["enabled"] = enable


def getEnabled() -> bool:
"""
Check if the magnifier is enabled in config.

:return: True if the magnifier is enabled, False otherwise.
"""
return config.conf["magnifier"]["enabled"]


class ZoomLevel:
"""
Constants and utilities for zoom level management.
Expand Down
1 change: 1 addition & 0 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@

# Magnifier settings
[magnifier]
enabled = boolean(default=false)
zoomLevel = float(min=1.0, max=10.0, default=2.0)
isTrueCentered = boolean(default=False)
filter = string(default="normal")
Expand Down
25 changes: 21 additions & 4 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import keyboardHandler
import languageHandler
import logHandler
from _magnifier.commands import toggleMagnifier
import _magnifier.config as magnifierConfig
from _magnifier.utils.types import Filter, FullScreenMode, MagnifierFollowFocusType
import queueHandler
Expand Down Expand Up @@ -6035,6 +6036,17 @@ def makeSettings(
sizer=settingsSizer,
)

# Enable the magnifier
# Translators: The label for a setting in magnifier settings to enable or disable the magnifier.
enableMagnifierText = _("&Enable magnifier (immediate effect)")
self.enableMagnifierCheckBox = sHelper.addItem(wx.CheckBox(self, label=enableMagnifierText))
self.bindHelpEvent(
"MagnifierEnable",
self.enableMagnifierCheckBox,
)
self.enableMagnifierCheckBox.Bind(wx.EVT_CHECKBOX, self.onEnableMagnifierChange)
self.enableMagnifierCheckBox.SetValue(magnifierConfig.getEnabled())

# ZOOM SETTINGS
# Translators: The label for a setting in magnifier settings to select the zoom level.
zoomLabelText = _("&Zoom level:")
Expand All @@ -6052,7 +6064,7 @@ def makeSettings(
self.zoomList,
)

# Set value from config
# Set value from config
zoomLevel = magnifierConfig.getZoomLevel()
zoomIndex = bisect.bisect_left(zoomValues, zoomLevel)
# Find the closest value
Expand Down Expand Up @@ -6085,7 +6097,7 @@ def makeSettings(

# FILTER SETTINGS
# Translators: The label for a setting in magnifier settings to select the default filter
filterLabelText = _("&filter:")
filterLabelText = _("&Filter:")
filterChoices = [f.displayString for f in Filter]
self.filterList = sHelper.addLabeledControl(
filterLabelText,
Expand All @@ -6100,7 +6112,7 @@ def makeSettings(

# FULLSCREEN MODE SETTINGS
# Translators: The label for a setting in magnifier settings to select the full-screen mode
fullscreenModeLabelText = _("&fullscreen mode:")
fullscreenModeLabelText = _("F&ullscreen mode:")
fullscreenModeChoices = [mode.displayString for mode in FullScreenMode] if FullScreenMode else []
self.fullscreenModeList = sHelper.addLabeledControl(
fullscreenModeLabelText,
Expand Down Expand Up @@ -6156,7 +6168,7 @@ def makeSettings(

# KEEP MOUSE CENTERED
# Translators: The label for a checkbox to keep the mouse pointer centered in the magnifier view
keepMouseCenteredText = _("Keep &mouse pointer centered in magnifier view")
keepMouseCenteredText = _("Keep mouse pointer &centered in magnifier view")
self.keepMouseCenteredCheckBox = sHelper.addItem(wx.CheckBox(self, label=keepMouseCenteredText))
self.bindHelpEvent(
"MagnifierKeepMouseCentered",
Expand All @@ -6166,6 +6178,8 @@ def makeSettings(

def onSave(self):
"""Save the current selections to config."""
magnifierConfig.setEnabled(self.enableMagnifierCheckBox.GetValue())

selectedZoom = self.zoomList.GetSelection()
magnifierConfig.setZoomLevel(magnifierConfig.ZoomLevel.zoom_range()[selectedZoom])

Expand All @@ -6182,6 +6196,9 @@ def onSave(self):
magnifierConfig.setFollowState(focusType, checkBox.GetValue())
config.conf["magnifier"]["keepMouseCentered"] = self.keepMouseCenteredCheckBox.GetValue()

def onEnableMagnifierChange(self, evt: wx.CommandEvent):
toggleMagnifier()


class PrivacyAndSecuritySettingsPanel(SettingsPanel):
# Translators: The title of the privacy and security category in NVDA's settings.
Expand Down
5 changes: 5 additions & 0 deletions user_docs/en/userGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2871,6 +2871,11 @@ Key: `NVDA+control+w`
The Magnifier category in the NVDA Settings dialog allows you to configure the default behavior of NVDA's built-in [Magnifier](#Magnifier) feature.
This settings category contains the following options:

##### Enable Magnfier {#MagnifierEnable}

Enables the magnifier.
When toggled, the magnifier will start and stop immediately, rather than on-save.

##### Zoom level {#MagnifierZoom}

This slider allows you to set the zoom level when using the magnifier.
Expand Down
Loading