Skip to content

Commit

Permalink
Retain aliases lost in #15121 (#15151)
Browse files Browse the repository at this point in the history
Follow up to #15121

Fixes #15142
Fixes #15141
Fixes #15148
Fixes #15147

Summary of the issue:
PR #15121 to fix #15120 had various unexpected side effects.
This is due to symbols that were previously star imported into gui/__init__.py being removed.
Add-ons and the vision enhancements core module relied on these symbols being imported.
While there was no API breaking changes, these changes affected over 30 add-ons

Description of user facing changes
Fix up issue with vision enhancement providers, such as opening the relevant settings panels.

Description of development approach
Add aliases for SettingsPanel, AutoSettingsMixin, _popupSettingsDialog in gui
  • Loading branch information
seanbudd authored Jul 17, 2023
1 parent f6cb4f7 commit c4ca763
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
36 changes: 35 additions & 1 deletion source/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import queueHandler
import core
from typing import (
Any,
Optional,
Type,
)
Expand Down Expand Up @@ -95,6 +96,28 @@ def quit():
"""


def __getattr__(attrName: str) -> Any:
"""Module level `__getattr__` used to preserve backward compatibility."""
from gui.settingsDialogs import AutoSettingsMixin, SettingsPanel
if attrName == "AutoSettingsMixin" and NVDAState._allowDeprecatedAPI():
log.warning(
"Importing AutoSettingsMixin from here is deprecated. "
"Import AutoSettingsMixin from gui.settingsDialogs instead. ",
# Include stack info so testers can report warning to add-on author.
stack_info=True,
)
return AutoSettingsMixin
if attrName == "SettingsPanel" and NVDAState._allowDeprecatedAPI():
log.warning(
"Importing SettingsPanel from here is deprecated. "
"Import SettingsPanel from gui.settingsDialogs instead. ",
# Include stack info so testers can report warning to add-on author.
stack_info=True,
)
return SettingsPanel
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")


class MainFrame(wx.Frame):
"""A hidden window, intended to act as the parent to all dialogs.
"""
Expand Down Expand Up @@ -199,6 +222,14 @@ def popupSettingsDialog(self, dialog: Type[SettingsDialog], *args, **kwargs):

self.postPopup()

if NVDAState._allowDeprecatedAPI():
def _popupSettingsDialog(self, dialog: Type[SettingsDialog], *args, **kwargs):
log.warning(
"_popupSettingsDialog is deprecated, use popupSettingsDialog instead.",
stack_info=True,
)
self.popupSettingsDialog(dialog, *args, **kwargs)

@blockAction.when(blockAction.Context.SECURE_MODE)
def onDefaultDictionaryCommand(self, evt):
self.popupSettingsDialog(DefaultDictionaryDialog)
Expand Down Expand Up @@ -344,7 +375,10 @@ def onPythonConsoleCommand(self, evt):

if NVDAState._allowDeprecatedAPI():
def onAddonsManagerCommand(self, evt: wx.MenuEvent):
log.warning("onAddonsManagerCommand is deprecated, use onAddonStoreCommand instead.")
log.warning(
"onAddonsManagerCommand is deprecated, use onAddonStoreCommand instead.",
stack_info=True,
)
self.onAddonStoreCommand(evt)

@blockAction.when(
Expand Down
14 changes: 8 additions & 6 deletions source/visionEnhancementProviders/NVDAHighlighter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
# Copyright (C) 2018-2022 NV Access Limited, Babbage B.V., Takuya Nishimoto
# Copyright (C) 2018-2023 NV Access Limited, Babbage B.V., Takuya Nishimoto

"""Default highlighter based on GDI Plus."""
from typing import Optional, Tuple
Expand All @@ -15,7 +15,11 @@
from vision import providerBase
from windowUtils import CustomWindow
import wx
import gui
from gui.settingsDialogs import (
AutoSettingsMixin,
SettingsPanel,
VisionProviderStateControl,
)
import api
from ctypes import byref, WinError
from ctypes.wintypes import COLORREF, MSG
Expand Down Expand Up @@ -239,17 +243,15 @@ def _get_supportedSettings(self) -> SupportedSettingType:


class NVDAHighlighterGuiPanel(
gui.AutoSettingsMixin,
gui.SettingsPanel
AutoSettingsMixin,
SettingsPanel
):

_enableCheckSizer: wx.BoxSizer
_enabledCheckbox: wx.CheckBox

helpId = "VisionSettingsFocusHighlight"

from gui.settingsDialogs import VisionProviderStateControl

def __init__(
self,
parent: wx.Window,
Expand Down
5 changes: 2 additions & 3 deletions source/visionEnhancementProviders/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ These are used to save / load settings for the provider.

A GUI can be built automatically from the DriverSettings objects accessed via the VisionEnhancementProviderSettings.
Alternatively the provider can supply a custom settings panel implementation via the getSettingsPanelClass class method.
A custom settings panel must return a class type derived from gui.SettingsPanel which will take responsibility for
building the GUI.
A custom settings panel must return a class type derived from `gui.settingsDialogs.SettingsPanel` which will take responsibility for building the GUI.
For an example see NVDAHighlighter or ScreenCurtain.

#### Automatic GUI building

The provider settings (described above) are also used to automatically construct a GUI for the provider when
getSettingsPanelClass returns None.

See exampleProvider_autoGui.py
See exampleProvider_autoGui.py
19 changes: 11 additions & 8 deletions source/visionEnhancementProviders/screenCurtain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
# Copyright (C) 2018-2019 NV Access Limited, Babbage B.V., Leonard de Ruijter
# Copyright (C) 2018-2023 NV Access Limited, Babbage B.V., Leonard de Ruijter

"""Screen curtain implementation based on the windows magnification API.
The Magnification API has been marked by MS as unsupported for WOW64 applications such as NVDA. (#12491)
Expand All @@ -17,7 +17,12 @@
from autoSettingsUtils.driverSetting import BooleanDriverSetting
from autoSettingsUtils.autoSettings import SupportedSettingType
import wx
import gui
from gui.nvdaControls import MessageDialog
from gui.settingsDialogs import (
AutoSettingsMixin,
SettingsPanel,
VisionProviderStateControl,
)
from logHandler import log
from typing import Optional, Type
import nvwave
Expand Down Expand Up @@ -141,7 +146,7 @@ def _get_supportedSettings(self) -> SupportedSettingType:
)


class WarnOnLoadDialog(gui.nvdaControls.MessageDialog):
class WarnOnLoadDialog(MessageDialog):

showWarningOnLoadCheckBox: wx.CheckBox
noButton: wx.Button
Expand All @@ -152,7 +157,7 @@ def __init__(
parent,
title=_("Warning"),
message=warnOnLoadText,
dialogType=gui.nvdaControls.MessageDialog.DIALOG_TYPE_WARNING
dialogType=MessageDialog.DIALOG_TYPE_WARNING
):
self._settingsStorage = screenCurtainSettingsStorage
super().__init__(parent, title, message, dialogType)
Expand Down Expand Up @@ -215,17 +220,15 @@ def _onShowEvt(self, evt):


class ScreenCurtainGuiPanel(
gui.AutoSettingsMixin,
gui.SettingsPanel,
AutoSettingsMixin,
SettingsPanel,
):

_enabledCheckbox: wx.CheckBox
_enableCheckSizer: wx.BoxSizer

helpId = "VisionSettingsScreenCurtain"

from gui.settingsDialogs import VisionProviderStateControl

def __init__(
self,
parent,
Expand Down

0 comments on commit c4ca763

Please sign in to comment.