diff --git a/config/settings/settings.conf b/config/settings/settings.conf index e090b402..ad76400e 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -97,6 +97,7 @@ doubleTapDelay=0.2 [general] debugLevel=3 +punctuationProfile=default punctuationLevel=some numberOfClipboards=10 # define the current fenrir key diff --git a/config/substitution/default.conf b/config/substitution/default.conf deleted file mode 100644 index d693a5fe..00000000 --- a/config/substitution/default.conf +++ /dev/null @@ -1,45 +0,0 @@ -[levelProfile] -None= -Some=.-$~+*-/\\@ -Most=.,:-$~+*-/\\@!#%^&*()[]}{<>; -All=!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ - -[punctDict] -&=and -'=apostrophe -@=at -\=backslash -|=bar -!=bang -^=carrot -:=colon -,=comma --=dash -$=dollar -.=dot ->=greater -`=grave -#=hash -{=left brace -[=left bracket -(=left paren -<=less -%=percent -+=plus -?=question -"=quote -)=right paren -}=right brace -]=right bracket -;=semicolon -/=slash -*=star -~=tilde -_=line -==equals - -[userDict] -:)=smile -;)=twinker -XD=loool -:D=lought diff --git a/src/fenrir/core/environment.py b/src/fenrir/core/environment.py index 6d66dc85..367305a8 100644 --- a/src/fenrir/core/environment.py +++ b/src/fenrir/core/environment.py @@ -11,6 +11,7 @@ from core import screenData from core import generalInformation from core import commands from core import inputEvent +from core import punctuation environment = { 'screenData': screenData.screenData, @@ -22,6 +23,7 @@ environment = { 'commandInfo': commands.commandInfo, 'commandBuffer': commands.commandBuffer, 'input': inputEvent.input, +'punctuation': punctuation.punctuation, 'soundIcons': {}, 'bindings': {}, } diff --git a/src/fenrir/core/punctuationManager.py b/src/fenrir/core/punctuationManager.py index b7b2f686..74465d82 100644 --- a/src/fenrir/core/punctuationManager.py +++ b/src/fenrir/core/punctuationManager.py @@ -17,55 +17,6 @@ class punctuationManager(): # dot, comma, grave, apostrophe for char in [ord('.'),ord(','),ord('`'),ord("'")]: self.allPunctNone[char] = None - self.punctuation = { - 'levels':{ - 'none': '', - 'some': '#-$~+*-/\\@', - 'most': '.,:-$~+*-/\\@!#%^&*()[]}{<>;', - 'all': string.punctuation, - }, - 'punctuationDict':{ - '&':'and', - "'":"apostrophe", - '@':'at', - '\\':'backslash', - '|':'bar', - '!':'bang', - '^':'carrot', - ':':'colon', - ',':'comma', - '-':'dash', - '$':'dollar', - '.':'dot', - '>':'greater', - '`':'grave', - '#':'hash', - '{':'left brace', - '[':'left bracket', - '(':'left paren', - '<':'less', - '%':'percent', - '+':'plus', - '?':'question', - '"':'quote', - ')':'right paren', - '}':'right brace', - ']':'right bracket', - ';':'semicolon', - '/':'slash', - '*':'star', - '~':'tilde', - '_':'line', - '=':'equals', - }, - 'customDict':{ - ':)':'smiley', - ';)':'winking face', - 'XD':'loool', - ':@':'angry face', - ':D':'lought' - } - } def shutdown(self): pass def removeUnused(self, text): @@ -87,18 +38,19 @@ class punctuationManager(): return resultText def proceedPunctuation(self, text, ignorePunctuation=False): - resultText = self.useCustomDict(text, self.punctuation['customDict']) + resultText = self.useCustomDict(text, self.env['punctuation']['CUSTOMDICT']) + resultText = self.useCustomDict(text, self.env['punctuation']['EMOJDICT']) currPunctLevel = '' - if not ignorePunctuation and self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower() in self.punctuation['levels']: - currPunctLevel = self.punctuation['levels'][self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()] + if not ignorePunctuation and self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower() in self.env['punctuation']['LEVELDICT']: + currPunctLevel = self.env['punctuation']['LEVELDICT'][self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()] else: currPunctLevel = string.punctuation - resultText = self.usePunctuationDict(resultText, self.punctuation['punctuationDict'], currPunctLevel) + resultText = self.usePunctuationDict(resultText, self.env['punctuation']['PUNCTDICT'], currPunctLevel) resultText = self.removeUnused(resultText) return resultText def cyclePunctuation(self): - punctList = list(self.punctuation['levels'].keys()) + punctList = list(self.env['punctuation']['LEVELDICT'].keys()) try: currIndex = punctList.index(self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()) # curr punctuation except: diff --git a/src/fenrir/core/settings.py b/src/fenrir/core/settings.py index a4fcbb12..13e4895b 100644 --- a/src/fenrir/core/settings.py +++ b/src/fenrir/core/settings.py @@ -41,6 +41,7 @@ settings = { }, 'general':{ 'debugLevel': debug.debugLevel.DEACTIVE, + 'punctuationProfile':'default', 'punctuationLevel': 1, 'numberOfClipboards': 10, 'fenrirKeys': ['KEY_KP0'], diff --git a/src/fenrir/core/settingsManager.py b/src/fenrir/core/settingsManager.py index 0d540500..2966e49a 100644 --- a/src/fenrir/core/settingsManager.py +++ b/src/fenrir/core/settingsManager.py @@ -33,6 +33,8 @@ class settingsManager(): if not line: break line = line.replace('\n','') + if line.replace(" ","") == '': + continue if line.replace(" ","").startswith("#"): continue if line.count("=") != 1: @@ -64,6 +66,8 @@ class settingsManager(): if not line: break line = line.replace('\n','') + if line.replace(" ","") == '': + continue if line.replace(" ","").startswith("#"): continue if line.count("=") != 1: @@ -83,6 +87,33 @@ class settingsManager(): self.env['soundIcons'][soundIcon] = soundIconFile siConfig.close() + def loadDicts(self, dictConfigPath=os.path.dirname(os.path.realpath(__main__.__file__)) + '/../../config/punctuation/default.conf'): + dictConfig = open(dictConfigPath,"r") + currDictName = '' + while(True): + line = dictConfig.readline() + if not line: + break + line = line.replace('\n','') + if line.replace(" ","") == '': + continue + if line.replace(" ","").startswith("#"): + continue + if line.replace(" ","").upper().startswith("[") and \ + line.replace(" ","").upper().endswith("DICT]"): + currDictName = line[line.find('[') + 1 :line.upper().find('DICT]') + 4].upper() + else: + if currDictName == '': + continue + if not ":===:" in line: + continue + sepLine = line.split(':===:') + if len(sepLine) != 2: + sepLine.append('') + self.env['punctuation'][currDictName][sepLine[0]] = sepLine[1] + self.env['runtime']['debug'].writeDebugOut("Punctuation: " + currDictName + '.' + str(sepLine[0]) + ' :' + sepLine[1] ,debug.debugLevel.INFO) + dictConfig.close() + def loadSettings(self, settingConfigPath): if not os.path.exists(settingConfigPath): return False @@ -189,6 +220,16 @@ class settingsManager(): else: environment['runtime']['settingsManager'].loadSoundIcons(self.getSetting('sound','theme')) + if not os.path.exists(self.getSetting('general','punctuationProfile')): + if os.path.exists(settingsRoot + 'punctuation/' + self.getSetting('general','punctuationProfile')): + self.setSetting('general', 'punctuationProfile', settingsRoot + 'punctuation/' + self.getSetting('general','punctuationProfile')) + environment['runtime']['settingsManager'].loadDicts(self.getSetting('general','punctuationProfile')) + if os.path.exists(settingsRoot + 'punctuation/' + self.getSetting('general','punctuationProfile') + '.conf'): + self.setSetting('general', 'punctuationProfile', settingsRoot + 'punctuation/' + self.getSetting('general','punctuationProfile') + '.conf') + environment['runtime']['settingsManager'].loadDicts(self.getSetting('general','punctuationProfile')) + else: + environment['runtime']['settingsManager'].loadDicts(self.getSetting('general','punctuationProfile')) + environment['runtime']['inputManager'] = inputManager.inputManager() environment['runtime']['inputManager'].initialize(environment) environment['runtime']['outputManager'] = outputManager.outputManager() diff --git a/src/fenrir/fenrir.egg-info/SOURCES.txt b/src/fenrir/fenrir.egg-info/SOURCES.txt index e8c40a4b..16a43f15 100644 --- a/src/fenrir/fenrir.egg-info/SOURCES.txt +++ b/src/fenrir/fenrir.egg-info/SOURCES.txt @@ -1,7 +1,5 @@ setup.py src/fenrir/fenrir -src/fenrir/braille/__init__.py -src/fenrir/braille/braille.py src/fenrir/commands/__init__.py src/fenrir/commands/command_template.py src/fenrir/commands/switchTrigger_template.py