def tttest_Bringup_voicecode_user_switching(self): user, dummy = natlink.getCurrentUser() if user == 'VoiceCode': mes = ['active user is: %s'% user, '', 'Cannot test voicecode_user_switching to VoiceCode again', '', 'Please start test with another user being active.'] actions.Message(mes) self.fail("start test with a user profile NOT being VoiceCode") preserveApps = ['emacs'] #ther adepps are killed after the test apps = ['voicecode', 'notepad'] if not self.doTestBringupApplications(apps, preserveApps, prompt="test_Bringup_voicecode_user_switching"): print('test_Bringup_voicecode_user_switching skipped halfway') return newUser, dummy = natlink.getCurrentUser() self.assert_equal('VoiceCode', newUser, "user name should be switched to 'VoiceCode'") if user == newUser: mes = ['cannot test voicecode user coming from another user', 'start test from another user as "VoiceCode"'] actions.Message(mes) natlink.openUser(user) newUser, dummy = natlink.getCurrentUser() self.assert_equal(user, newUser, "user name should be switched to '%s'\n" "in order to be able to test the user switching part of this test"% user) self.doTestBringupApplications(apps, preserveApps, prompt=0) newUser, dummy = natlink.getCurrentUser() self.assert_equal('VoiceCode', newUser, "user name should be switched to 'VoiceCode', also the second time of testing")
def setUp(self): if self.first: actions.debugActions(1) self.first = 0 else: actions.debugActions(1, openMode='a') self.startUser = natlink.getCurrentUser()[0]
def setUp(self): if not natlink.isNatSpeakRunning(): raise TestError, 'NatSpeak is not currently running' if not self.connected: self.connect() self.user = natlink.getCurrentUser()[0] self.setMicState = "off" self.connected = 1
def gotResultsObject(self,recogType,resObj): global logFile currentUser=natlink.getCurrentUser()[0] if recogType == 'reject': message = "*REJECT*" else: message = resObj.getWords(0) currentModule=natlink.getCurrentModule() windowTitle =string.replace(currentModule[1],"\t"," ") message ="%s\t%s\t%s"% (currentModule[0],windowTitle,message) logMessageToFile (logFile, "%s\t%s" % (currentUser, message))
def gotResultsObject(self, recogType, resObj): global logFile currentUser = natlink.getCurrentUser()[0] if recogType == 'reject': message = "*REJECT*" else: message = resObj.getWords(0) currentModule = natlink.getCurrentModule() windowTitle = string.replace(currentModule[1], "\t", " ") message = "%s\t%s\t%s" % (currentModule[0], windowTitle, message) logMessageToFile(logFile, "%s\t%s" % (currentUser, message))
def createNewUser(userName,baseModel,baseTopic): if natlink.getCurrentUser()[0] == userName: print 'Training existing user:'******'Creating user:'******' using baseModel:',baseModel else: print ' using baseModel: (default)' if baseTopic: print ' using baseTopic:',baseTopic else: print ' using baseTopic: (default)' natlink.createUser(userName,baseModel,baseTopic) natlink.openUser(userName) if natlink.getUserTraining(): print 'Error: user is already at least partially trained.' raise TrainingError,'user is trained'
def createNewUser(userName, baseModel, baseTopic): if natlink.getCurrentUser()[0] == userName: print 'Training existing user:'******'Creating user:'******' using baseModel:', baseModel else: print ' using baseModel: (default)' if baseTopic: print ' using baseTopic:', baseTopic else: print ' using baseTopic: (default)' natlink.createUser(userName, baseModel, baseTopic) natlink.openUser(userName) if natlink.getUserTraining(): print 'Error: user is already at least partially trained.' raise TrainingError, 'user is trained'
def set_user_language(self, args: Any = None): """can be called from other module to explicitly set the user language to 'enx', 'nld', etc """ if not (args and len(args) == 2): try: args = natlink.getCurrentUser() except natlink.NatError: # when Dragon not running, for testing: args = () if args: self.user, self.profile = args self.language = self.get_user_language(self.profile) self.logger.debug( f'set_user_language, user: "******", profile: "{self.profile}", language: "{self.language}"' ) else: self.user, self.profile = '', '' self.logger.warning( 'set_user_language, cannot get input for get_user_language, set to "enx",\n\tprobably Dragon is not running' ) self.language = 'enx'
def start_natlink(doNatConnect=None): """do the startup of the python macros system """ global userDirectory, DNSVersion, baseDirectory, WindowsVersion, unimacroDirectory try: # compute the directory where this module came from if not natlink.isNatSpeakRunning(): print 'start Dragon first, the rerun the script natlinkmain...' time.sleep(10) return if doNatConnect: natlink.natConnect( 1) # 0 or 1, should not be needed when automatic startup #print "\n".join(["%s=%s" % (k,v) for k, v in sys.modules ]) #print "\n".join(sys.modules.keys()) for modname in ['natlink', 'natlinkmain']: try: coreDirectory = os.path.split( sys.modules[modname].__dict__['__file__'])[0] except KeyError: pass else: break if debugLoad: print "NatLink pyd dir " + coreDirectory baseDirectory = os.path.normpath( os.path.abspath(os.path.join(coreDirectory, ".."))) if not baseDirectory in sys.path: sys.path.insert(0, baseDirectory) if debugLoad: print 'insert baseDirectory: %s to sys.path!' % baseDirectory if debugLoad: print "NatLink base dir" + baseDirectory # get the current user information from the NatLink module userDirectory = status.getUserDirectory() if userDirectory: if not userDirectory in sys.path: sys.path.insert(0, userDirectory) if debugLoad: print 'insert userDirectory: %s to sys.path!' % userDirectory else: if debugLoad: print 'userDirectory: %s' % userDirectory else: if debugLoad: print 'no userDirectory' # for unimacro, in order to reach unimacro files to be imported: unimacroDirectory = status.getUnimacroDirectory() if unimacroDirectory: if status.UnimacroIsEnabled(): if not unimacroDirectory in sys.path: sys.path.insert(0, unimacroDirectory) if debugLoad: print 'insert unimacroDirectory: %s to sys.path!' % unimacroDirectory else: if debugLoad: print 'unimacroDirectory: %s' % unimacroDirectory else: if debugLoad: print 'Unimacro not enabled' else: if debugLoad: print 'no unimacroDirectory' # setting searchImportDirs: setSearchImportDirs() # get invariant variables: DNSVersion = status.getDNSVersion() WindowsVersion = status.getWindowsVersion() # init things identical to when user changes: # [MDL: this calls findAndLoadFiles()!] changeCallback('user', natlink.getCurrentUser()) ## BaseModel, BaseTopic = status.getBaseModelBaseTopic() # load all global files in user directory and current directory findAndLoadFiles() # initialize our callbacks natlink.setBeginCallback(beginCallback) natlink.setChangeCallback(changeCallback) print 'natlinkmain started from %s:\n NatLink version: %s\n DNS version: %s\n Python version: %s\n Windows Version: %s\n'% \ (status.getCoreDirectory(), status.getInstallVersion(), DNSVersion, status.getPythonVersion(), WindowsVersion) except: sys.stderr.write('Error initializing natlinkmain\n') traceback.print_exc() if debugLoad: print "userDirectory: %s\nbaseDirectory: %s\nunimacroDirectory: %s\n" % ( userDirectory, baseDirectory, unimacroDirectory) print "natlinkmain imported-----------------------------------" elif natlinkmainPrintsAtEnd: if status.UnimacroIsEnabled(): print 'Unimacro enabled, user directory: %s' % status.getUnimacroUserDirectory( ) if status.VocolaIsEnabled(): print 'Vocola enabled, user directory: %s' % status.getVocolaUserDirectory( ) if userDirectory: print "User defined macro's (UserDirectory) enabled: %s" % userDirectory print '-' * 40 #else: # natlinkLogMessage('natlinkmain started (imported)\n') if status.hadWarning: print '=' * 30 print status.getWarningText() print '=' * 30 status.emptyWarning()
def tearDown(self): endUser = natlink.getCurrentUser()[0] if self.startUser != endUser: print 'reopen user: %s' % self.startUser natlink.openUser(self.startUser) actions.debugActions(0)
'no spacing': (natqh.wf_NoSpaceFollowingThisWord | natqh.wf_NoSpacePreceedingThisWord | natqh.wf_TurnOffSpacingBetweenWords | natqh.wf_DoNotApplyFormattingToThisWord ), # normal words: 'normal words': ( natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing ), # extra space(do one space): 'extra space': ( natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing | natqh.wf_AddAnExtraSpaceFollowingThisWord ), } version = natqh.getDNSVersion() user = natlink.getCurrentUser()[0] wordsFolder = os.path.split( sys.modules[__name__].__dict__['__file__'])[0] + \ '\\' + language + "_words" + \ '\\' + user utilsqh.createFolderIfNotExistent(wordsFolder) files = [os.path.splitext(f)[0] for f in os.listdir(wordsFolder)] ## print '_general, files in wordsFolder %s: %s'% (wordsFolder, files) if language == 'enx': nameList = {'Q. H.': 'QH', 'R. A.': 'RA', 'underscore': '', } elif language == 'nld': nameList = {'QH': 'QH',
def start_natlink(doNatConnect=None): """do the startup of the python macros system Better not use doNatConnect, but ensure this is done before calling, and with a finally: natlink.natDisconnect() call """ global loadedFiles print('--') nGrammarsLoaded = len(loadedFiles) if nGrammarsLoaded: if debugLoad: print("unload everything, %s grammars loaded"% nGrammarsLoaded) unloadEverything() else: if debugLoad: print("no grammars loaded yet") if natlinkmainPrintsAtStart: print('-- natlinkmain starting...') if not natlink.isNatSpeakRunning(): print('start Dragon first, then rerun the script natlinkmain...') time.sleep(10) return if not doNatConnect is None: if doNatConnect: print('start_natlink, do natConnect with option 1, threading') natlink.natConnect(1) # 0 or 1, should not be needed when automatic startup else: print('start_natlink, do natConnect with option 0, no threading') natlink.natConnect(0) # 0 or 1, should not be needed when automatic startup print("----natlink.natConnect succeeded") # for modname in ['natlink', 'natlinkmain']: if not baseDirectory in sys.path: sys.path.insert(0,baseDirectory) if debugLoad: print('insert baseDirectory: %s to sys.path!'% baseDirectory) if debugLoad: print(("Natlink base dir" + baseDirectory)) # get the current user information from the Natlink module if userDirectory and os.path.isdir(userDirectory): if not userDirectory in sys.path: sys.path.insert(0,userDirectory) if debugLoad: print('insert userDirectory: %s to sys.path!'% userDirectory) else: if debugLoad: print('userDirectory: %s'% userDirectory) else: if debugLoad: print('no userDirectory') # for unimacro, in order to reach unimacro files to be imported: if unimacroDirectory and os.path.isdir(unimacroDirectory): if status.UnimacroIsEnabled(): if not unimacroDirectory in sys.path: sys.path.insert(0,unimacroDirectory) if debugLoad: print('insert unimacroDirectory: %s to sys.path!'% unimacroDirectory) else: if debugLoad: print('unimacroDirectory: %s'% unimacroDirectory) else: if debugLoad: print('Unimacro not enabled') else: if debugLoad: print('no unimacroDirectory') # setting searchImportDirs, also insert at front of sys.path if not in the list yet. setSearchImportDirs() ## BaseModel, BaseTopic = status.getBaseModelBaseTopic() # load all global files in user directory and current directory # findAndLoadFiles() # initialize our callbacks natlink.setBeginCallback(beginCallback) natlink.setChangeCallback(changeCallback) # init things identical to when user changes: changeCallback('user', natlink.getCurrentUser()) print(('natlinkmain started from %s:\n Natlink version: %s\n DNS version: %s\n Python version: %s\n Windows Version: %s'% \ (status.getCoreDirectory(), status.getInstallVersion(), DNSVersion, status.getPythonVersion(), windowsVersion, ))) if debugLoad: print("userDirectory: %s\nbaseDirectory: %s\nunimacroDirectory: %s\n"% (userDirectory, baseDirectory, unimacroDirectory)) print("loadedFiles: %s"% loadedFiles) print("natlinkmain imported-----------------------------------") elif natlinkmainPrintsAtEnd: if status.UnimacroIsEnabled(): print('Unimacro enabled, UnimacroUserDirectory:\n %s'% status.getUnimacroUserDirectory()) if status.VocolaIsEnabled(): print('Vocola enabled, VocolaUserDirectory:\n %s'% status.getVocolaUserDirectory()) if userDirectory: print("User defined macro's enabled, UserDirectory:\n %s"% userDirectory) print('-'*40) #else: # natlinkLogMessage('natlinkmain started (imported)\n') if status.hadWarning: print('='*30) print(status.getWarningText()) print('='*30) status.emptyWarning()
FORMATS = { # for letters (do nothing): 'no spacing': (natqh.wf_NoSpaceFollowingThisWord | natqh.wf_NoSpacePreceedingThisWord | natqh.wf_TurnOffSpacingBetweenWords | natqh.wf_DoNotApplyFormattingToThisWord), # normal words: 'normal words': (natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing), # extra space(do one space): 'extra space': (natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing | natqh.wf_AddAnExtraSpaceFollowingThisWord), } version = natqh.getDNSVersion() user = natlink.getCurrentUser()[0] wordsFolder = os.path.split( sys.modules[__name__].__dict__['__file__'])[0] + \ '\\' + language + "_words" + \ '\\' + user utilsqh.createFolderIfNotExistent(wordsFolder) files = [os.path.splitext(f)[0] for f in os.listdir(wordsFolder)] ## print '_general, files in wordsFolder %s: %s'% (wordsFolder, files) if language == 'enx': nameList = { 'Q. H.': 'QH', 'R. A.': 'RA', 'underscore': '', } elif language == 'nld':
def start_natlink(doNatConnect=None): """do the startup of the python macros system """ global userDirectory, DNSVersion, baseDirectory, WindowsVersion try: # compute the directory where this module came from if not natlink.isNatSpeakRunning(): print 'start Dragon first, the rerun the script natlinkmain...' time.sleep(10) return if doNatConnect: natlink.natConnect(1) # 0 or 1, should not be needed when automatic startup #print "\n".join(["%s=%s" % (k,v) for k, v in sys.modules ]) #print "\n".join(sys.modules.keys()) for modname in ['natlink', 'natlinkmain']: try: coreDirectory = os.path.split( sys.modules[modname].__dict__['__file__'])[0] except KeyError: pass else: break if debugLoad: print "NatLink pyd dir " + coreDirectory baseDirectory = os.path.normpath(os.path.abspath(os.path.join(coreDirectory,".."))) if debugLoad: print "NatLink base dir" + baseDirectory # get the current user information from the NatLink module userDirectory = status.getUserDirectory() # for unimacro, in order to reach unimacro files to be imported: if userDirectory and os.path.isdir(userDirectory) and not userDirectory in sys.path: if debugLoad: print 'insert userDirectory: %s to sys.path!'% userDirectory sys.path.insert(0,userDirectory) # setting searchImportDirs: setSearchImportDirs() # get invariant variables: DNSVersion = status.getDNSVersion() WindowsVersion = status.getWindowsVersion() # init things identical to when user changes: changeCallback('user', natlink.getCurrentUser()) ## BaseModel, BaseTopic = status.getBaseModelBaseTopic() print 'Starting natlinkmain from %s:\n NatLink version: %s\n DNS version: %s\n Python version: %s\n Windows Version: %s\n'% \ (status.getCoreDirectory(), status.getInstallVersion(), DNSVersion, status.getPythonVersion(), WindowsVersion) # load all global files in user directory and current directory findAndLoadFiles() # initialize our callbacks natlink.setBeginCallback(beginCallback) natlink.setChangeCallback(changeCallback) except: sys.stderr.write( 'Error initializing natlinkmain\n' ) traceback.print_exc() if debugLoad: print "userDirectory: %s\nbaseDirectory: %s"% (userDirectory, baseDirectory) print "natlinkmain imported-----------------------------------" elif natlinkmainPrintsAtEnd: print 'natlinkmain started (imported)\n' else: natlinkLogMessage('natlinkmain started (imported)\n') if status.hadWarning: print '='*30 print status.getWarningText() print '='*30 status.emptyWarning()