def changeCallback(type, args): global userName, DNSuserDirectory, language, BaseModel, BaseTopic, DNSmode, changeCallbackUserFirst, shiftkey if debugCallback: print 'changeCallback, type: %s, args: %s' % (type, args) if type == 'mic' and args == 'on': if debugCallback: print 'findAndLoadFiles...' moduleInfo = natlink.getCurrentModule() findAndLoadFiles() beginCallback(moduleInfo, checkAll=1) loadModSpecific(moduleInfo) if type == 'user' and userName != args[0]: userName, DNSuserDirectory = args moduleInfo = natlink.getCurrentModule() if debugCallback: print "---------changeCallback, User changed to", userName elif not changeCallbackUserFirst: # first time, no print message, but next time do... print "\n------ user changed to: %s\n" % userName unloadEverything() ## this is not longer needed here, as we fixed the userDirectory ## changeUserDirectory() status.setUserInfo(args) language = status.getLanguage() shiftkey = status.getShiftKey(language) print 'setting shiftkey to: %s (language: %s)' % (shiftkey, language) if debugCallback: print 'usercallback, language: %s' % language if changeCallbackUserFirst: natlinkstartup.start() changeCallbackUserFirst = 0 # changed next two lines QH: findAndLoadFiles() beginCallback(moduleInfo, checkAll=1) loadModSpecific(moduleInfo) # give a warning for BestMatch V , only for Dragon 12: BaseModel, BaseTopic = status.getBaseModelBaseTopic() if DNSVersion == 12 and BaseModel.find("BestMatch V") > 0: print '\n--- WARNING: Speech Model BestMatch V is used for this User Profile' print 'The performance of many NatLink grammars is not good with this model.' print 'Please choose another User Profile with for example Speech Model BestMatch IV.' print 'See http://unimacro.antenna.nl/installation/speechmodel.html\n----' #ADDED BY BJ, possibility to finish exclusive mode by a grammar itself # the grammar should include a function like: #def changeCallback(): # if thisGrammar: # thisGrammar.cancelMode() # and the grammar should have a cancelMode function that finishes exclusive mode. # see _oops, _repeat, _control for examples changeCallbackLoadedModules(type, args)
def changeCallback(Type,args): global userName, DNSuserDirectory, language, userLanguage, userTopic, \ BaseModel, BaseTopic, DNSmode, changeCallbackUserFirst, shiftkey if debugCallback: print('changeCallback, Type: %s, args: %s'% (Type, args)) if Type == 'mic' and args == 'on': if debugCallback: print('findAndLoadFiles...') moduleInfo = natlink.getCurrentModule() findAndLoadFiles() beginCallback(moduleInfo, checkAll=1) loadModSpecific(moduleInfo) ## user: at start and at user switch: if Type == 'user' and userName != args[0]: if debugCallback: print('callback user, args: %s'% repr(args)) moduleInfo = natlink.getCurrentModule() if debugCallback: print("---------changeCallback, User changed to", args[0]) elif not changeCallbackUserFirst: # first time, no print message, but next time do... print("\n--- user changed to: %s"% args[0]) unloadEverything() ## this is not longer needed here, as we fixed the userDirectory ## changeUserDirectory() status.clearUserInfo() # if debugLoad: print('setUserInfo of natlinkstatus to: %s"'% repr(args)) status.setUserInfo(args) language = status.getLanguage() DNSuserDirectory = status.getDNSuserDirectory() userLanguage = status.getUserLanguage() userTopic = status.getUserTopic() baseTopic = status.getBaseTopic() # obsolescent, 2018, DPI15 baseModel = status.getBaseModel() # osbolescent, 2018, DPI 15 userName = status.getUserName() shiftkey = status.getShiftKey() if debugCallback: print('setting shiftkey to: %s (language: %s)'% (shiftkey, language)) if debugCallback: print('usercallback, language: %s'% language) # initialize recentEnv in natlinkcorefunctions (new 2018, 4.1uniform) natlinkstatus.AddExtendedEnvVariables() natlinkstatus.AddNatlinkEnvironmentVariables(status=status) if changeCallbackUserFirst: natlinkstartup.start() changeCallbackUserFirst = 0 # changed next two lines QH: findAndLoadFiles() beginCallback(moduleInfo, checkAll=1) loadModSpecific(moduleInfo) # # give a warning for BestMatch V , only for Dragon 12: BaseModel = status.getBaseModel() # BaseTopic = status.getBaseTopic(userTopic=userTopic) BaseTopic = status.getBaseTopic() if debugCallback: print('language: %s (%s)'% (language, type(language))) print('userLanguage: %s (%s)'% (userLanguage, type(userLanguage))) print('DNSuserDirectory: %s (%s)'% (DNSuserDirectory, type(DNSuserDirectory))) else: ## end of user info message: if language != 'enx': print('--- userLanguage: %s\n'% language) #ADDED BY BJ, possibility to finish exclusive mode by a grammar itself (around 2002) # the grammar should include a function like: #def changeCallback(): # if thisGrammar: # thisGrammar.cancelMode() # and the grammar should have a cancelMode function that finishes exclusive mode. # see _oops, _repeat, _control for examples changeCallbackLoadedModules(Type,args)
def changeCallback(Type, args): global userName, DNSuserDirectory, language, userLanguage, userTopic, \ BaseModel, BaseTopic, DNSmode, changeCallbackUserFirst, shiftkey if debugCallback: print 'changeCallback, Type: %s, args: %s' % (Type, args) if Type == 'mic' and args == 'on': if debugCallback: print 'findAndLoadFiles...' moduleInfo = natlink.getCurrentModule() findAndLoadFiles() beginCallback(moduleInfo, checkAll=1) loadModSpecific(moduleInfo) ## user: at start and at user switch: if Type == 'user' and userName != args[0]: if debugCallback: print 'callback user, args: %s' % repr(args) moduleInfo = natlink.getCurrentModule() if debugCallback: print "---------changeCallback, User changed to", args[0] elif not changeCallbackUserFirst: # first time, no print message, but next time do... print("\n--- user changed to: %s" % args[0]) unloadEverything() ## this is not longer needed here, as we fixed the userDirectory ## changeUserDirectory() status.clearUserInfo() status.setUserInfo(args) language = status.getLanguage() DNSuserDirectory = status.getDNSuserDirectory() userLanguage = status.getUserLanguage() userTopic = status.getUserTopic() baseTopic = status.getBaseTopic() # obsolescent, 2018, DPI15 baseModel = status.getBaseModel() # osbolescent, 2018, DPI 15 userName = status.getUserName() shiftkey = status.getShiftKey() if debugCallback: print 'setting shiftkey to: %s (language: %s)' % (shiftkey, language) if debugCallback: print 'usercallback, language: %s' % language # initialize recentEnv in natlinkcorefunctions (new 2018, 4.1uniform) natlinkstatus.AddExtendedEnvVariables() natlinkstatus.AddNatlinkEnvironmentVariables(status=status) if changeCallbackUserFirst: natlinkstartup.start() changeCallbackUserFirst = 0 # changed next two lines QH: findAndLoadFiles() beginCallback(moduleInfo, checkAll=1) loadModSpecific(moduleInfo) # # give a warning for BestMatch V , only for Dragon 12: BaseModel = status.getBaseModel() # BaseTopic = status.getBaseTopic(userTopic=userTopic) BaseTopic = status.getBaseTopic() if DNSVersion == 12 and BaseModel.find("BestMatch V") > 0: print '\n--- WARNING: Speech Model BestMatch V is used for this User Profile' print 'The performance of many NatLink grammars is not good with this model.' print 'Please choose another User Profile with for example Speech Model BestMatch IV.' print 'See http://unimacro.antenna.nl/installation/speechmodel.html\n----' if debugCallback: print 'language: %s (%s)' % (language, type(language)) print 'userLanguage: %s (%s)' % (userLanguage, type(userLanguage)) print 'DNSuserDirectory: %s (%s)' % (DNSuserDirectory, type(DNSuserDirectory)) else: ## end of user info message: if language != 'enx': print('--- userLanguage: %s\n' % language) #ADDED BY BJ, possibility to finish exclusive mode by a grammar itself # the grammar should include a function like: #def changeCallback(): # if thisGrammar: # thisGrammar.cancelMode() # and the grammar should have a cancelMode function that finishes exclusive mode. # see _oops, _repeat, _control for examples changeCallbackLoadedModules(Type, args) ## else: ## # possibility to do things when changeCallBack with mic on: (experiment) ## changeCallbackLoadedModulesMicOn(type, args) if debugCallback: print '=== debugCallback info ===' for name in [ 'coreDirectory', 'baseDirectory', 'DNSuserDirectory', 'userName', 'unimacroDirectory', 'userDirectory', 'WindowsVersion', 'BaseModel', 'BaseTopic', 'language', 'userLanguage', 'userTopic' ]: if not name in globals(): print 'natlinkmain, changeCallback, not in globals: %s' % name else: print 'natlinkmain changeCallback, global variable: %s: %s' % ( name, globals()[name])