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
18 changes: 6 additions & 12 deletions addon/globalPlugins/webAccess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import addonHandler
import api
import baseObject
from buildVersion import version_detailed as NVDA_VERSION
import controlTypes
import core
import eventHandler
Expand Down Expand Up @@ -285,9 +284,9 @@ def chooseNVDAObjectOverlayClasses(self, obj, clsList):
if cls in clsList
):
if obj.role in (
controlTypes.ROLE_APPLICATION,
controlTypes.ROLE_DIALOG,
controlTypes.ROLE_DOCUMENT,
controlTypes.Role.APPLICATION,
controlTypes.Role.DIALOG,
controlTypes.Role.DOCUMENT,
):
clsList.insert(0, overlay.WebAccessDocument)
return
Expand All @@ -296,7 +295,7 @@ def chooseNVDAObjectOverlayClasses(self, obj, clsList):
from .gui import inspector
if (
inspector.outputWindowHandle is not None
and obj.role == controlTypes.ROLE_EDITABLETEXT
and obj.role == controlTypes.Role.EDITABLETEXT
and obj.windowHandle == inspector.outputWindowHandle
and obj.appModule.appName == "nvda"
):
Expand Down Expand Up @@ -356,12 +355,7 @@ def script_showWebAccessSettings(self, gesture): # @UnusedVariable
# After the above import, it appears that the `gui` name now points to the `.gui` module
# rather than NVDA's `gui`… No clue why…
import gui
if NVDA_VERSION < "2023.2":
# Deprecated as of NVDA 2023.2
gui.mainFrame._popupSettingsDialog(WebAccessSettingsDialog)
else:
# Now part of the public API as of NVDA PR #15121
gui.mainFrame.popupSettingsDialog(WebAccessSettingsDialog)
gui.mainFrame.popupSettingsDialog(WebAccessSettingsDialog)

@script(
# Translators: Input help mode message for a WebAccess command
Expand Down Expand Up @@ -501,7 +495,7 @@ def appModule_nvda_event_NVDAObject_init(self, obj):
"popupContextMenuName" in globals()
and popupContextMenuName is not None
and isinstance(obj, IAccessible)
and obj.role == controlTypes.ROLE_POPUPMENU
and obj.role == controlTypes.Role.POPUPMENU
):
obj.name = popupContextMenuName
popupContextMenuName = None
Expand Down
24 changes: 10 additions & 14 deletions addon/globalPlugins/webAccess/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@


from abc import abstractmethod
from buildVersion import version_detailed as NVDA_VERSION
from collections import OrderedDict
from dataclasses import dataclass
from enum import Enum, auto
import re
import sys
from typing import Any, Callable
import wx
import wx.lib.mixins.listctrl as listmix
from wx.lib.scrolledpanel import ScrolledPanel

import gui
from gui import guiHelper, nvdaControls
Expand All @@ -56,11 +55,11 @@

from ..utils import guarded, logException, notifyError, updateOrDrop

# TabbableScrolledPanel was removed in NVDA 2026.1 (wxPython 4.2.3 update).
# Fall back to wx.lib.scrolledpanel.ScrolledPanel which now has the fix built-in.
_TabbableScrolledPanel = getattr(nvdaControls, "TabbableScrolledPanel", ScrolledPanel)

if sys.version_info[1] < 9:
from typing import Iterable, Mapping, Sequence, Set
else:
from collections.abc import Iterable, Mapping, Sequence, Set
from collections.abc import Iterable, Mapping, Sequence, Set


addonHandler.initTranslation()
Expand Down Expand Up @@ -251,7 +250,7 @@ def _buildGui(self):
self.SetSizer(self.mainSizer)


# TODO: Consider migrating to NVDA's SettingsDialog once we hit 2023.2 as minimum version
# TODO: Consider migrating to NVDA's SettingsDialog
class ContextualDialog(ScalingMixin, wx.Dialog):

def initData(self, context):
Expand Down Expand Up @@ -367,12 +366,9 @@ def configuredSettingsDialogType(hasApplyButton: bool) -> type(SettingsDialog):
class Type(SettingsDialog):

def __init__(self, *args, **kwargs):
if NVDA_VERSION < "2023.2":
kwargs["hasApplyButton"] = hasApplyButton
else:
buttons: Set[int] = kwargs.get("buttons", {wx.OK, wx.CANCEL})
if not hasApplyButton:
buttons -= {wx.APPLY}
buttons: Set[int] = kwargs.get("buttons", {wx.OK, wx.CANCEL})
if not hasApplyButton:
buttons -= {wx.APPLY}
super().__init__(*args, **kwargs)

return Type
Expand Down Expand Up @@ -572,7 +568,7 @@ def makeSettings(self, settingsSizer):
style=wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT
)

self.container = nvdaControls.TabbableScrolledPanel(
self.container = _TabbableScrolledPanel(
parent = self,
style = wx.TAB_TRAVERSAL | wx.BORDER_THEME,
size=containerDim
Expand Down
6 changes: 3 additions & 3 deletions addon/globalPlugins/webAccess/gui/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ def getNodeDescription(node, root=None, identifier=None):
parts.append(f"{labels['text']} {getText(node)}")
else:
parts.append(f"{labels['tag']} {node.tag}")
parts.append(f"{labels['role']} {controlTypes.roleLabels[node.role]}")
parts.append(f"{labels['role']} {node.role.displayString}")
parts.append(f"{labels['id']} {coalesce(node.id, '')}")
parts.append(f"{labels['className']} {coalesce(node.className, '')}")
states = ", ".join(sorted((
controlTypes.stateLabels.get(state, state)
state.displayString if isinstance(state, controlTypes.State) else str(state)
for state in node.states
)))
parts.append(f"{labels['states']} {states}")
Expand Down Expand Up @@ -270,7 +270,7 @@ def computeRelativePath(node1, node2):
if index1 < index2:
link = "r" * (index2 - index1)
else:
link = "l" * (index1 - index2)
link = "l" * (index1 - index2)
return path1 + link + path2


Expand Down
7 changes: 1 addition & 6 deletions addon/globalPlugins/webAccess/gui/rule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
__author__ = "Julien Cochuyt <j.cochuyt@accessolutions.fr>"


import sys
from typing import Any

import wx
Expand All @@ -37,11 +36,7 @@
from ...utils import updateOrDrop
from .properties import Properties


if sys.version_info[1] < 9:
from typing import Mapping
else:
from collections.abc import Mapping
from collections.abc import Mapping


addonHandler.initTranslation()
Expand Down
32 changes: 13 additions & 19 deletions addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from collections import OrderedDict
from copy import deepcopy
import re
import sys
from typing import Any
import wx
from wx.lib.expando import EVT_ETC_LAYOUT_NEEDED, ExpandoTextCtrl
Expand Down Expand Up @@ -66,16 +65,11 @@
from .gestures import GesturesPanelBase
from .properties import Properties, PropertiesPanelBase, Property


if sys.version_info[1] < 9:
from typing import Mapping, Sequence
else:
from collections.abc import Mapping, Sequence
from collections.abc import Mapping, Sequence


addonHandler.initTranslation()

from six import iteritems, text_type

EXPR_VALUE = re.compile("(([^!&| ])+( (?=[^!&|]))*)+")
"""
Expand Down Expand Up @@ -104,7 +98,7 @@ def captureValues(expr):

def getStatesLblExprForSet(states):
return " & ".join((
controlTypes.stateLabels.get(state, state)
state.displayString if isinstance(state, controlTypes.State) else str(state)
for state in states
))

Expand All @@ -113,7 +107,7 @@ def translateExprValues(expr, func):
buf = list(expr)
offset = 0
for src, start, end in captureValues(expr):
dest = text_type(func(src))
dest = str(func(src))
start += offset
end += offset
buf[start:end] = dest
Expand All @@ -124,17 +118,17 @@ def translateExprValues(expr, func):
def translateRoleIdToLbl(expr):
def translate(value):
try:
return controlTypes.roleLabels[int(value)]
return controlTypes.Role(int(value)).displayString
except (KeyError, ValueError):
return value
return translateExprValues(expr, translate)


def translateRoleLblToId(expr, raiseOnError=True):
def translate(value):
for key, candidate in iteritems(controlTypes.roleLabels):
if candidate == value:
return text_type(key.value)
for role in controlTypes.Role:
if role.displayString == value:
return str(role.value)
if raiseOnError:
raise ValidationError(value)
return value
Expand All @@ -144,17 +138,17 @@ def translate(value):
def translateStatesIdToLbl(expr):
def translate(value):
try:
return controlTypes.stateLabels[int(value)]
return controlTypes.State(int(value)).displayString
except (KeyError, ValueError):
return value
return translateExprValues(expr, translate)


def translateStatesLblToId(expr, raiseOnError=True):
def translate(value):
for key, candidate in iteritems(controlTypes.stateLabels):
if candidate == value:
return text_type(key.value)
for state in controlTypes.State:
if state.displayString == value:
return str(state.value)
if raiseOnError:
raise ValidationError(value)
return value
Expand Down Expand Up @@ -814,7 +808,7 @@ def initData_others(self, context):
urlChoices = []
# todo: actually there are empty choices created
while node is not None:
roleChoices.append(controlTypes.roleLabels.get(node.role, "") or "")
roleChoices.append(node.role.displayString if node.role else "")
tagChoices.append(node.tag or "")
idChoices.append(node.id or "")
classChoices.append(node.className or "")
Expand Down Expand Up @@ -952,7 +946,7 @@ def onTestCriteria(self, evt):
testCriteria(self.context)

def isValid(self):
self.updateData()
self.updateData()
return self.isValid_context() and self.isValid_others()

def isValid_context(self):
Expand Down
14 changes: 5 additions & 9 deletions addon/globalPlugins/webAccess/gui/rule/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from dataclasses import dataclass
from enum import Enum
from functools import partial
import sys
from typing import Any
import wx
from wx.lib.expando import EVT_ETC_LAYOUT_NEEDED, ExpandoTextCtrl
Expand Down Expand Up @@ -80,18 +79,14 @@
SinglePropertyEditorPanelBase,
)


if sys.version_info[1] < 9:
from typing import Mapping, Sequence
else:
from collections.abc import Mapping, Sequence
from collections.abc import Mapping, Sequence


addonHandler.initTranslation()

formModeRoles = [
controlTypes.ROLE_EDITABLETEXT,
controlTypes.ROLE_COMBOBOX,
controlTypes.Role.EDITABLETEXT,
controlTypes.Role.COMBOBOX,
]

SHARED_LABELS: Mapping[str, str] = {
Expand Down Expand Up @@ -632,7 +627,7 @@ def delete(self):
def onGestureChange(self, change: Change, id: str):
super().onGestureChange(change, id)
prm = self.categoryParams
self.refreshParent(prm.treeNode)
self.refreshParent(prm.treeNode)

def spaceIsPressedOnTreeNode(self, withShift=False):
self.gesturesListBox.SetFocus()
Expand Down Expand Up @@ -753,6 +748,7 @@ def makeSettings_buttons(self, gbSizer, row, col, full=True):

row += 1
gbSizer.Add(scale(0, guiHelper.SPACE_BETWEEN_VERTICAL_DIALOG_ITEMS), pos=(row, col))



def spaceIsPressedOnTreeNode(self, withShift=False):
Expand Down
7 changes: 1 addition & 6 deletions addon/globalPlugins/webAccess/gui/rule/gestureBinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
)


import sys
from typing import Any
import wx

Expand All @@ -45,11 +44,7 @@
from ...utils import guarded, logException
from .. import ScalingMixin, showContextualDialog


if sys.version_info[1] < 9:
from typing import Mapping
else:
from collections.abc import Mapping
from collections.abc import Mapping


addonHandler.initTranslation()
Expand Down
7 changes: 1 addition & 6 deletions addon/globalPlugins/webAccess/gui/rule/gestures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
)


import sys
from typing import Any
import wx

Expand All @@ -44,11 +43,7 @@
from . import gestureBinding
from .abc import RuleAwarePanelBase


if sys.version_info[1] < 9:
from typing import Mapping
else:
from collections.abc import Mapping
from collections.abc import Mapping


addonHandler.initTranslation()
Expand Down
Loading