Skip to content

Commit 1163416

Browse files
authored
Merge 019d477 into 35ceac2
2 parents 35ceac2 + 019d477 commit 1163416

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

source/gui/nvdaControls.py

Lines changed: 67 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,63 @@ 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+
cr = child.GetScreenRect()
372+
spr = self.GetScreenPosition()
373+
return wx.Rect(cr.x - spr.x, cr.y - spr.y, cr.width, cr.height)
374+
375+
def ScrollChildIntoView(self, child: wx.Window) -> None:
376+
"""
377+
Uses the same logic as super().ScrollChildIntoView(self, child)
378+
except cr = self.GetChildRectRelativeToSelf(child) instead of cr = GetRect()
379+
"""
380+
sppu_x, sppu_y = self.GetScrollPixelsPerUnit()
381+
vs_x, vs_y = self.GetViewStart()
382+
cr = self.GetChildRectRelativeToSelf(child)
383+
clntsz = self.GetClientSize()
384+
new_vs_x, new_vs_y = -1, -1
385+
386+
# is it before the left edge?
387+
if cr.x < 0 and sppu_x > 0:
388+
new_vs_x = vs_x + (cr.x / sppu_x)
389+
390+
# is it above the top?
391+
if cr.y < 0 and sppu_y > 0:
392+
new_vs_y = vs_y + (cr.y / sppu_y)
393+
394+
# For the right and bottom edges, scroll enough to show the
395+
# whole control if possible, but if not just scroll such that
396+
# the top/left edges are still visible
397+
398+
# is it past the right edge ?
399+
if cr.right > clntsz.width and sppu_x > 0:
400+
diff = math.ceil(1.0 * (cr.right - clntsz.width + 1) / sppu_x)
401+
if cr.x - diff * sppu_x > 0:
402+
new_vs_x = vs_x + diff
403+
else:
404+
new_vs_x = vs_x + (cr.x / sppu_x)
405+
406+
# is it below the bottom ?
407+
if cr.bottom > clntsz.height and sppu_y > 0:
408+
diff = math.ceil(1.0 * (cr.bottom - clntsz.height + 1) / sppu_y)
409+
if cr.y - diff * sppu_y > 0:
410+
new_vs_y = vs_y + diff
411+
else:
412+
new_vs_y = vs_y + (cr.y / sppu_y)
413+
414+
# if we need to adjust
415+
if new_vs_x != -1 or new_vs_y != -1:
416+
self.Scroll(new_vs_x, new_vs_y)

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)