Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DriverSetting classes from autoSettingUtils rather than from driverHandler #12168

Merged
merged 3 commits into from
Mar 17, 2021
Merged
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
20 changes: 13 additions & 7 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import bdDetect
import queueHandler
import brailleViewer
from autoSettingsUtils.driverSetting import BooleanDriverSetting, NumericDriverSetting


roleLabels = {
# Translators: Displayed in braille for an object which is a
Expand Down Expand Up @@ -2233,19 +2235,23 @@ def terminate():

class BrailleDisplayDriver(driverHandler.Driver):
"""Abstract base braille display driver.
Each braille display driver should be a separate Python module in the root brailleDisplayDrivers directory containing a BrailleDisplayDriver class which inherits from this base class.
Each braille display driver should be a separate Python module in the root brailleDisplayDrivers directory
containing a BrailleDisplayDriver class which inherits from this base class.

At a minimum, drivers must set L{name} and L{description} and override the L{check} method.
To display braille, L{numCells} and L{display} must be implemented.

Drivers should dispatch input such as presses of buttons, wheels or other controls using the L{inputCore} framework.
They should subclass L{BrailleDisplayGesture} and execute instances of those gestures using L{inputCore.manager.executeGesture}.
Drivers should dispatch input such as presses of buttons, wheels or other controls
using the L{inputCore} framework.
They should subclass L{BrailleDisplayGesture}
and execute instances of those gestures using L{inputCore.manager.executeGesture}.
These gestures can be mapped in L{gestureMap}.
A driver can also inherit L{baseObject.ScriptableObject} to provide display specific scripts.

@see: L{hwIo} for raw serial and HID I/O.

There are factory functions to create L{driverHandler.DriverSetting} instances for common display specific settings; e.g. L{DotFirmnessSetting}.
There are factory functions to create L{autoSettingsUtils.driverSetting.DriverSetting} instances
for common display specific settings; e.g. L{DotFirmnessSetting}.
"""
_configSection = "braille"
# Most braille display drivers don't have settings yet.
Expand Down Expand Up @@ -2463,7 +2469,7 @@ def _handleAck(self):
@classmethod
def DotFirmnessSetting(cls,defaultVal,minVal,maxVal,useConfig=False):
"""Factory function for creating dot firmness setting."""
return driverHandler.NumericDriverSetting(
return NumericDriverSetting(
"dotFirmness",
# Translators: Label for a setting in braille settings dialog.
_("Dot firm&ness"),
Expand All @@ -2476,7 +2482,7 @@ def DotFirmnessSetting(cls,defaultVal,minVal,maxVal,useConfig=False):
@classmethod
def BrailleInputSetting(cls, useConfig=True):
"""Factory function for creating braille input setting."""
return driverHandler.BooleanDriverSetting(
return BooleanDriverSetting(
"brailleInput",
# Translators: Label for a setting in braille settings dialog.
_("Braille inp&ut"),
Expand All @@ -2486,7 +2492,7 @@ def BrailleInputSetting(cls, useConfig=True):
@classmethod
def HIDInputSetting(cls, useConfig):
"""Factory function for creating HID input setting."""
return driverHandler.BooleanDriverSetting(
return BooleanDriverSetting(
"hidKeyboardInput",
# Translators: Label for a setting in braille settings dialog.
_("&HID keyboard input simulation"),
Expand Down
12 changes: 0 additions & 12 deletions source/driverHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
"""Handler for driver functionality that is global to synthesizers and braille displays."""
from autoSettingsUtils.autoSettings import AutoSettings

# F401: the following imports, while unused in this file, are provided for backwards compatibility.
from autoSettingsUtils.driverSetting import ( # noqa: F401
DriverSetting,
BooleanDriverSetting,
NumericDriverSetting,
AutoPropertyObject,
)
from autoSettingsUtils.utils import ( # noqa: F401
UnsupportedConfigParameterError,
StringParameterInfo,
)


class Driver(AutoSettings):
"""
Expand Down
34 changes: 21 additions & 13 deletions source/synthDriverHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
import extensionPoints
import synthDrivers
import driverHandler
from autoSettingsUtils.driverSetting import BooleanDriverSetting, DriverSetting, NumericDriverSetting
from autoSettingsUtils.utils import StringParameterInfo

from abc import abstractmethod


class LanguageInfo(driverHandler.StringParameterInfo):
class LanguageInfo(StringParameterInfo):
"""Holds information for a particular language"""

def __init__(self, id):
Expand All @@ -31,7 +34,7 @@ def __init__(self, id):
super(LanguageInfo, self).__init__(id, displayName)


class VoiceInfo(driverHandler.StringParameterInfo):
class VoiceInfo(StringParameterInfo):
"""Provides information about a single synthesizer voice.
"""

Expand All @@ -46,13 +49,18 @@ def __init__(self, id, displayName, language=None):


class SynthDriver(driverHandler.Driver):
"""Abstract base synthesizer driver.
Each synthesizer driver should be a separate Python module in the root synthDrivers directory containing a SynthDriver class which inherits from this base class.
"""
Abstract base synthesizer driver.
Each synthesizer driver should be a separate Python module in the root synthDrivers directory
containing a SynthDriver class
which inherits from this base class.

At a minimum, synth drivers must set L{name} and L{description} and override the L{check} method.
The methods L{speak}, L{cancel} and L{pause} should be overridden as appropriate.
L{supportedSettings} should be set as appropriate for the settings supported by the synthesiser.
There are factory functions to create L{driverHandler.DriverSetting} instances for common settings; e.g. L{VoiceSetting} and L{RateSetting}.
There are factory functions to create L{autoSettingsUtils.driverSetting.DriverSetting} instances
for common settings;
e.g. L{VoiceSetting} and L{RateSetting}.
Each setting is retrieved and set using attributes named after the setting;
e.g. the L{voice} attribute is used for the L{voice} setting.
These will usually be properties.
Expand Down Expand Up @@ -98,7 +106,7 @@ class SynthDriver(driverHandler.Driver):
@classmethod
def LanguageSetting(cls):
"""Factory function for creating a language setting."""
return driverHandler.DriverSetting(
return DriverSetting(
"language",
# Translators: Label for a setting in voice settings dialog.
_("&Language"),
Expand All @@ -110,7 +118,7 @@ def LanguageSetting(cls):
@classmethod
def VoiceSetting(cls):
"""Factory function for creating voice setting."""
return driverHandler.DriverSetting(
return DriverSetting(
"voice",
# Translators: Label for a setting in voice settings dialog.
_("&Voice"),
Expand All @@ -122,7 +130,7 @@ def VoiceSetting(cls):
@classmethod
def VariantSetting(cls):
"""Factory function for creating variant setting."""
return driverHandler.DriverSetting(
return DriverSetting(
"variant",
# Translators: Label for a setting in voice settings dialog.
_("V&ariant"),
Expand All @@ -134,7 +142,7 @@ def VariantSetting(cls):
@classmethod
def RateSetting(cls, minStep=1):
"""Factory function for creating rate setting."""
return driverHandler.NumericDriverSetting(
return NumericDriverSetting(
"rate",
# Translators: Label for a setting in voice settings dialog.
_("&Rate"),
Expand All @@ -147,7 +155,7 @@ def RateSetting(cls, minStep=1):
@classmethod
def RateBoostSetting(cls):
"""Factory function for creating rate boost setting."""
return driverHandler.BooleanDriverSetting(
return BooleanDriverSetting(
"rateBoost",
# Translators: This is the name of the rate boost voice toggle
# which further increases the speaking rate when enabled.
Expand All @@ -160,7 +168,7 @@ def RateBoostSetting(cls):
@classmethod
def VolumeSetting(cls, minStep=1):
"""Factory function for creating volume setting."""
return driverHandler.NumericDriverSetting(
return NumericDriverSetting(
"volume",
# Translators: Label for a setting in voice settings dialog.
_("V&olume"),
Expand All @@ -174,7 +182,7 @@ def VolumeSetting(cls, minStep=1):
@classmethod
def PitchSetting(cls, minStep=1):
"""Factory function for creating pitch setting."""
return driverHandler.NumericDriverSetting(
return NumericDriverSetting(
"pitch",
# Translators: Label for a setting in voice settings dialog.
_("&Pitch"),
Expand All @@ -187,7 +195,7 @@ def PitchSetting(cls, minStep=1):
@classmethod
def InflectionSetting(cls, minStep=1):
"""Factory function for creating inflection setting."""
return driverHandler.NumericDriverSetting(
return NumericDriverSetting(
"inflection",
# Translators: Label for a setting in voice settings dialog.
_("&Inflection"),
Expand Down
1 change: 0 additions & 1 deletion source/synthDrivers/espeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from synthDriverHandler import SynthDriver, VoiceInfo, synthIndexReached, synthDoneSpeaking
import speech
from logHandler import log
from driverHandler import BooleanDriverSetting

from speech.commands import (
IndexCommand,
Expand Down
13 changes: 7 additions & 6 deletions source/synthSettingsRing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
import config
import synthDriverHandler
import queueHandler
import driverHandler
from autoSettingsUtils.driverSetting import BooleanDriverSetting, NumericDriverSetting


class SynthSetting(baseObject.AutoPropertyObject):
"""a numeric synth setting. Has functions to set, get, increase and decrease its value """
def __init__(self,synth,setting,min=0,max=100):
self.synth = synth
self.setting = setting
self.min = setting.minVal if isinstance(setting,driverHandler.NumericDriverSetting) else min
self.max = setting.maxVal if isinstance(setting,driverHandler.NumericDriverSetting) else max
self.step = setting.normalStep if isinstance(setting,driverHandler.NumericDriverSetting) else 1
self.min = setting.minVal if isinstance(setting, NumericDriverSetting) else min
self.max = setting.maxVal if isinstance(setting, NumericDriverSetting) else max
self.step = setting.normalStep if isinstance(setting, NumericDriverSetting) else 1

def increase(self):
val = min(self.max,self.value+self.step)
Expand Down Expand Up @@ -139,9 +140,9 @@ def updateSupportedSettings(self,synth):
if not s.availableInSettingsRing: continue
if prevID == s.id: #restore the last setting
self._current=len(list)
if isinstance(s,driverHandler.NumericDriverSetting):
if isinstance(s, NumericDriverSetting):
cls=SynthSetting
elif isinstance(s,driverHandler.BooleanDriverSetting):
elif isinstance(s, BooleanDriverSetting):
cls=BooleanSynthSetting
else:
cls=StringSynthSetting
Expand Down
5 changes: 2 additions & 3 deletions source/visionEnhancementProviders/NVDAHighlighter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# visionEnhancementProviders/NVDAHighlighter.py
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
Expand All @@ -8,6 +7,7 @@
from typing import Optional, Tuple

from autoSettingsUtils.autoSettings import SupportedSettingType
from autoSettingsUtils.driverSetting import BooleanDriverSetting
import vision
from vision.constants import Context
from vision.util import getContextRect
Expand All @@ -29,7 +29,6 @@
import weakref
from colors import RGB
import core
import driverHandler


class HighlightStyle(
Expand Down Expand Up @@ -229,7 +228,7 @@ def getDisplayName(cls) -> str:

def _get_supportedSettings(self) -> SupportedSettingType:
return [
driverHandler.BooleanDriverSetting(
BooleanDriverSetting(
'highlight%s' % (context[0].upper() + context[1:]),
_contextOptionLabelsWithAccelerators[context],
defaultVal=True
Expand Down
14 changes: 7 additions & 7 deletions source/visionEnhancementProviders/_exampleProvider_autoGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (C) 2019 NV Access Limited

from vision import providerBase
import driverHandler
from autoSettingsUtils.driverSetting import BooleanDriverSetting, DriverSetting, NumericDriverSetting
import gui
from autoSettingsUtils.utils import StringParameterInfo
from autoSettingsUtils.autoSettings import SupportedSettingType
Expand Down Expand Up @@ -58,22 +58,22 @@ def getPreInitSettings(cls) -> SupportedSettingType:
This is a class method because it does not rely on any instance state in this class.
"""
return [
driverHandler.BooleanDriverSetting(
BooleanDriverSetting(
"shouldDoX", # value stored in matching property name on class
"Should Do X",
defaultVal=True
),
driverHandler.BooleanDriverSetting(
BooleanDriverSetting(
"shouldDoY", # value stored in matching property name on class
"Should Do Y",
defaultVal=False
),
driverHandler.NumericDriverSetting(
NumericDriverSetting(
"amountOfZ", # value stored in matching property name on class
"Amount of Z",
defaultVal=11
),
driverHandler.DriverSetting(
DriverSetting(
# options for this come from a property with name generated by
# f"available{settingID.capitalize()}s"
# Note:
Expand All @@ -100,15 +100,15 @@ def _getAvailableRuntimeSettings(self) -> SupportedSettingType:
settings = []
if self._hasFeature("runtimeOnlySetting_externalValueLoad"):
settings.extend([
driverHandler.NumericDriverSetting(
NumericDriverSetting(
"runtimeOnlySetting_externalValueLoad", # value stored in matching property name on class
"Runtime Only amount, external value load",
# no GUI default
),
])
if self._hasFeature("runtimeOnlySetting_localDefault"):
settings.extend([
driverHandler.NumericDriverSetting(
NumericDriverSetting(
"runtimeOnlySetting_localDefault", # value stored in matching property name on class
"Runtime Only amount, local default",
defaultVal=50,
Expand Down
2 changes: 2 additions & 0 deletions user_docs/en/changes.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ What's New in NVDA
- `speakTextInfo` will no longer send speech through `speakWithoutPauses` if reason is `SAYALL`, as `sayAllhandler` does this manually now. (#12150)
- The `synthDriverHandler` module is no longer star imported into `globalCommands` and `gui.settingsDialogs` - use `from synthDriverHandler import synthFunctionExample` instead. (#12172)
- `ROLE_EQUATION` has been removed from controlTypes - use `ROLE_MATH`` instead. (#12164)
- `autoSettingsUtils.driverSetting` classes are removed from `driverHandler` - please use them from `autoSettingUtils.driverSetting`. (#12168)
- `autoSettingsUtils.utils` classes are removed from `driverHandler` - please use them from `autoSettingUtils.utils`. (#12168)


= 2020.4 =
Expand Down