Skip to content

Commit 63eb140

Browse files
committed
spotlight moved to utils
1 parent cd431eb commit 63eb140

File tree

6 files changed

+239
-213
lines changed

6 files changed

+239
-213
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ repos:
117117
# Override python interpreter from .python-versions as that is too strict for pre-commit.ci
118118
args: ["-p3.13"]
119119

120-
- repo: https://github.com/DavidAnson/markdownlint-cli2
121-
rev: v0.18.1
122-
hooks:
123-
- id: markdownlint-cli2
124-
name: Lint markdown files
125-
args: ["--fix"]
120+
# - repo: https://github.com/DavidAnson/markdownlint-cli2
121+
# rev: v0.18.1
122+
# hooks:
123+
# - id: markdownlint-cli2
124+
# name: Lint markdown files
125+
# args: ["--fix"]
126126

127127
- repo: local
128128
hooks:

source/_magnifier/commands.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def zoomOut() -> None:
9696
def toggleFilter() -> None:
9797
"""Cycle through color filters"""
9898
magnifier: Magnifier = getMagnifier()
99-
log.info(f"Toggling filter for magnifier: {magnifier}")
99+
log.debug(f"Toggling filter for magnifier: {magnifier}")
100100
if magnifierIsActiveVerify(
101101
magnifier,
102102
MagnifierAction.TOGGLE_FILTER,
@@ -130,7 +130,7 @@ def toggleFullscreenMode() -> None:
130130
currentMode = magnifier.fullscreenMode
131131
idx = modes.index(currentMode)
132132
newMode = modes[(idx + 1) % len(modes)]
133-
log.info(f"Changing full-screen mode from {currentMode} to {newMode}")
133+
log.debug(f"Changing full-screen mode from {currentMode} to {newMode}")
134134
magnifier.fullscreenMode = newMode
135135
ui.message(
136136
pgettext(
@@ -152,9 +152,9 @@ def startSpotlight() -> None:
152152
magnifier,
153153
MagnifierAction.START_SPOTLIGHT,
154154
):
155-
log.info("trying to launch spotlight mode")
155+
log.debug("trying to launch spotlight mode")
156156
if magnifier._spotlightManager._spotlightIsActive:
157-
log.info("found spotlight manager and it is active")
157+
log.debug("found spotlight manager and it is active")
158158
ui.message(
159159
pgettext(
160160
"magnifier",
@@ -163,7 +163,7 @@ def startSpotlight() -> None:
163163
),
164164
)
165165
else:
166-
log.info("no active spotlight manager found, starting new one")
166+
log.debug("no active spotlight manager found, starting new one")
167167
magnifier._startSpotlight()
168168
ui.message(
169169
pgettext(

source/_magnifier/fullscreenMagnifier.py

Lines changed: 11 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
"""
99

1010
from logHandler import log
11-
from typing import Callable
12-
import ui
1311
import winUser
14-
import wx
1512
from winBindings import magnification
1613
from .magnifier import Magnifier
1714
from .utils.filterHandler import FilterMatrix
18-
from .utils.types import Filter, ZoomHistory, Coordinates, FullScreenMode, FocusType
15+
from .utils.spotlightManager import SpotlightManager
16+
from .utils.types import Filter, Coordinates, FullScreenMode, FocusType
1917
from .config import getDefaultFullscreenMode, shouldKeepMouseCentered
2018

2119

@@ -58,15 +56,15 @@ def event_gainFocus(
5856
obj,
5957
nextHandler,
6058
):
61-
log.info("Full-screen Magnifier gain focus event")
59+
log.debug("Full-screen Magnifier gain focus event")
6260
nextHandler()
6361

6462
def _startMagnifier(self) -> None:
6563
"""
6664
Start the Full-screen magnifier using windows DLL
6765
"""
6866
super()._startMagnifier()
69-
log.info(
67+
log.debug(
7068
f"Starting magnifier with zoom level {self.zoomLevel} and filter {self.filterType} and full-screen mode {self.fullscreenMode}",
7169
)
7270
# Initialize Magnification API if not already initialized
@@ -106,7 +104,7 @@ def _stopMagnifier(self) -> None:
106104
# Reset color effect to normal (identity matrix)
107105
magnification.MagSetFullscreenColorEffect(FilterMatrix.NORMAL.value)
108106
except Exception as e:
109-
log.info(f"Error resetting magnification: {e}")
107+
log.debug(f"Error resetting magnification: {e}")
110108

111109
# Uninitialize Magnification API
112110
try:
@@ -147,9 +145,9 @@ def _fullscreenMagnifier(self, coordinates: Coordinates) -> None:
147145
top,
148146
)
149147
if not result:
150-
log.info("Failed to set full-screen transform")
148+
log.debug("Failed to set full-screen transform")
151149
except AttributeError:
152-
log.info("Magnification API not available")
150+
log.debug("Magnification API not available")
153151

154152
def _getCoordinatesForMode(
155153
self,
@@ -165,9 +163,9 @@ def _getCoordinatesForMode(
165163

166164
match self._fullscreenMode:
167165
case FullScreenMode.RELATIVE:
168-
return self._relativePos(x, y)
166+
return self._relativePos((x, y))
169167
case FullScreenMode.BORDER:
170-
return self._borderPos(x, y)
168+
return self._borderPos((x, y))
171169
case FullScreenMode.CENTER:
172170
return coordinates
173171

@@ -176,7 +174,7 @@ def moveMouseToScreen(self) -> None:
176174
keep mouse in screen
177175
"""
178176
x, y = self.currentCoordinates
179-
left, top, visibleWidth, visibleHeight = self._getMagnifierPosition(x, y)
177+
left, top, visibleWidth, visibleHeight = self._getMagnifierPosition((x, y))
180178
centerX = int(left + (visibleWidth / 2))
181179
centerY = int(top + (visibleHeight / 2))
182180
winUser.setCursorPos(centerX, centerY)
@@ -258,7 +256,7 @@ def _startSpotlight(self) -> None:
258256
"""
259257
Launch Spotlight from Full-screen class
260258
"""
261-
log.info(f"Launching spotlight mode from full-screen magnifier with mode {self._fullscreenMode}")
259+
log.debug(f"Launching spotlight mode from full-screen magnifier with mode {self._fullscreenMode}")
262260
self._stopTimer()
263261
self._spotlightManager._startSpotlight()
264262

@@ -268,173 +266,3 @@ def _stopSpotlight(self) -> None:
268266
"""
269267
self._spotlightManager._spotlightIsActive = False
270268
self._startTimer(self._updateMagnifier)
271-
272-
273-
class SpotlightManager:
274-
def __init__(
275-
self,
276-
fullscreenMagnifier: FullScreenMagnifier,
277-
):
278-
self._fullscreenMagnifier: FullScreenMagnifier = fullscreenMagnifier
279-
self._spotlightIsActive: bool = False
280-
self._lastMousePosition = Coordinates(0, 0)
281-
self._timer: wx.CallLater | None = None
282-
self._animationSteps: int = 40
283-
self._currentCoordinates: Coordinates = fullscreenMagnifier._getFocusCoordinates()
284-
self._originalZoomLevel: float = fullscreenMagnifier.zoomLevel
285-
self._currentZoomLevel: float = fullscreenMagnifier.zoomLevel
286-
self._originalMode: FullScreenMode | None = None
287-
288-
def _startSpotlight(self) -> None:
289-
"""
290-
Start the spotlight
291-
"""
292-
log.info("start spotlight")
293-
self._spotlightIsActive = True
294-
295-
startCoords = self._fullscreenMagnifier._getFocusCoordinates()
296-
startCoords = self._fullscreenMagnifier._getCoordinatesForMode(startCoords)
297-
centerScreen = (
298-
self._fullscreenMagnifier._screenWidth // 2,
299-
self._fullscreenMagnifier._screenHeight // 2,
300-
)
301-
302-
# Save the current mode for zoom back
303-
self._originalMode = self._fullscreenMagnifier._fullscreenMode
304-
self._currentCoordinates = startCoords
305-
self._animateZoom(1.0, centerScreen, self._startMouseMonitoring)
306-
307-
def _stopSpotlight(self) -> None:
308-
"""
309-
Stop the spotlight
310-
"""
311-
log.info("stop spotlight")
312-
ui.message(
313-
pgettext(
314-
"magnifier",
315-
# Translators: Message announced when stopping the magnifier spotlight.
316-
"Magnifier spotlight stopped",
317-
),
318-
)
319-
if self._timer:
320-
self._timer.Stop()
321-
self._timer = None
322-
323-
self._spotlightIsActive = False
324-
self._fullscreenMagnifier._stopSpotlight()
325-
326-
def _animateZoom(
327-
self,
328-
targetZoom: float,
329-
targetCoordinates: Coordinates,
330-
callback: Callable[[], None],
331-
) -> None:
332-
"""
333-
Animate the zoom level change
334-
335-
:param targetZoom: The target zoom level
336-
:param targetCoordinates: The target Coordinates (x, y)
337-
:param callback: The function to call after animation completes
338-
"""
339-
self._animationStepsList = self._computeAnimationSteps(
340-
self._currentZoomLevel,
341-
targetZoom,
342-
self._currentCoordinates,
343-
targetCoordinates,
344-
)
345-
346-
self._executeStep(0, callback)
347-
348-
def _executeStep(
349-
self,
350-
stepIndex: int,
351-
callback: Callable[[], None],
352-
) -> None:
353-
"""
354-
Execute one animation step
355-
356-
:param stepIndex: The index of the current animation step
357-
:param callback: The function to call after animation completes
358-
"""
359-
360-
if stepIndex < len(self._animationStepsList):
361-
zoomLevel, (x, y) = self._animationStepsList[stepIndex]
362-
self._fullscreenMagnifier.zoomLevel = zoomLevel
363-
self._fullscreenMagnifier._fullscreenMagnifier((x, y))
364-
self._currentZoomLevel = zoomLevel
365-
self._currentCoordinates = (x, y)
366-
wx.CallLater(12, lambda: self._executeStep(stepIndex + 1, callback))
367-
else:
368-
if callback:
369-
callback()
370-
371-
def _startMouseMonitoring(self) -> None:
372-
"""
373-
Start monitoring the mouse position to detect idleness
374-
"""
375-
self._lastMousePosition = wx.GetMousePosition()
376-
self._timer = wx.CallLater(2000, self._checkMouseIdle)
377-
378-
def _checkMouseIdle(self) -> None:
379-
"""
380-
Check if the mouse has been idle
381-
"""
382-
currentMousePosition = wx.GetMousePosition()
383-
if currentMousePosition == self._lastMousePosition:
384-
self.zoomBack()
385-
else:
386-
# Mouse moved, continue monitoring
387-
self._lastMousePosition = currentMousePosition
388-
self._currentCoordinates = currentMousePosition
389-
self._timer = wx.CallLater(1500, self._checkMouseIdle)
390-
391-
def zoomBack(self) -> None:
392-
"""
393-
Zoom back to mouse position
394-
"""
395-
focusX, focusY = self._fullscreenMagnifier._getFocusCoordinates()
396-
397-
if self._originalMode == FullScreenMode.RELATIVE:
398-
savedZoom = self._fullscreenMagnifier.zoomLevel
399-
self._fullscreenMagnifier.zoomLevel = self._originalZoomLevel
400-
endCoordinates = self._fullscreenMagnifier._relativePos(focusX, focusY)
401-
self._fullscreenMagnifier.zoomLevel = savedZoom
402-
else:
403-
endCoordinates = (focusX, focusY)
404-
self._fullscreenMagnifier.lastScreenPosition = endCoordinates
405-
406-
self._animateZoom(self._originalZoomLevel, endCoordinates, self._stopSpotlight)
407-
408-
def _computeAnimationSteps(
409-
self,
410-
zoomStart: float,
411-
zoomEnd: float,
412-
coordinateStart: Coordinates,
413-
coordinateEnd: Coordinates,
414-
) -> list[ZoomHistory]:
415-
"""
416-
Compute all intermediate animation steps with zoom levels and Coordinates
417-
418-
:param zoomStart: Starting zoom level
419-
:param zoomEnd: Ending zoom level
420-
:param coordinateStart: Starting Coordinates (x, y)
421-
:param coordinateEnd: Ending Coordinates (x, y)
422-
423-
:returns ZoomHistory list: List of animation steps as ZoomHistory for each animation step
424-
"""
425-
startX, startY = coordinateStart
426-
endX, endY = coordinateEnd
427-
animationSteps = []
428-
429-
zoomDelta = (zoomEnd - zoomStart) / self._animationSteps
430-
coordDeltaX = (endX - startX) / self._animationSteps
431-
coordDeltaY = (endY - startY) / self._animationSteps
432-
433-
for step in range(1, self._animationSteps + 1):
434-
currentZoom = zoomStart + zoomDelta * step
435-
436-
currentX = startX + coordDeltaX * step
437-
currentY = startY + coordDeltaY * step
438-
439-
animationSteps.append((round(currentZoom, 2), (int(round(currentX)), int(round(currentY)))))
440-
return animationSteps

source/_magnifier/magnifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _stopTimer(self) -> None:
204204
self.timer.Stop()
205205
self.timer = None
206206
else:
207-
log.info("no timer to stop")
207+
log.debug("no timer to stop")
208208

209209
def _getMagnifierPosition(self, coordinates: Coordinates) -> MagnifierPosition:
210210
"""

0 commit comments

Comments
 (0)