-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_control.py
More file actions
executable file
·694 lines (611 loc) · 27 KB
/
Copy path_control.py
File metadata and controls
executable file
·694 lines (611 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
"""Unimacro grammar that controls/shows/traces state of other grammars
"""
__version__ = "$Rev: 537 $ on $Date: 2014-04-16 16:41:11 +0200 (wo, 16 apr 2014) $ by $Author: quintijn $"
# This file is part of a SourceForge project called "unimacro" see
# http://unimacro.SourceForge.net and http://qh.antenna.nl/unimacro
# (c) copyright 2003 see http://qh.antenna.nl/unimacro/aboutunimacro.html
# or the file COPYRIGHT.txt in the natlink\natlink directory
#
# _control.py, adapted version of_gramutils.py
# Author: Bart Jan van Os, Version: 1.0, nov 1999
# starting new version Quintijn Hoogenboom, August 2003
import string,os,sys,re # cPickle
import natlink
from natlinkutils import *
from natlinkmain import loadedFiles, unloadModule, loadModule
natbj = __import__('natlinkutilsbj')
natut = __import__('natlinkutils')
natqh = __import__('natlinkutilsqh')
import D_
# extra commands for controlling actions module:
try:
actions = __import__('actions')
except ImportError:
actions = None
print 'warning: actions module not imported'
try:
spokenforms = __import__('spokenforms')
except ImportError:
spokenforms = None
print 'warning: spokenforms module not imported'
tracecount = map(str, range(1, 10))
#Words that are 'filtered out' (actually: removed) in Filter Mode
#See below for the different modes
def ReadFilteredWords(Filename):
#reads all words from the Filtered words file
#does not really belong here
try:
File=open(Filename,'r')
except:
return []
Words = File.readlines()
File.close
for w in Words:
Words[Words.index(w)]=w[:-1]
freq={}
for w in Words:
if freq.has_key(w):
freq[w]=freq[w]+1
else:
freq[w]=1
Words=freq.keys()
return Words
FilteredWords = ['in','the','minimum','to','and','end','a','of','that','it',
'if', 'its', 'is', 'this', 'booth', 'on', 'with',"'s"]
#(taken from natlinkmain, to prevent import:)
baseDirectory = natqh.getUnimacroUserDirectory()
FilterFileName=baseDirectory+'\\filtered.txt'
FilteredWords=natbj.Union(FilteredWords, ReadFilteredWords(FilterFileName))
#Constants for the UtilGrammar
Normal=0
Training=1 #obsolete
Command=2 #obsolete
Filter=4
FilterTraining=5
Display=6
showAll = 1 # reset if no echo of exclusive commands is wished
#voicecodeHome = None
#if 'VCODE_HOME' in os.environ:
# voicecodeHome = os.environ['VCODE_HOME']
# if os.path.isdir(voicecodeHome):
# for subFolder in ('Admin', 'Config', 'Mediator'):
# newFolder = os.path.join(voicecodeHome, subFolder)
# if os.path.isdir(newFolder) and newFolder not in sys.path:
# sys.path.append(newFolder)
# print 'appending to sys.path: %s'% newFolder
# else:
# print '_control: VCODE_HOME points NOT to a directory: %s'% voicecodeHome
# voicecodeHome = None
ancestor = natbj.IniGrammar
class UtilGrammar(ancestor):
language = natqh.getLanguage()
iniIgnoreGrammarLists = ['gramnames', 'tracecount', 'message'] # are set in this module
name = 'control'
## normalSet = ['show', 'edit', 'trace', 'switch', 'message']
## exclusiveSet = ['showexclusive', 'message']
# commands for controlling module actions
specialList = []
if actions:
specialList.append("actions")
if spokenforms:
specialList.append("'spoken forms'")
if specialList:
specials = "|" + '|'.join(specialList)
else:
specials = ""
gramRules = ['show', 'edit', 'switch', 'showexclusive', 'resetexclusive', 'checkalphabet', 'message']
gramDict = {}
gramDict['show'] = """<show> exported = show ((all|active) grammars |
{gramnames} | (grammar|inifile) {gramnames}
""" + specials + """);"""
gramDict['edit'] = """<edit> exported = edit ({gramnames}| (grammar|inifile) {gramnames}"""+ specials +""");"""
gramDict['switch'] = """<switch> exported = switch ((on|off) ((all grammars)|{gramnames}|grammar {gramnames})|
((all grammars)|{gramnames}|grammar {gramnames})(on|off));"""
gramDict['showexclusive'] = """<showexclusive> exported = show (exclusive |exclusive grammars);"""
gramDict['resetexclusive'] = """<resetexclusive> exported = reset (exclusive | exclusive grammars);"""
gramDict['checkalphabet'] = """<checkalphabet> exported = check alphabet;"""
gramDict['message'] = """<message> exported = {message};"""
gramSpec = []
assert set(gramRules) == set(gramDict.keys())
if language == 'nld':
gramDict['checkalphabet'] = """<checkalphabet> exported = controleer alfabet;"""
for rulename in gramRules:
gramSpec.append(gramDict[rulename])
## extra: the trace rule:
if specials:
specials2 = specials[1:] # remove initial "|" (at show it is "| actions | 'spoken forms'", here it is
# "actions | 'spoken forms'" only, because gramnames etc are not implemented
# for tracing)
traceSpecial = """<trace> exported = trace (("""+ specials2 +""") |
((on|off| {tracecount})("""+ specials2 +""")) |
(("""+ specials2 +""") (on|off|{tracecount}))) ;"""
gramSpec.append(traceSpecial) # add trace for actions of spoken forms (latter not implemented)
Mode = Normal
LastMode = Normal
CurrentWord = 0
Repeat = 0
def initialize(self):
global loadedNames
# temp set allResults to 0, disabling the messages trick:
if not self.load(self.gramSpec, allResults=showAll):
return None
natbj.RegisterControlObject(self)
self.emptyList('message')
self.setList('gramnames', natbj.loadedGrammars.keys())
self.setNumbersList('tracecount', tracecount)
self.activateAll()
self.setMode(Normal)
self.startExclusive = self.exclusive # exclusive state at start of recognition!
## if natqh.getUser() == 'martijn':
## print 'martijn, set exclusive %s'% self.name
## self.setExclusive(1)
def unload(self):
natbj.UnRegisterControlObject(self)
ancestor.unload(self)
def gotBegin(self, moduleInfo):
#Now is the time to get the names of the grammar objects and
# activate the list for the <ShowTrainGrammar> rule
if natbj.grammarsChanged:
prevSet = set(self.Lists['gramnames'])
newSet = set(natbj.loadedGrammars.keys())
if prevSet != newSet:
if newSet - prevSet:
print '_control, added Unimacro grammar(s): %s'% list(newSet - prevSet)
if prevSet - newSet:
print '_control, removed Unimacro grammar(s): %s'% list(prevSet - newSet)
self.setList('gramnames', list(newSet))
natbj.ClearGrammarsChangedFlag()
if self.checkForChanges:
self.checkInifile()
self.startExclusive = self.exclusive # exclusive state at start of recognition!
def gotResultsInit(self,words,fullResults):
if self.mayBeSwitchedOn == 'exclusive':
print 'recog controle, switch off mic: %s'% words
natbj.SetMic('off')
if self.exclusive:
self.DisplayMessage('<%s>'% ' '.join(words))
def resetExclusiveMode(self):
"""no activateAll, do nothing, this grammar follows the last unexclusive grammar
"""
pass
def setExclusiveMode(self):
"""no nothing, control follows other exclusive grammars
"""
pass
def gotResultsObject(self,recogType,resObj):
if natbj.IsDisplayingMessage:
return
mes = natbj.GetPendingMessage()
if mes:
mes = '\n\n'.join(mes)
natbj.ClearPendingMessage()
self.DisplayMessage(mes)
return
natqh.doPendingBringUps() # if there were
natqh.doPendingExecScripts() # if there were
if self.startExclusive and self.exclusive and showAll:
# display recognition results for exclusive grammars
# with showAll = None (in top of this file), you can disable this feature
if recogType == 'reject':
URName = ''
exclGram = natbj.exclusiveGrammars
exclGramKeys = exclGram.keys()
if len(exclGramKeys) > 1 and self.name in exclGramKeys:
exclGramKeys.remove(self.name)
if len(exclGramKeys) > 1:
URName = ', '.join(exclGramKeys)
k = exclGramKeys[0]
v = exclGram[k]
# UE stands for unrecognised exclusive:
# if more exclusive grammars,
# the last one is taken
URName = URName or v[2] # combined name or last rule of excl grammar
msg = '<'+URName+': ???>'
self.DisplayMessage(msg, alsoPrint=0)
#Utilities for Filter Modes and other special modes
def setMode(self,NewMode):
self.LastMode = self.Mode
self.Mode = NewMode
def restoreMode(self):
self.Mode = self.LastMode
def gotResults_checkalphabet(self,words,fullResults):
"""check the exact spoken versions of the alphabet in spokenforms
"""
import spokenforms
version = natqh.getDNSVersion()
spok = spokenforms.SpokenForms(self.language, version)
alph = 'alphabet'
ini = spokenforms.ini
for letter in string.ascii_lowercase:
spoken = ini.get(alph, letter, '')
if not spoken:
print 'fill in in "%s_spokenform.ini", [alphabet] spoken for: "%s"'% (self.language, letter)
continue
if version < 11:
normalform = '%s\\%s'% (letter.upper(), spoken)
else:
normalform = '%s\\letter\\%s'% (letter.upper(), spoken)
try:
natlink.recognitionMimic([normalform])
except natlink.MimicFailed:
print 'invalid spoken form "%s" for "%s"'% (spoken, letter)
if spoken == spoken.lower():
spoken = spoken.capitalize()
trying = 'try capitalized variant'
elif spoken == spoken.capitalize():
spoken = spoken.lower()
trying = 'try lowercase variant'
else:
continue
if version < 11:
normalform = '%s\\%s'% (letter.upper(), spoken)
else:
normalform = '%s\\letter\\%s'% (letter.upper(), spoken)
try:
natlink.recognitionMimic([normalform])
except natlink.MimicFailed:
print '%s fails also: "%s" for "%s"'% (trying, spoken, letter)
else:
print 'alphabet section is corrected with: "%s = %s"'% (letter, spoken)
ini.set(alph, letter, spoken)
ini.writeIfChanged()
def gotResults_trace(self,words,fullResults):
print 'control, trace: %s'% words
traceNumList = self.getNumbersFromSpoken(words) # returns a string or None
if traceNumList:
traceNum = int(traceNumList[0])
else:
traceNum = None
if self.hasCommon(words, 'actions'):
if self.hasCommon(words, 'show'):
actions.debugActionsShow()
elif self.hasCommon(words, 'off'):
actions.debugActions(0)
elif self.hasCommon(words, 'on'):
actions.debugActions(1)
elif traceNum:
actions.debugActions(traceNum)
else:
actions.debugActions(1)
elif self.hasCommon(words, 'spoken forms'):
print "no tracing possible for spoken forms"
#def gotResults_voicecode(self,words,fullResults):
# """switch on if requirements are fulfilled
#
# voicecodeHome must exist
# emacs must be in foreground
# """
# wxmed = os.path.join(voicecodeHome, 'mediator', 'wxmediator.py')
# if os.path.isfile(wxmed):
# commandLine = r"%spython.exe %s > D:\foo1.txt >> D:\foo2.txt"% (sys.prefix, wxmed)
# os.system(commandLine)
# else:
# print 'not a file: %s'% wxmed
def gotResults_switch(self,words,fullResults):
#print 'control, switch: %s'% words
if self.hasCommon(words, 'on'):
funcName = 'switchOn'
elif self.hasCommon(words, 'off'):
funcName = 'switchOff'
else:
try:
t = {'nld': '<%s: ongeldig schakel-commando>'% self.GetName()}[self.language]
except:
t = '<%s: invalid switch command>'% self.GetName()
self.DisplayMessage(t)
return
if self.hasCommon(words, 'all grammars'):
#print '%s all grammars:'% funcName
for g in natbj.loadedGrammars:
gram = natbj.loadedGrammars[g]
if gram == self:
print 'no need to switch on _control (should always be on...)'
else:
self.switch(gram, g, funcName)
else:
gramname = self.hasCommon(words, natbj.loadedGrammars.keys())
if gramname:
gram = natbj.loadedGrammars[gramname]
if gram == self:
print 'No %s of grammar _control needed or allowed!'% funcName
else:
self.switch(gram, gramname, funcName)
else:
print 'no grammar name found: %s'% gramname
def switch(self, gram, gramName, funcName):
"""switch on or off grammar, and set in inifile,
force the setting!
"""
func = getattr(gram, funcName)
# in case manual changes were done:
#gram.checkInifile()
if funcName == 'switchOn':
self.checkInifile()
if not gram.mayBeSwitchedOn:
gram.ini.set('general', 'initial on', 1)
#gram.mayBeSwitchedOn = 1
gram.ini.write()
print 'reload grammar "%s" after 1 seconds (switching on)'% gram.getName()
natqh.Wait(1)
else:
print 'reload grammar "%s"'% gram.getName()
modName = gram.__module__
unloadModule(modName)
loadModule(modName)
#print 'reloaded "%s"'% modName
return 1
elif funcName == 'switchOff':
if gram.mayBeSwitchedOn:
gram.ini.set('general', 'initial on', 0)
gram.ini.writeIfChanged()
gram.mayBeSwitchedOn = 0
result = func()
print 'grammar "%s" switched off'% gram.getName()
else:
result = func()
print 'grammar "%s" switched off (again)'% gram.getName()
else:
raise ValueError('switching on/off should have as function "switchOn" or "switchOff", not: %s'% func)
def gotResults_showexclusive(self,words,fullResults):
All = 0
name = 'exclusive grammars'
if len(name)>0:
Start=(string.join(name),[])
else:
Start=()
# fix state at this moment (in case of Active grammars popup)
if natbj.exclusiveGrammars:
Exclusive = 1
self.BrowsePrepare(Start, All, Exclusive)
T = ['exclusive grammars:']
for e in natbj.exclusiveGrammars:
T.append('\t'+e)
T.append('\t'+self.name)
T.append('')
T.append('')
T.append("Note: exclusive mode is still on, so the buttons of this dialog cannot be clicked by voice.")
T.append('')
T.append("Reset the exclusive mode by toggling the microphone")
T.append('or by calling the command "reset exclusive mode"')
T.append('')
T.append("Show details of exclusive Unimacro grammars?")
msg = '\n'.join(T)
if actions.YesNo(msg, "Exclusive grammars", icon="information", defaultToSecondButton=1):
self.BrowseShow()
else:
self.DisplayMessage('no exclusive grammars')
def gotResults_resetexclusive(self,words,fullResults):
print 'reset exclusive'
if natbj.exclusiveGrammars:
T = ['exclusive grammars:']
for e in natbj.exclusiveGrammars:
T.append(e)
T.append(self.name)
T.append('... reset exclusive mode')
self.DisplayMessage(' '.join(T))
natbj.GlobalResetExclusiveMode()
natqh.Wait(1)
self.DisplayMessage('reset exclusive mode OK')
else:
self.DisplayMessage('no exclusive grammars')
## def setExclusive(self, state):
## """control grammar, do NOT register, set and maintain state
##
## special position because of ControlGrammar
## """
## print 'control set exclusive: %s'% state
## if state == None:
## return
## if state == self.exclusive:
## return
## print 'control, (re)set exclusive: %s'% state
## self.gramObj.setExclusive(state)
## self.exclusive = state
def gotResults_show(self,words,fullResults):
# special case for actions:
if self.hasCommon(words, 'actions'):
actions.showActions(comingFrom=self, name="show actions")
return
if self.hasCommon(words, 'spoken forms'):
spokenforms.showSpokenForms(comingFrom=self, name="show spoken forms", language=self.language)
return
Exclusive = 0
if natbj.exclusiveGrammars:
print 'exclusive grammars (+ control) are: %s'% ' '.join(natbj.exclusiveGrammars.keys())
self.gotResults_showexclusive(words, fullResults)
return
grammars = natbj.loadedGrammars
gramNames = grammars.keys()
gramName = self.hasCommon(words, gramNames)
if gramName:
grammar = grammars[gramName]
if not grammar.isActive:
# off, show message:
self.offInfo(grammar)
return
if not self.hasCommon(words, 'grammar'):
grammar.showInifile()
return
try:
grammar.showInifile()
return
except AttributeError:
try:
grammar.showGrammar()
return
except AttributeError:
pass
# now show the grammar in the browser application:
if gramName:
name = [gramName]
else:
name = words[1:-1]
All=1
if len(name)>0:
All=self.hasCommon(words, 'all')
Active = self.hasCommon(words, 'active')
if Active:
All = 0
elif All:
All = 1
if len(name)>0:
Start=(string.join(name),[])
else:
Start=()
# fix state at this moment (in case of Active grammars popup)
self.BrowsePrepare(Start, All, Exclusive)
if Active:
#print 'collect and show active, non-active and non-Unimacro grammars'
activeGrammars, inactiveGrammars, switchedOffGrammars = [], [], []
otherGrammars = loadedFiles.keys() # start with all keys from natlinkmain
for g in natbj.loadedGrammars:
gram = natbj.loadedGrammars[g]
result = getattr(gram, 'isActive')
modName = gram.__module__
#print 'gram: %s, modName: %s, result: %s'% (gram, modName, result)
if result:
activeGrammars.append(g)
if modName in otherGrammars:
otherGrammars.remove(modName)
else:
print 'cannot remove from otherGrammars: %s'% modName
elif result == 0:
maySwitchOn = gram.mayBeSwitchedOn
if maySwitchOn:
inactiveGrammars.append(g)
else:
switchedOffGrammars.append(g)
#print 'gram: %s, name: %s'% (gram, modName)
if modName in otherGrammars:
otherGrammars.remove(modName)
else:
print 'cannot remove from otherGrammars: %s'% modName
if not activeGrammars:
msg = 'No Unimacro grammars are active'
elif activeGrammars == [self.name]:
msg = 'No grammars are active (apart from "%s")'% self.name
elif inactiveGrammars or switchedOffGrammars:
msg = 'Active Unimacro grammars:\n' + ', '.join(activeGrammars)
else:
msg = 'All Unimacro grammars are active:\n' + ', '.join(activeGrammars)
if inactiveGrammars:
inactive = 'Inactive (but "Switched on") grammars:\n' + ', '.join(inactiveGrammars)
msg += '\n\n' + inactive
if switchedOffGrammars:
switchedoff = '"Switched off" grammars:\n' + ', '.join(switchedOffGrammars)
msg += '\n\n' + switchedoff
if otherGrammars:
other = 'Other grammars (outside Unimacro):\n' + ', '.join(otherGrammars)
msg = msg + '\n\n' + other
if activeGrammars and activeGrammars != [self.name]:
msg = msg + '\n\n' + "Show details of active Unimacro grammars?"
if not actions.YesNo(msg, "Active grammars", icon="information", defaultToSecondButton=1):
return
else:
msg = msg + '\n\n' + 'Activate with\n\t"switch on <grammar name>" or \n\t"switch on all grammars".'
actions.Message(msg, "No active Unimacro grammars", icon="information")
return
self.BrowseShow()
def gotResults_edit(self,words,fullResults):
# special case for actions:
if self.hasCommon(words, 'actions'):
actions.editActions(comingFrom=self, name="edit actions")
return
elif self.hasCommon(words, 'spoken forms'):
actions.Message('Warning: spoken forms lists do NOT refresh automatically.\n\nA restart of NatSpeak is required after you edited the "spokenforms.ini" file')
spokenforms.editSpokenForms(comingFrom=self, name="edit spoken forms", language=self.language)
return
grammars = natbj.loadedGrammars
gramNames = grammars.keys()
gramName = self.hasCommon(words[-1:], gramNames)
if gramName:
grammar = grammars[gramName]
if self.hasCommon(words, 'grammar'):
module = grammar.__module__
filename = natqh.getModuleFilename(module)
#print 'open for edit file: %s'% filename
self.openFileDefault(filename, mode="edit", name='edit grammar %s'% gramName)
natqh.setCheckForGrammarChanges(1)
else:
# edit the inifile
try:
grammar.switchOn()
grammar.editInifile()
except AttributeError:
self.DisplayMessage('grammar "%s" has no method "editInifile"'% gramName)
return
else:
print 'no grammar name found'
def switchOff(self, **kw):
"""overload, this grammar never switches off
"""
print 'remains switched on: %s' % self
def switchOn(self, **kw):
"""overload, just switch on
"""
self.activateAll()
return 1
def offInfo(self, grammar):
"""gives a nice message that the grammar is switched off
Gives also information on how to switch on.
"""
name = grammar.getName()
try:
t = {'nld': ['Grammatica "%s" is uitgeschakeld'% name,
'',
'"Schakel in %s" om te activeren'% name]}[self.language]
title = {'nld': 'Grammatica %s'% name}[self.language]
except KeyError:
t = ['Grammar "%s" is switched off'% name,
'"Switch On Grammar %s" to activate'% name]
title = 'Grammar %s'% name
if natbj.loadedMessageGrammar:
t = '; '.join(t)
self.DisplayMessage(t)
else:
t = t.replace('; ', '\n')
actions.Message(t)
class MessageDictGrammar(natut.DictGramBase):
def __init__(self):
natut.DictGramBase.__init__(self)
def initialize(self):
print 'initializing/loading DictGrammar!!'
self.load()
natbj.RegisterMessageObject(self)
def unload(self):
natbj.UnRegisterMessageObject(self)
natut.DictGramBase.unload(self)
def gotResults(self, words):
pass
#print 'messageDictGrammar: heard dictation: %s '% words
# standard stuff Joel (adapted for possible empty gramSpec, QH, unimacro)
messageDictGrammar = MessageDictGrammar()
messageDictGrammar.initialize()
print 'messageDictGrammar initialized'
# standard stuff Joel (adapted for possible empty gramSpec, QH, unimacro)
utilGrammar = UtilGrammar()
if utilGrammar.gramSpec:
utilGrammar.initialize()
else:
print 'grammar _control has no specification for this language---------'
utilGrammar = None
def unload():
global utilGrammar, messageDictGrammar
if utilGrammar: utilGrammar.unload()
utilGrammar = None
if messageDictGrammar:
messageDictGrammar.unload()
messageDictGrammar = None
def changeCallback(type,args):
global utilGrammar
# Whenever the mic is turned off, the intercept mode is turned off.
# and any special modes, except training
if ((type == 'mic') and (args=='on')):
return # check WAS in natlinkmain...
natbj.GlobalResetExclusiveMode()
if utilGrammar:
utilGrammar.setMode(Normal)
#This could be done anywhere, but not within natlinkutilsbj
#Because that module is 'imported from'.
if utilGrammar.interceptMode:
CallAllGrammarObjects('setInterceptMode',[0])