Skip to content

Commit a395425

Browse files
authored
Merge e926a92 into ce28256
2 parents ce28256 + e926a92 commit a395425

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

source/gui/nvdaControls.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# -*- coding: UTF-8 -*-
2-
#A part of NonVisual Desktop Access (NVDA)
3-
#Copyright (C) 2016-2018 NV Access Limited, Derek Riemer
4-
#This file is covered by the GNU General Public License.
5-
#See the file COPYING for more details.
2+
# A part of NonVisual Desktop Access (NVDA)
3+
# Copyright (C) 2016-2021 NV Access Limited, Derek Riemer
4+
# This file is covered by the GNU General Public License.
5+
# See the file COPYING for more details.
66

7-
from ctypes.wintypes import BOOL
8-
from typing import Any, Tuple, Optional
97
import wx
10-
from comtypes import GUID
8+
from wx.lib import scrolledpanel
119
from wx.lib.mixins import listctrl as listmix
1210
from .dpiScalingHelper import DpiScalingHelperMixin
1311
from . import guiHelper
14-
import oleacc
1512
import winUser
1613
import winsound
14+
import math
15+
1716
from collections.abc import Callable
1817

1918
class AutoWidthColumnListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
@@ -355,3 +354,37 @@ def onSliderChar(self, evt):
355354
evt.Skip()
356355
return
357356
self.SetValue(newValue)
357+
358+
359+
class TabbableScrolledPanel(scrolledpanel.ScrolledPanel):
360+
"""
361+
This class was created to ensure a ScrolledPanel scrolls to nested children of the panel when navigating
362+
with tabs (#12224). A PR to wxPython implementing this fix can be tracked on
363+
https://github.com/wxWidgets/Phoenix/pull/1950
364+
"""
365+
def GetChildRectRelativeToSelf(self, child: wx.Window) -> wx.Rect:
366+
"""
367+
window.GetRect returns the size of a window, and its position relative to its parent.
368+
When calculating ScrollChildIntoView, the position relative to its parent is not relevant unless the
369+
parent is the ScrolledPanel itself. Instead, calculate the position relative to scrolledPanel
370+
"""
371+
childRectRelativeToScreen = child.GetScreenRect()
372+
scrolledPanelScreenPosition = self.GetScreenPosition()
373+
return wx.Rect(
374+
childRectRelativeToScreen.x - scrolledPanelScreenPosition.x,
375+
childRectRelativeToScreen.y - scrolledPanelScreenPosition.y,
376+
childRectRelativeToScreen.width,
377+
childRectRelativeToScreen.height
378+
)
379+
380+
def ScrollChildIntoView(self, child: wx.Window) -> None:
381+
"""
382+
Overrides child.GetRect with `GetChildRectRelativeToSelf` before calling
383+
`super().ScrollChildIntoView`. `super().ScrollChildIntoView` incorrectly uses child.GetRect to
384+
navigate scrolling, which is relative to the parent, where it should instead be relative to this
385+
ScrolledPanel.
386+
"""
387+
oldChildGetRectFunction = child.GetRect
388+
child.GetRect = lambda: self.GetChildRectRelativeToSelf(child)
389+
super().ScrollChildIntoView(child)
390+
child.GetRect = oldChildGetRectFunction

source/gui/settingsDialogs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import typing
1515
import wx
1616
from vision.providerBase import VisionEnhancementProviderSettings
17-
from wx.lib import scrolledpanel
1817
from wx.lib.expando import ExpandoTextCtrl
1918
import wx.lib.newevent
2019
import winUser
@@ -483,7 +482,7 @@ def makeSettings(self, settingsSizer):
483482
# The provided column header is just a placeholder, as it is hidden due to the wx.LC_NO_HEADER style flag.
484483
self.catListCtrl.InsertColumn(0,categoriesLabelText)
485484

486-
self.container = scrolledpanel.ScrolledPanel(
485+
self.container = nvdaControls.TabbableScrolledPanel(
487486
parent = self,
488487
style = wx.TAB_TRAVERSAL | wx.BORDER_THEME,
489488
size=containerDim

0 commit comments

Comments
 (0)