-
-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy pathconfig.py
More file actions
168 lines (125 loc) · 3.79 KB
/
config.py
File metadata and controls
168 lines (125 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2025 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
"""
NVDA Magnifier module.
Handles module initialization, configuration and settings interaction.
"""
import config
from .utils.types import Filter, FullScreenMode
class ZoomLevel:
"""
Constants and utilities for zoom level management.
"""
MAX_ZOOM: float = 10.0
MIN_ZOOM: float = 1.0
STEP_FACTOR: float = 0.5
ZOOM_MESSAGE = pgettext(
"magnifier",
# Translators: Message announced when zooming in with {zoomLevel} being the target zoom level.
"{zoomLevel}x",
)
@classmethod
def zoom_range(cls) -> list[float]:
"""
Return the list of available zoom levels.
"""
start = round(cls.MIN_ZOOM / cls.STEP_FACTOR)
end = round(cls.MAX_ZOOM / cls.STEP_FACTOR)
return [i * cls.STEP_FACTOR for i in range(start, end + 1)]
@classmethod
def zoom_strings(cls) -> list[str]:
"""
Return localized zoom level strings.
"""
return [
cls.ZOOM_MESSAGE.format(
zoomLevel=f"{value:.1f}",
)
for value in cls.zoom_range()
]
def getZoomLevel() -> float:
"""
Get zoom level from config.
:return: The zoom level.
"""
zoomLevel = config.conf["magnifier"]["zoomLevel"]
return zoomLevel
def getZoomLevelString() -> str:
"""
Get zoom level as a formatted string.
:return: Formatted zoom level string.
"""
zoomLevel = getZoomLevel()
zoomValues = ZoomLevel.zoom_range()
zoomStrings = ZoomLevel.zoom_strings()
if not zoomValues:
# Fallback: format the current zoom level directly if no predefined values are available.
return ZoomLevel.ZOOM_MESSAGE.format(
zoomLevel=f"{zoomLevel:.1f}",
)
# Find the index of the zoom value closest to the configured zoom level.
closestIndex = min(
range(len(zoomValues)),
key=lambda i: abs(zoomValues[i] - zoomLevel),
)
return zoomStrings[closestIndex]
def setZoomLevel(zoomLevel: float) -> None:
"""
Set zoom level from settings.
:param zoomLevel: The zoom level to set.
"""
if "magnifier" not in config.conf:
config.conf["magnifier"] = {}
config.conf["magnifier"]["zoomLevel"] = zoomLevel
def getPanStep() -> int:
"""
Get pan value from config.
:return: The pan value.
"""
return config.conf["magnifier"]["panStep"]
def setPanStep(panStep: int) -> None:
"""
Set pan value from settings.
:param panStep: The pan value to set.
"""
if "magnifier" not in config.conf:
config.conf["magnifier"] = {}
config.conf["magnifier"]["panStep"] = panStep
def getFilter() -> Filter:
"""
Get filter from config.
:return: The filter.
"""
return Filter(config.conf["magnifier"]["filter"])
def setFilter(filter: Filter) -> None:
"""
Set filter from settings.
:param filter: The filter to set.
"""
config.conf["magnifier"]["filter"] = filter.value
def isTrueCentered() -> bool:
"""
Check if true centered mode is enabled in config.
:return: True if true centered mode is enabled, False otherwise.
"""
return config.conf["magnifier"]["isTrueCentered"]
def shouldKeepMouseCentered() -> bool:
"""
Check if mouse pointer should be kept centered in magnifier view.
:return: True if mouse should be kept centered, False otherwise.
"""
return config.conf["magnifier"]["keepMouseCentered"]
def getFullscreenMode() -> FullScreenMode:
"""
Get full-screen mode from config.
:return: The full-screen mode.
"""
return FullScreenMode(config.conf["magnifier"]["fullscreenMode"])
def setFullscreenMode(mode: FullScreenMode) -> None:
"""
Set full-screen mode from settings.
:param mode: The full-screen mode to set.
"""
config.conf["magnifier"]["fullscreenMode"] = mode.value