initial punctuation and dict import

This commit is contained in:
root 2016-10-12 21:36:11 +02:00
parent 6ec714e494
commit 0c0564012c
7 changed files with 51 additions and 101 deletions

View File

@ -97,6 +97,7 @@ doubleTapDelay=0.2
[general] [general]
debugLevel=3 debugLevel=3
punctuationProfile=default
punctuationLevel=some punctuationLevel=some
numberOfClipboards=10 numberOfClipboards=10
# define the current fenrir key # define the current fenrir key

View File

@ -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

View File

@ -11,6 +11,7 @@ from core import screenData
from core import generalInformation from core import generalInformation
from core import commands from core import commands
from core import inputEvent from core import inputEvent
from core import punctuation
environment = { environment = {
'screenData': screenData.screenData, 'screenData': screenData.screenData,
@ -22,6 +23,7 @@ environment = {
'commandInfo': commands.commandInfo, 'commandInfo': commands.commandInfo,
'commandBuffer': commands.commandBuffer, 'commandBuffer': commands.commandBuffer,
'input': inputEvent.input, 'input': inputEvent.input,
'punctuation': punctuation.punctuation,
'soundIcons': {}, 'soundIcons': {},
'bindings': {}, 'bindings': {},
} }

View File

@ -17,55 +17,6 @@ class punctuationManager():
# dot, comma, grave, apostrophe # dot, comma, grave, apostrophe
for char in [ord('.'),ord(','),ord('`'),ord("'")]: for char in [ord('.'),ord(','),ord('`'),ord("'")]:
self.allPunctNone[char] = None 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): def shutdown(self):
pass pass
def removeUnused(self, text): def removeUnused(self, text):
@ -87,18 +38,19 @@ class punctuationManager():
return resultText return resultText
def proceedPunctuation(self, text, ignorePunctuation=False): 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 = '' currPunctLevel = ''
if not ignorePunctuation and self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower() in self.punctuation['levels']: if not ignorePunctuation and self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower() in self.env['punctuation']['LEVELDICT']:
currPunctLevel = self.punctuation['levels'][self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()] currPunctLevel = self.env['punctuation']['LEVELDICT'][self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()]
else: else:
currPunctLevel = string.punctuation currPunctLevel = string.punctuation
resultText = self.usePunctuationDict(resultText, self.punctuation['punctuationDict'], currPunctLevel) resultText = self.usePunctuationDict(resultText, self.env['punctuation']['PUNCTDICT'], currPunctLevel)
resultText = self.removeUnused(resultText) resultText = self.removeUnused(resultText)
return resultText return resultText
def cyclePunctuation(self): def cyclePunctuation(self):
punctList = list(self.punctuation['levels'].keys()) punctList = list(self.env['punctuation']['LEVELDICT'].keys())
try: try:
currIndex = punctList.index(self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()) # curr punctuation currIndex = punctList.index(self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()) # curr punctuation
except: except:

View File

@ -41,6 +41,7 @@ settings = {
}, },
'general':{ 'general':{
'debugLevel': debug.debugLevel.DEACTIVE, 'debugLevel': debug.debugLevel.DEACTIVE,
'punctuationProfile':'default',
'punctuationLevel': 1, 'punctuationLevel': 1,
'numberOfClipboards': 10, 'numberOfClipboards': 10,
'fenrirKeys': ['KEY_KP0'], 'fenrirKeys': ['KEY_KP0'],

View File

@ -33,6 +33,8 @@ class settingsManager():
if not line: if not line:
break break
line = line.replace('\n','') line = line.replace('\n','')
if line.replace(" ","") == '':
continue
if line.replace(" ","").startswith("#"): if line.replace(" ","").startswith("#"):
continue continue
if line.count("=") != 1: if line.count("=") != 1:
@ -64,6 +66,8 @@ class settingsManager():
if not line: if not line:
break break
line = line.replace('\n','') line = line.replace('\n','')
if line.replace(" ","") == '':
continue
if line.replace(" ","").startswith("#"): if line.replace(" ","").startswith("#"):
continue continue
if line.count("=") != 1: if line.count("=") != 1:
@ -83,6 +87,33 @@ class settingsManager():
self.env['soundIcons'][soundIcon] = soundIconFile self.env['soundIcons'][soundIcon] = soundIconFile
siConfig.close() 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): def loadSettings(self, settingConfigPath):
if not os.path.exists(settingConfigPath): if not os.path.exists(settingConfigPath):
return False return False
@ -189,6 +220,16 @@ class settingsManager():
else: else:
environment['runtime']['settingsManager'].loadSoundIcons(self.getSetting('sound','theme')) 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'] = inputManager.inputManager()
environment['runtime']['inputManager'].initialize(environment) environment['runtime']['inputManager'].initialize(environment)
environment['runtime']['outputManager'] = outputManager.outputManager() environment['runtime']['outputManager'] = outputManager.outputManager()

View File

@ -1,7 +1,5 @@
setup.py setup.py
src/fenrir/fenrir src/fenrir/fenrir
src/fenrir/braille/__init__.py
src/fenrir/braille/braille.py
src/fenrir/commands/__init__.py src/fenrir/commands/__init__.py
src/fenrir/commands/command_template.py src/fenrir/commands/command_template.py
src/fenrir/commands/switchTrigger_template.py src/fenrir/commands/switchTrigger_template.py