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]
debugLevel=3
punctuationProfile=default
punctuationLevel=some
numberOfClipboards=10
# 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 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': {},
}

View File

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

View File

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

View File

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

View File

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