Skip to content

Commit

Permalink
internal code changes.
Browse files Browse the repository at this point in the history
updated way of using timers, now core.callLater is used.
  • Loading branch information
davidacm committed Mar 29, 2022
1 parent b55f6a7 commit 77bc828
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/upload-on-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with open("buildVars.py", 'r+', encoding='utf-8') as f:
text = f.read()
version = "${{ github.ref }}".split("/")[-1]
text = re.sub("\"addon_version\" : ,", "\"addon_version\" : \"%s\",", text) % version
text = re.sub('"addon_version" *:.*,', '"addon_version" : "%s",' % version, text)
f.seek(0)
f.write(text)
f.truncate()
Expand Down
39 changes: 27 additions & 12 deletions addon/globalPlugins/enhancedPhoneticReading.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Released under GPL 2.0
#globalPlugins/enhancedPhoneticReading.py

import characterProcessing, config, controlTypes, globalPluginHandler, gui, addonHandler, six, speech, textInfos, threading, wx
import characterProcessing, config, controlTypes, core, globalPluginHandler, gui, addonHandler, six, speech, textInfos, threading, wx
from globalCommands import SCRCAT_SPEECH

addonHandler.initTranslation()
Expand Down Expand Up @@ -43,9 +43,20 @@ def cancelSpeech():
origCancelSpeech()
cancelTimer()

class _FakeTextInfo():
"""
this class is used to preserve the information of the old object that contain the text. Its useful to use with delayed descriptions.
"""

def __init__(self, origTextInfo: textInfos.TextInfo):
self.text = origTextInfo.text
self.fields = origTextInfo.getTextWithFields({})

def getTextWithFields(self, _ = None):
return self.fields

#saves the original speakTextInfo function
origSpeakTextInfo = speech.speakTextInfo

instantDescriptions = False
# alternate function to speakTextInfo. We determine here if a delayed description is needed base on textInfos.UNIT_CHARACTER.
def speakTextInfo(*args, **kwargs):
Expand All @@ -54,18 +65,22 @@ def speakTextInfo(*args, **kwargs):
if instantDescriptions and kwargs.get('unit') == textInfos.UNIT_CHARACTER: return speech.spellTextInfo(info, True)
tmp = origSpeakTextInfo(*args, **kwargs)
if config.conf['enhancedPhoneticReading']['delayedDescriptions'] and kwargs.get('unit') == textInfos.UNIT_CHARACTER:
characterDescriptionTimer = wx.CallLater(config.conf['enhancedPhoneticReading']['delay'], speakDescription, info.text, info.getTextWithFields({}))
characterDescriptionTimer = core.callLater(config.conf['enhancedPhoneticReading']['delay'], speakDelayedDescription, _FakeTextInfo(info))
return tmp

def speakDescription(text, fields):
curLanguage=speech.getCurrentLanguage()
if not config.conf['speech']['autoLanguageSwitching'] and characterProcessing.getCharacterDescription(curLanguage, text.lower()):
return speakSpelling(text, curLanguage, useCharacterDescriptions=True)
for field in fields:
if isinstance(field, six.string_types) and characterProcessing.getCharacterDescription(curLanguage, field.lower()):
speakSpelling(field,curLanguage,useCharacterDescriptions=True)
elif isinstance(field,textInfos.FieldCommand) and field.command=="formatChange":
curLanguage= field.field.get('language', curLanguage) or curLanguage
def speakDelayedDescription(info: _FakeTextInfo):
"""
this function is used to announce the delayed descriptions, we can't call spellTextInfo directly because we need to check if the description is available first.
"""
if info.text.strip() == "": return
curLang = speech.getCurrentLanguage()
if config.conf['speech']['autoLanguageSwitching']:
for k in info.fields:
if isinstance(k, textInfos.FieldCommand) and k.command == "formatChange":
curLang = k.field.get('language', curLang)
_, description = speech.getCharDescListFromText(info.text, locale=curLang)[0]
if description:
speech.spellTextInfo(info, useCharacterDescriptions=True)

class EnhancedPhoneticReadingPanel(gui.SettingsPanel):
# Translators: This is the label for the Enhanced phonetic reading settings category in NVDA Settings screen.
Expand Down
4 changes: 2 additions & 2 deletions buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
# Minimum NVDA version supported (e.g. "2018.3.0")
"addon_minimumNVDAVersion" : "2018.3.0",
# Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion" : "2021.3.1",
"addon_lastTestedNVDAVersion" : "2022.1.1",
# Add-on update channel (default is stable or None)
"addon_updateChannel": "dev",
"addon_updateChannel": "stable",
}

from os import path
Expand Down
10 changes: 4 additions & 6 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Changes for 1.1-dev ##
updated the way of using timers, now wx.CallLater is used instead. This should fix an incompatibility with bluetoothAudio add-on.
updated now delay config is saved in ms.
## Changes for 1.1.2-dev ##

## Changes for 1.0 ##
Updated manifest to add compatibility with NVDA 2021.3.1.
Updated readme files.
* Updated manifest to add compatibility with NVDA 2022.1.1.
* now core.callLater is used instead of python threads. This solves issues with another add-ons like bluetooth-audio.
* internal code changes.

0 comments on commit 77bc828

Please sign in to comment.