Skip to content

Commit 02c99d6

Browse files
Merge fec7595 into f16d63d
2 parents f16d63d + fec7595 commit 02c99d6

4 files changed

Lines changed: 293 additions & 212 deletions

File tree

source/gui/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import speechViewer
3333
import winUser
3434
import api
35+
from .speechDict import DictionaryDialog
36+
3537

3638
try:
3739
import updateCheck
@@ -156,15 +158,15 @@ def _popupSettingsDialog(self, dialog, *args, **kwargs):
156158

157159
self.postPopup()
158160

159-
def onDefaultDictionaryCommand(self,evt):
161+
def onDefaultDictionaryCommand(self, evt):
160162
# Translators: Title for default speech dictionary dialog.
161163
self._popupSettingsDialog(DictionaryDialog,_("Default dictionary"),speechDictHandler.dictionaries["default"])
162164

163-
def onVoiceDictionaryCommand(self,evt):
165+
def onVoiceDictionaryCommand(self, evt):
164166
# Translators: Title for voice dictionary for the current voice such as current eSpeak variant.
165167
self._popupSettingsDialog(DictionaryDialog,_("Voice dictionary (%s)")%speechDictHandler.dictionaries["voice"].fileName,speechDictHandler.dictionaries["voice"])
166168

167-
def onTemporaryDictionaryCommand(self,evt):
169+
def onTemporaryDictionaryCommand(self, evt):
168170
# Translators: Title for temporary speech dictionary dialog (the voice dictionary that is active as long as NvDA is running).
169171
self._popupSettingsDialog(DictionaryDialog,_("Temporary dictionary"),speechDictHandler.dictionaries["temp"])
170172

@@ -570,6 +572,11 @@ def wx_CallAfter_wrapper(func, *args, **kwargs):
570572
winUser.PostMessage(topHandle, winUser.WM_NULL, 0, 0)
571573
wx.CallAfter = wx_CallAfter_wrapper
572574

575+
# Deprecated: The three following lines should be removed for 2022.1
576+
DictionaryEntryDialog = speechDict.DictionaryEntryDialog # noqa: F405
577+
settingsDialogs.DictionaryDialog = DictionaryDialog # noqa: F405
578+
settingsDialogs.DictionaryEntryDialog = DictionaryEntryDialog # noqa: F405
579+
573580

574581
def terminate():
575582
global mainFrame

source/gui/settingsDialogs.py

Lines changed: 0 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from logHandler import log
3030
import nvwave
3131
import audioDucking
32-
import speechDictHandler
3332
import queueHandler
3433
import braille
3534
import brailleTables
@@ -2954,213 +2953,6 @@ def onEnableControlsCheckBox(self, evt):
29542953
self.advancedControls.Enable(evt.IsChecked())
29552954

29562955

2957-
class DictionaryEntryDialog(
2958-
gui.contextHelp.ContextHelpMixin,
2959-
wx.Dialog, # wxPython does not seem to call base class initializer, put last in MRO
2960-
):
2961-
helpId = "SpeechDictionaries"
2962-
2963-
TYPE_LABELS = {
2964-
# Translators: This is a label for an Entry Type radio button in add dictionary entry dialog.
2965-
speechDictHandler.ENTRY_TYPE_ANYWHERE: _("&Anywhere"),
2966-
# Translators: This is a label for an Entry Type radio button in add dictionary entry dialog.
2967-
speechDictHandler.ENTRY_TYPE_WORD: _("Whole &word"),
2968-
# Translators: This is a label for an Entry Type radio button in add dictionary entry dialog.
2969-
speechDictHandler.ENTRY_TYPE_REGEXP: _("Regular &expression")
2970-
}
2971-
TYPE_LABELS_ORDERING = (speechDictHandler.ENTRY_TYPE_ANYWHERE, speechDictHandler.ENTRY_TYPE_WORD, speechDictHandler.ENTRY_TYPE_REGEXP)
2972-
2973-
# Translators: This is the label for the edit dictionary entry dialog.
2974-
def __init__(self, parent, title=_("Edit Dictionary Entry")):
2975-
super(DictionaryEntryDialog,self).__init__(parent,title=title)
2976-
mainSizer=wx.BoxSizer(wx.VERTICAL)
2977-
sHelper = guiHelper.BoxSizerHelper(self, orientation=wx.VERTICAL)
2978-
2979-
# Translators: This is a label for an edit field in add dictionary entry dialog.
2980-
patternLabelText = _("&Pattern")
2981-
self.patternTextCtrl=sHelper.addLabeledControl(patternLabelText, wx.TextCtrl)
2982-
2983-
# Translators: This is a label for an edit field in add dictionary entry dialog and in punctuation/symbol pronunciation dialog.
2984-
replacementLabelText = _("&Replacement")
2985-
self.replacementTextCtrl=sHelper.addLabeledControl(replacementLabelText, wx.TextCtrl)
2986-
2987-
# Translators: This is a label for an edit field in add dictionary entry dialog.
2988-
commentLabelText = _("&Comment")
2989-
self.commentTextCtrl=sHelper.addLabeledControl(commentLabelText, wx.TextCtrl)
2990-
2991-
# Translators: This is a label for a checkbox in add dictionary entry dialog.
2992-
caseSensitiveText = _("Case &sensitive")
2993-
self.caseSensitiveCheckBox=sHelper.addItem(wx.CheckBox(self,label=caseSensitiveText))
2994-
2995-
# Translators: This is a label for a set of radio buttons in add dictionary entry dialog.
2996-
typeText = _("&Type")
2997-
typeChoices = [DictionaryEntryDialog.TYPE_LABELS[i] for i in DictionaryEntryDialog.TYPE_LABELS_ORDERING]
2998-
self.typeRadioBox=sHelper.addItem(wx.RadioBox(self,label=typeText, choices=typeChoices))
2999-
3000-
sHelper.addDialogDismissButtons(wx.OK | wx.CANCEL, separated=True)
3001-
3002-
mainSizer.Add(sHelper.sizer, border=guiHelper.BORDER_FOR_DIALOGS, flag=wx.ALL)
3003-
mainSizer.Fit(self)
3004-
self.SetSizer(mainSizer)
3005-
self.setType(speechDictHandler.ENTRY_TYPE_ANYWHERE)
3006-
self.patternTextCtrl.SetFocus()
3007-
self.Bind(wx.EVT_BUTTON,self.onOk,id=wx.ID_OK)
3008-
3009-
def getType(self):
3010-
typeRadioValue = self.typeRadioBox.GetSelection()
3011-
if typeRadioValue == wx.NOT_FOUND:
3012-
return speechDictHandler.ENTRY_TYPE_ANYWHERE
3013-
return DictionaryEntryDialog.TYPE_LABELS_ORDERING[typeRadioValue]
3014-
3015-
def onOk(self,evt):
3016-
if not self.patternTextCtrl.GetValue():
3017-
# Translators: This is an error message to let the user know that the pattern field in the dictionary entry is not valid.
3018-
gui.messageBox(_("A pattern is required."), _("Dictionary Entry Error"), wx.OK|wx.ICON_WARNING, self)
3019-
self.patternTextCtrl.SetFocus()
3020-
return
3021-
try:
3022-
dictEntry = self.dictEntry = speechDictHandler.SpeechDictEntry(
3023-
self.patternTextCtrl.GetValue(),
3024-
self.replacementTextCtrl.GetValue(),
3025-
self.commentTextCtrl.GetValue(),
3026-
bool(self.caseSensitiveCheckBox.GetValue()),
3027-
self.getType()
3028-
)
3029-
dictEntry.sub("test") # Ensure there are no grouping error (#11407)
3030-
except Exception as e:
3031-
log.debugWarning("Could not add dictionary entry due to (regex error) : %s" % e)
3032-
# Translators: This is an error message to let the user know that the dictionary entry is not valid.
3033-
gui.messageBox(_("Regular Expression error: \"%s\".")%e, _("Dictionary Entry Error"), wx.OK|wx.ICON_WARNING, self)
3034-
return
3035-
evt.Skip()
3036-
3037-
def setType(self, type):
3038-
self.typeRadioBox.SetSelection(DictionaryEntryDialog.TYPE_LABELS_ORDERING.index(type))
3039-
3040-
3041-
class DictionaryDialog(SettingsDialog):
3042-
TYPE_LABELS = {t: l.replace("&", "") for t, l in DictionaryEntryDialog.TYPE_LABELS.items()}
3043-
helpId = "SpeechDictionaries"
3044-
3045-
def __init__(self,parent,title,speechDict):
3046-
self.title = title
3047-
self.speechDict = speechDict
3048-
self.tempSpeechDict=speechDictHandler.SpeechDict()
3049-
self.tempSpeechDict.extend(self.speechDict)
3050-
globalVars.speechDictionaryProcessing=False
3051-
super().__init__(parent, resizeable=True)
3052-
# Historical initial size, result of L{self.dictList} being (550,350) as of #6287.
3053-
# Setting an initial size on L{self.dictList} by passing a L{size} argument when
3054-
# creating the control would also set its minimum size and thus block the dialog from being shrunk.
3055-
self.SetSize(576, 502)
3056-
self.CentreOnScreen()
3057-
3058-
def makeSettings(self, settingsSizer):
3059-
sHelper = guiHelper.BoxSizerHelper(self, sizer=settingsSizer)
3060-
# Translators: The label for the list box of dictionary entries in speech dictionary dialog.
3061-
entriesLabelText=_("&Dictionary entries")
3062-
self.dictList = sHelper.addLabeledControl(
3063-
entriesLabelText,
3064-
wx.ListCtrl, style=wx.LC_REPORT | wx.LC_SINGLE_SEL
3065-
)
3066-
# Translators: The label for a column in dictionary entries list used to identify comments for the entry.
3067-
self.dictList.InsertColumn(0,_("Comment"),width=150)
3068-
# Translators: The label for a column in dictionary entries list used to identify pattern (original word or a pattern).
3069-
self.dictList.InsertColumn(1,_("Pattern"),width=150)
3070-
# Translators: The label for a column in dictionary entries list and in a list of symbols from symbol pronunciation dialog used to identify replacement for a pattern or a symbol
3071-
self.dictList.InsertColumn(2,_("Replacement"),width=150)
3072-
# Translators: The label for a column in dictionary entries list used to identify whether the entry is case sensitive or not.
3073-
self.dictList.InsertColumn(3,_("case"),width=50)
3074-
# Translators: The label for a column in dictionary entries list used to identify whether the entry is a regular expression, matches whole words, or matches anywhere.
3075-
self.dictList.InsertColumn(4,_("Type"),width=50)
3076-
self.offOn = (_("off"),_("on"))
3077-
for entry in self.tempSpeechDict:
3078-
self.dictList.Append((entry.comment,entry.pattern,entry.replacement,self.offOn[int(entry.caseSensitive)],DictionaryDialog.TYPE_LABELS[entry.type]))
3079-
self.editingIndex=-1
3080-
3081-
bHelper = guiHelper.ButtonHelper(orientation=wx.HORIZONTAL)
3082-
bHelper.addButton(
3083-
parent=self,
3084-
# Translators: The label for a button in speech dictionaries dialog to add new entries.
3085-
label=_("&Add")
3086-
).Bind(wx.EVT_BUTTON, self.OnAddClick)
3087-
3088-
bHelper.addButton(
3089-
parent=self,
3090-
# Translators: The label for a button in speech dictionaries dialog to edit existing entries.
3091-
label=_("&Edit")
3092-
).Bind(wx.EVT_BUTTON, self.OnEditClick)
3093-
3094-
bHelper.addButton(
3095-
parent=self,
3096-
# Translators: The label for a button in speech dictionaries dialog to remove existing entries.
3097-
label=_("&Remove")
3098-
).Bind(wx.EVT_BUTTON, self.OnRemoveClick)
3099-
3100-
sHelper.addItem(bHelper)
3101-
3102-
def postInit(self):
3103-
self.dictList.SetFocus()
3104-
3105-
def onCancel(self,evt):
3106-
globalVars.speechDictionaryProcessing=True
3107-
super(DictionaryDialog, self).onCancel(evt)
3108-
3109-
def onOk(self,evt):
3110-
globalVars.speechDictionaryProcessing=True
3111-
if self.tempSpeechDict!=self.speechDict:
3112-
del self.speechDict[:]
3113-
self.speechDict.extend(self.tempSpeechDict)
3114-
self.speechDict.save()
3115-
super(DictionaryDialog, self).onOk(evt)
3116-
3117-
def OnAddClick(self,evt):
3118-
# Translators: This is the label for the add dictionary entry dialog.
3119-
entryDialog=DictionaryEntryDialog(self,title=_("Add Dictionary Entry"))
3120-
if entryDialog.ShowModal()==wx.ID_OK:
3121-
self.tempSpeechDict.append(entryDialog.dictEntry)
3122-
self.dictList.Append((entryDialog.commentTextCtrl.GetValue(),entryDialog.patternTextCtrl.GetValue(),entryDialog.replacementTextCtrl.GetValue(),self.offOn[int(entryDialog.caseSensitiveCheckBox.GetValue())],DictionaryDialog.TYPE_LABELS[entryDialog.getType()]))
3123-
index=self.dictList.GetFirstSelected()
3124-
while index>=0:
3125-
self.dictList.Select(index,on=0)
3126-
index=self.dictList.GetNextSelected(index)
3127-
addedIndex=self.dictList.GetItemCount()-1
3128-
self.dictList.Select(addedIndex)
3129-
self.dictList.Focus(addedIndex)
3130-
self.dictList.SetFocus()
3131-
entryDialog.Destroy()
3132-
3133-
def OnEditClick(self,evt):
3134-
if self.dictList.GetSelectedItemCount()!=1:
3135-
return
3136-
editIndex=self.dictList.GetFirstSelected()
3137-
if editIndex<0:
3138-
return
3139-
entryDialog=DictionaryEntryDialog(self)
3140-
entryDialog.patternTextCtrl.SetValue(self.tempSpeechDict[editIndex].pattern)
3141-
entryDialog.replacementTextCtrl.SetValue(self.tempSpeechDict[editIndex].replacement)
3142-
entryDialog.commentTextCtrl.SetValue(self.tempSpeechDict[editIndex].comment)
3143-
entryDialog.caseSensitiveCheckBox.SetValue(self.tempSpeechDict[editIndex].caseSensitive)
3144-
entryDialog.setType(self.tempSpeechDict[editIndex].type)
3145-
if entryDialog.ShowModal()==wx.ID_OK:
3146-
self.tempSpeechDict[editIndex]=entryDialog.dictEntry
3147-
self.dictList.SetItem(editIndex,0,entryDialog.commentTextCtrl.GetValue())
3148-
self.dictList.SetItem(editIndex,1,entryDialog.patternTextCtrl.GetValue())
3149-
self.dictList.SetItem(editIndex,2,entryDialog.replacementTextCtrl.GetValue())
3150-
self.dictList.SetItem(editIndex,3,self.offOn[int(entryDialog.caseSensitiveCheckBox.GetValue())])
3151-
self.dictList.SetItem(editIndex,4,DictionaryDialog.TYPE_LABELS[entryDialog.getType()])
3152-
self.dictList.SetFocus()
3153-
entryDialog.Destroy()
3154-
3155-
def OnRemoveClick(self,evt):
3156-
index=self.dictList.GetFirstSelected()
3157-
while index>=0:
3158-
self.dictList.DeleteItem(index)
3159-
del self.tempSpeechDict[index]
3160-
index=self.dictList.GetNextSelected(index)
3161-
self.dictList.SetFocus()
3162-
3163-
31642956
class BrailleSettingsPanel(SettingsPanel):
31652957
# Translators: This is the label for the braille panel
31662958
title = _("Braille")

0 commit comments

Comments
 (0)