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