def testPreTests(self): # make sure that NatSpeak is loaded into memory testForException = self.doTestForException # these function should all fail before natConnect is called testForException( natlink.NatError, "natlink.playString('')" ) testForException( natlink.NatError, "natlink.getCurrentModule()" ) testForException( natlink.NatError, "natlink.getCurrentUser()" ) testForException( natlink.NatError, "natlink.getMicState()" ) testForException( natlink.NatError, "natlink.setMicState('off')" ) testForException( natlink.NatError, "natlink.execScript('')" ) testForException( natlink.NatError, "natlink.recognitionMimic('')" ) testForException( natlink.NatError, "natlink.playEvents([])" ) testForException( natlink.NatError, "natlink.inputFromFile('test.wav')" ) testForException( natlink.NatError, "natlink.setTimerCallback(None)" ) testForException( natlink.NatError, "natlink.getTrainingMode()" ) testForException( natlink.NatError, "natlink.startTraining('calibrate')" ) testForException( natlink.NatError, "natlink.finishTraining()" ) testForException( natlink.NatError, "natlink.getAllUsers()" ) testForException( natlink.NatError, "natlink.openUser('testUser')" ) testForException( natlink.NatError, "natlink.saveUser()" ) testForException( natlink.NatError, "natlink.getUserTraining()" ) testForException( natlink.NatError, "natlink.waitForSpeech(0)" ) testForException( natlink.NatError, "natlink.GramObj().load('')" ) testForException( natlink.NatError, "natlink.DictObj()" ) # these functions should all work before natConnect is called natlink.displayText('',0) natlink.getClipboard() natlink.getCallbackDepth() natlink.getCursorPos() natlink.getScreenSize() natlink.setBeginCallback(None) natlink.setChangeCallback(None) natlink.isNatSpeakRunning()
def enable_callback(): global callback_enabled if not callback_enabled: callback_enabled = True if not Quintijn_installer: # Replace NatLink's "begin" callback function with ours: natlink.setBeginCallback(vocolaBeginCallback)
def start(self) -> None: self.logger.info('starting natlink loader') natlink.active_loader = self self._add_dirs_to_path(self.config.directories) if self.config.load_on_startup: self.trigger_load() natlink.setBeginCallback(self.on_begin_callback) natlink.setChangeCallback(self.on_change_callback)
def initialize(): # Redirect standard output and standard error to the # natlink-controlled no save file log window. redirect_std_streams() import dragonfly.log as log global log_; log_ = log director = Director() director.load_modules() natlink.setBeginCallback(director.begin_callback) natlink.setChangeCallback(director.change_callback)
def start(self) -> None: self.logger.info( f'starting natlink loader from config file:\n\t"{self.config.config_path}"' ) natlink.active_loader = self if not self.config.directories: self.logger.warning( f'Starting Natlink, but no directories to load are specified.\n\tPlease add one or more directories\n\tin config file: "{self.config.config_path}".' ) return # self.logger.debug(f'directories: {self.config.directories}') self._add_dirs_to_path(self.config.directories) if self.config.load_on_startup: # set language property: self.set_user_language() self.trigger_load() natlink.setBeginCallback(self.on_begin_callback) natlink.setChangeCallback(self.on_change_callback)
def run(): global s global g natlink.natConnect(1) #if natlink.isNatSpeakRunning() else wait try: print 'MicState:', natlink.getMicState() natlink.setBeginCallback(beginCallback) natlink.setChangeCallback(changeCallback) updateGrammarFromClient() natlink.setMicState('on') natlink.waitForSpeech(300) #data = client_socket.recv(512) #data = raw_input ( "SEND( TYPE q or Q to Quit):" ) except: #print sys.exc_info() print traceback.format_exc() finally: g.unload() natlink.natDisconnect() print 'iDisconnected.' s.close() print 'all closed'
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 disable_callback(): global callback_enabled callback_enabled = False if not Quintijn_installer: natlink.setBeginCallback(beginCallback)
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()
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()