commit/nvda: norrumar: Implemented review code suggestions for characterProcessing and add symbol: ticket 4354

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Wed, 05 Nov 2014 22:09:10 -0000

1 new commit in nvda:

https://bitbucket.org/nvdaaddonteam/nvda/commits/320774f784a7/
Changeset:   320774f784a7
Branch:      t4354
User:        norrumar
Date:        2014-11-05 22:08:19+00:00
Summary:     Implemented review code suggestions for characterProcessing and 
add symbol: ticket 4354

Affected #:  2 files

diff --git a/source/characterProcessing.py b/source/characterProcessing.py
index c1ed02f..ae36fcc 100644
--- a/source/characterProcessing.py
+++ b/source/characterProcessing.py
@@ -374,7 +374,7 @@ class SpeechSymbolProcessor(object):
                # We need to merge symbol data from several sources.
                sources = self.sources = []
                builtin, user = 
self.localeSymbols.fetchLocaleData(locale,fallback=False)
-               self.builtinSources = [builtin]
+               self.builtinSources = [builtin.symbols]
                self.userSymbols = user
                sources.append(user)
                sources.append(builtin)
@@ -383,7 +383,7 @@ class SpeechSymbolProcessor(object):
                if locale != "en":
                        # Only the builtin data.
                        
sources.append(self.localeSymbols.fetchLocaleData("en")[0])
-                       
self.builtinSources.append(self.localeSymbols.fetchLocaleData("en")[0])
+                       
self.builtinSources.extend(self.localeSymbols.fetchLocaleData("en")[0].symbols)
 
                # The computed symbol information from all sources.
                symbols = self.computedSymbols = collections.OrderedDict()
@@ -526,7 +526,10 @@ class SpeechSymbolProcessor(object):
                @rtype: bool
                """
                identifier = newSymbol.identifier
-               oldSymbol = self.computedSymbols[identifier]
+               try:
+                       oldSymbol = self.computedSymbols[identifier]
+               except KeyError:
+                       oldSymbol = None
                if oldSymbol is newSymbol:
                        return False
                try:
@@ -535,19 +538,19 @@ class SpeechSymbolProcessor(object):
                        userSymbol = SpeechSymbol(identifier)
 
                changed = False
-               if newSymbol.pattern != oldSymbol.pattern:
+               if oldSymbol and newSymbol.pattern != oldSymbol.pattern:
                        userSymbol.pattern = newSymbol.pattern
                        changed = True
-               if newSymbol.replacement != oldSymbol.replacement:
+               if not oldSymbol or newSymbol.replacement != 
oldSymbol.replacement:
                        userSymbol.replacement = newSymbol.replacement
                        changed = True
-               if newSymbol.level != oldSymbol.level:
+               if not oldSymbol or newSymbol.level != oldSymbol.level:
                        userSymbol.level = newSymbol.level
                        changed = True
-               if newSymbol.preserve != oldSymbol.preserve:
+               if not oldSymbol or newSymbol.preserve != oldSymbol.preserve:
                        userSymbol.preserve = newSymbol.preserve
                        changed = True
-               if newSymbol.displayName != oldSymbol.displayName:
+               if not oldSymbol or newSymbol.displayName != 
oldSymbol.displayName:
                        userSymbol.displayName = newSymbol.displayName
                        changed = True
 
@@ -561,8 +564,8 @@ class SpeechSymbolProcessor(object):
        def deleteSymbol(self, symbol):
                del self.userSymbols[symbol.identifier]
 
-       def isBuiltin(self, symbol):
-               if symbol in self.builtinSources:
+       def isBuiltin(self, symbolIdentifier):
+               if symbolIdentifier in self.builtinSources:
                        return True
                return False
 

diff --git a/source/gui/settingsDialogs.py b/source/gui/settingsDialogs.py
index 51a92da..6d0aead 100644
--- a/source/gui/settingsDialogs.py
+++ b/source/gui/settingsDialogs.py
@@ -1459,33 +1459,23 @@ class BrailleSettingsDialog(SettingsDialog):
                enable = len(self.possiblePorts) > 0 and not 
(len(self.possiblePorts) == 1 and self.possiblePorts[0][0] == "auto")
                self.portsList.Enable(enable)
 
-class SymbolEntryDialog(wx.Dialog):
+class AddSymbolDialog(wx.Dialog):
 
        # Translators: This is the label for the edit symbol entry dialog.
-       def __init__(self, parent, title=_("Edit Symbol Entry")):
-               super(SymbolEntryDialog,self).__init__(parent,title=title)
+       def __init__(self, parent, title=_("Add symbol")):
+               super(AddSymbolDialog,self).__init__(parent,title=title)
                mainSizer=wx.BoxSizer(wx.VERTICAL)
                settingsSizer=wx.BoxSizer(wx.VERTICAL)
                # Translators: This is a label for an edit field in add symbol 
entry dialog.
                settingsSizer.Add(wx.StaticText(self,-1,label=_("&Symbol")))
-               self.patternTextCtrl=wx.TextCtrl(self,wx.NewId())
-               settingsSizer.Add(self.patternTextCtrl)
-               # Translators: This is a label for an edit field in add 
dictionary entry dialog and in punctuation/symbol pronunciation dialog.
-               
settingsSizer.Add(wx.StaticText(self,-1,label=_("&Replacement")))
-               self.replacementTextCtrl=wx.TextCtrl(self,wx.NewId())
-               settingsSizer.Add(self.replacementTextCtrl)
-               # Translators: The label for the combo box in symbol 
pronunciation dialog to change the speech level of a symbol.
-               settingsSizer.Add(wx.StaticText(self, wx.ID_ANY, _("&Level")))
-               symbolLevelLabels = 
characterProcessing.SPEECH_SYMBOL_LEVEL_LABELS
-               self.levelList = wx.Choice(self, wx.ID_ANY,choices=[
-                       symbolLevelLabels[level] for level in 
characterProcessing.SPEECH_SYMBOL_LEVELS])
-               settingsSizer.Add(self.levelList)
+               self.identifierTextCtrl=wx.TextCtrl(self,wx.NewId())
+               settingsSizer.Add(self.identifierTextCtrl)
                
mainSizer.Add(settingsSizer,border=20,flag=wx.LEFT|wx.RIGHT|wx.TOP)
                buttonSizer=self.CreateButtonSizer(wx.OK|wx.CANCEL)
                
mainSizer.Add(buttonSizer,border=20,flag=wx.LEFT|wx.RIGHT|wx.BOTTOM)
                mainSizer.Fit(self)
                self.SetSizer(mainSizer)
-               self.patternTextCtrl.SetFocus()
+               self.identifierTextCtrl.SetFocus()
 
 class SpeechSymbolsDialog(SettingsDialog):
        # Translators: This is the label for the symbol pronunciation dialog.
@@ -1536,16 +1526,14 @@ class SpeechSymbolsDialog(SettingsDialog):
                changeSizer.Add(sizer)
                settingsSizer.Add(changeSizer)
                entryButtonsSizer=wx.BoxSizer(wx.HORIZONTAL)
-               addButtonID=wx.NewId()
                # Translators: The label for a button in speech symbols dialog 
to add new entries.
-               
addButton=wx.Button(self,addButtonID,_("&Add"),wx.DefaultPosition)
+               addButton=wx.Button(self,label=_("&Add"))
                entryButtonsSizer.Add(addButton)
-               removeButtonID=wx.NewId()
-               
self.removeButton=wx.Button(self,removeButtonID,_("&Remove"),wx.DefaultPosition)
+               self.removeButton=wx.Button(self,label=_("&Remove"))
                self.removeButton.Disable()
                entryButtonsSizer.Add(self.removeButton)
-               self.Bind(wx.EVT_BUTTON,self.OnAddClick,id=addButtonID)
-               self.Bind(wx.EVT_BUTTON,self.OnRemoveClick,id=removeButtonID)
+               addButton.Bind(wx.EVT_BUTTON,self.OnAddClick)
+               self.removeButton.Bind(wx.EVT_BUTTON,self.OnRemoveClick)
                settingsSizer.Add(entryButtonsSizer)
 
                self.editingItem = None
@@ -1566,10 +1554,11 @@ class SpeechSymbolsDialog(SettingsDialog):
                symbol.replacement = self.replacementEdit.Value
                symbol.level = 
characterProcessing.SPEECH_SYMBOL_LEVELS[self.levelList.Selection]
                self.updateListItem(item, symbol)
-               if symbol.identifier not in 
self.symbolProcessor.builtinSymbols.symbols.keys(): # and symbol.identifier in 
self.symbolProcessor.userSymbols.symbols.keys() or symbol in self.addedSymbols:
-                       self.removeButton.Enable()
-               else:
-                       self.removeButton.Disable()
+               #if symbol.identifier not in 
self.symbolProcessor.builtinSymbols.symbols.keys(): # and symbol.identifier in 
self.symbolProcessor.userSymbols.symbols.keys() or symbol in self.addedSymbols:
+                       #self.removeButton.Enable()
+               #else:
+                       #self.removeButton.Disable()
+               self.removeButton.Enabled = not 
self.symbolProcessor.isBuiltin(symbol.identifier)
 
        def onListItemFocused(self, evt):
                # Update the editing controls to reflect the newly selected 
symbol.
@@ -1592,22 +1581,15 @@ class SpeechSymbolsDialog(SettingsDialog):
 
        def OnAddClick(self,evt):
                # Translators: This is the label for the add symbol entry 
dialog.
-               entryDialog=SymbolEntryDialog(self,title=_("Add Synbol Entry"))
+               entryDialog=AddSymbolDialog(self)
                if entryDialog.ShowModal()==wx.ID_OK:
-                       addedSymbol = 
characterProcessing.SpeechSymbol(entryDialog.patternTextCtrl.GetValue())
-                       addedSymbol.displayName = addedSymbol.pattern = 
entryDialog.patternTextCtrl.GetValue()
-                       #addedSymbol.pattern = 
entryDialog.patternTextCtrl.GetValue()
-                       addedSymbol.replacement = 
entryDialog.replacementTextCtrl.GetValue()
-                       addedSymbol.level = 
characterProcessing.SPEECH_SYMBOL_LEVELS[entryDialog.levelList.Selection]
+                       addedSymbol = 
characterProcessing.SpeechSymbol(entryDialog.identifierTextCtrl.GetValue())
+                       addedSymbol.displayName = 
entryDialog.identifierTextCtrl.GetValue()
+                       addedSymbol.replacement = ""
+                       addedSymbol.level = characterProcessing.SYMLVL_ALL
                        self.symbols.append(addedSymbol)
-                       self.symbolsList.DeleteAllItems()
-                       for symbol in self.symbols:
-                               item = 
self.symbolsList.Append((symbol.displayName,))
-                               self.updateListItem(item, symbol)
-                       index=self.symbolsList.GetFirstSelected()
-                       while index>=0:
-                               self.symbolsList.Select(index,on=0)
-                               index=self.symbolsList.GetNextSelected(index)
+                       item = 
self.symbolsList.Append((addedSymbol.displayName,))
+                       self.updateListItem(item, addedSymbol)
                        addedIndex=self.symbolsList.GetItemCount()-1
                        self.symbolsList.Select(addedIndex)
                        self.symbolsList.Focus(addedIndex)
@@ -1635,7 +1617,8 @@ class SpeechSymbolsDialog(SettingsDialog):
                self.onSymbolEdited(None)
                self.editingItem = None
                for symbol in self.symbols:
-                       self.symbolProcessor.updateSymbol(symbol)
+                       if symbol.replacement != "":
+                               self.symbolProcessor.updateSymbol(symbol)
                try:
                        self.symbolProcessor.userSymbols.save()
                except IOError as e:

Repository URL: https://bitbucket.org/nvdaaddonteam/nvda/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.

Other related posts:

  • » commit/nvda: norrumar: Implemented review code suggestions for characterProcessing and add symbol: ticket 4354 - commits-noreply