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 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 gotResults_hyphenatephrase(self,words,fullResults): # selection or last utterance is spelled out with all caps and hyphens # Quintijn, August 15, 2009 # save clipboard, release after the action: action("CLIPSAVE") # hasCommon function for possibility of translations/synonyms without altering the code: if self.hasCommon(words[-1], "phrase"): keystroke("{Ctrl+c}") # do contents of clipboard: t = string.strip(natlink.getClipboard()) if not t: if self.language == 'nld': com = "Selecteer dat" else: com = "Select That" if natqh.getDNSVersion() >= 7: com = com.lower() action("HW %s"%com) natqh.Wait(0.5) keystroke("{Ctrl+c}") t = string.strip(natlink.getClipboard()) if not t: self.DisplayMessage("select a text first") action("CLIPRESTORE") return elif self.hasCommon(words, ('word', 'words')): counts = self.getNumbersFromSpoken(words) if counts: count = counts[0] else: count = 1 keystroke("{shift+ctrl+left %s}"% count) keystroke("{Ctrl+c}") t = string.strip(natlink.getClipboard()) if not t: self.DisplayMessage("could not select a valid text") action("CLIPRESTORE") return else: self.DisplayMessage("unexpected last word in command phrase: %s"% words[-1]) action("CLIPRESTORE") return # first paste back the selected text, and add a space if needed: L = [] # for each word in utterance join uppercased characters of word with a '-' tWords = t.split() for word in tWords: L.append('-'.join([t.upper() for t in word])) L.append(' ') keystroke(''.join(L)) action("CLIPRESTORE")
def view_selection_current_line(self): natqh.saveClipboard() keystroke('{ctrl+c}') contents = natlink.getClipboard() if len(contents) == 0: print 'no_space_by_existing selection' keystroke('{end}{shift+home}') keystroke('{ctrl+c}') contents = natlink.getClipboard() natqh.restoreClipboard() return contents
def gotResults_hyphenatephrase(self, words, fullResults): # selection or last utterance is spelled out with all caps and hyphens # Quintijn, August 15, 2009 # save clipboard, release after the action: action("CLIPSAVE") # hasCommon function for possibility of translations/synonyms without altering the code: if self.hasCommon(words[-1], "phrase"): keystroke("{Ctrl+c}") # do contents of clipboard: t = string.strip(natlink.getClipboard()) if not t: if self.language == 'nld': com = "Selecteer dat" else: com = "Select That" if natqh.getDNSVersion() >= 7: com = com.lower() action("HW %s" % com) natqh.Wait(0.5) keystroke("{Ctrl+c}") t = string.strip(natlink.getClipboard()) if not t: self.DisplayMessage("select a text first") action("CLIPRESTORE") return elif self.hasCommon(words, ('word', 'words')): counts = self.getNumbersFromSpoken(words) if counts: count = counts[0] else: count = 1 keystroke("{shift+ctrl+left %s}" % count) keystroke("{Ctrl+c}") t = string.strip(natlink.getClipboard()) if not t: self.DisplayMessage("could not select a valid text") action("CLIPRESTORE") return else: self.DisplayMessage("unexpected last word in command phrase: %s" % words[-1]) action("CLIPRESTORE") return # first paste back the selected text, and add a space if needed: L = [] # for each word in utterance join uppercased characters of word with a '-' tWords = t.split() for word in tWords: L.append('-'.join([t.upper() for t in word])) L.append(' ') keystroke(''.join(L)) action("CLIPRESTORE")
def gotResults_namephrase(self,words,fullResults): # list of words that can be combined in a double christian name # eg Jan Jaap or Jan-Marie voornamenList = ['Jan', 'Jaap', 'Peter', 'Louise', 'Anne' ] modInfo = natlink.getCurrentModule() action("CLIPSAVE") keystroke("{Ctrl+c}") # do contents of clipboard: t = string.strip(natlink.getClipboard()) if not t: modInfo = natlink.getCurrentModule() if natqh.matchModule('natspeak', 'spell', modInfo): keystroke("{ExtHome}{Shift+ExtEnd}{Ctrl+x}") natqh.Wait(0.5) t = string.strip(natlink.getClipboard()) if not t: action("CLIPRESTORE") return else: if self.language == 'nld': com = "Selecteer dat" else: com = "Select That" if natqh.getDNSVersion() >= 7: com = com.lower() action("HW %s"%com) natqh.Wait(0.5) keystroke("{Ctrl+c}") t = string.strip(natlink.getClipboard()) if not t: self.DisplayMessage("select a text first") action("CLIPRESTORE") return if self.hasCommon(words, ['naam', 'Name']): result = namelist.namelistUnimacro(t, ini=self.ini) print 'result of namelistUnimacro function: %s'% result for r in result: print 'adding part: %s'% r natqh.addWordIfNecessary(t) keystroke(r) else: # zonder naam in words, a normal phrase: print 'adding phrase %s'% t natqh.addWordIfNecessary(t) keystroke(t) action("CLIPRESTORE")
def gotResults_variable(self, words, fullResults): vartrick = self.getFromInifile(words[0], 'formatvariable', '') print 'vartrick: %s' % vartrick if vartrick: self.gotVariable = vartrick else: print 'no vartrick found, return' # c = self.getNumberFromSpoken(words[-1]) if not c: print 'vartrick %s wait for dgndictation' % vartrick return keystroke('{Shift+Ctrl+Left %s}' % c) keystroke('{ctrl+x}') print 'here comes the copy paste trick %s words' % c natqh.Wait(0.5) t = natlink.getClipboard() tList = t.split() print 'tList: %s' % tList natqh.Wait(0.5) funcName = 'format_%s' % vartrick # print 'funcName: %s'% funcNameyour try: func = getattr(self, funcName) # print 'func: %s'% func except AttributeError: print 'no formatfunction for variable trick: %s' % vartrick return result = func(tList) # keystroke(result) return
def gotResults_namephrase(self, words, fullResults): # list of words that can be combined in a double christian name # eg Jan Jaap or Jan-Marie voornamenList = ['Jan', 'Jaap', 'Peter', 'Louise', 'Anne'] modInfo = natlink.getCurrentModule() action("CLIPSAVE") keystroke("{Ctrl+c}") # do contents of clipboard: t = string.strip(natlink.getClipboard()) if not t: modInfo = natlink.getCurrentModule() if natqh.matchModule('natspeak', 'spell', modInfo): keystroke("{ExtHome}{Shift+ExtEnd}{Ctrl+x}") natqh.Wait(0.5) t = string.strip(natlink.getClipboard()) if not t: action("CLIPRESTORE") return else: if self.language == 'nld': com = "Selecteer dat" else: com = "Select That" if natqh.getDNSVersion() >= 7: com = com.lower() action("HW %s" % com) natqh.Wait(0.5) keystroke("{Ctrl+c}") t = string.strip(natlink.getClipboard()) if not t: self.DisplayMessage("select a text first") action("CLIPRESTORE") return if self.hasCommon(words, ['naam', 'Name']): result = namelist.namelistUnimacro(t, ini=self.ini) print 'result of namelistUnimacro function: %s' % result for r in result: print 'adding part: %s' % r natqh.addWordIfNecessary(t) keystroke(r) else: # zonder naam in words, a normal phrase: print 'adding phrase %s' % t natqh.addWordIfNecessary(t) keystroke(t) action("CLIPRESTORE")
def get_selection_that(self, line=0): natqh.saveClipboard() if line: action('<<selectline>><<cut>>') else: action('<<cut>>') contents = natlink.getClipboard().strip().replace('\r', '') if len(contents) == 0: if line: print '_latex, empty line' return "" action('HW select that') action('<<cut>>') contents = natlink.getClipboard().strip().replace('\r', '') if len(contents) == 0: print '_latex, empty contents, no last dicatate utterance available' natqh.restoreClipboard() return contents
def gotResults_start(self, words, fullResults): # figure out how many words if len(words) > 3: count = int(words[3]) else: count = 1 # select that many words natlink.playString('{ctrl+right}{left}') natlink.playString('{ctrl+shift+left %d}' % count) natlink.playString('{ctrl+c}') text = natlink.getClipboard() # reverse the text newText = reverse(text) natlink.playString(newText)
def gotResults_start(self, words, fullResults): # figure out how many words if len(words) > 3: count = int(words[3]) else: count = 1 # select that many words natlink.playString("{ctrl+right}{left}") natlink.playString("{ctrl+shift+left %d}" % count) natlink.playString("{ctrl+c}") text = natlink.getClipboard() # reverse the text newText = reverse(text) natlink.playString(newText)
def gotResults(self, words, fullResults): # see if something selected, leaving the clipboard intact # keystroke('{ctrl+x}') # try to cut the selection if self.between: natqh.saveClipboard() action('<<cut>>') contents = natlink.getClipboard().replace('\r','') natqh.restoreClipboard() else: contents = "" if self.here: natqh.buttonClick('left', 1) natqh.visibleWait() leftText = rightText = leftTextDict = rightTextDict = "" if contents: # strip from clipboard contents: contents, leftText, rightText = self.stripFromBothSides(contents) if self.dictated.strip(): contents, leftTextDict, rightTextDict = self.stripFromBothSides(self.dictated) elif self.dictated: # the case of only a space-bar: leftTextDict = self.dictated lSpacing = leftText + leftTextDict rSpacing = rightTextDict + rightText if lSpacing: keystroke(lSpacing) action(self.pleft) natqh.visibleWait() if contents: #print 'contents: |%s|'% repr(contents) keystroke(contents) natqh.visibleWait() action(self.pright) natqh.visibleWait() if rSpacing: keystroke(rSpacing) if not contents: # go back so you stand inside the brackets: nLeft = len(self.pright) + len(rSpacing) keystroke('{ExtLeft %s}'% nLeft)
def gotResults(self, words, fullResults): tag = self.letters.strip() ## print 'rule gotResults: %s'% tag pleft = pright = "" if not tag: return pleft = '<%s>' % tag if tag.find(' ') >= 0: endTag = ' '.split(tag)[0] else: endTag = tag pright = '</%s>' % endTag # see of something selected, leave clipboard intact natqh.saveClipboard() keystroke('{ctrl+x}') # try to cut the selection contents = natlink.getClipboard().replace('\r', '').strip() natqh.restoreClipboard() leftText = rightText = leftTextDict = rightTextDict = "" #if contents: # # strip from clipboard contents: # contents, leftText, rightText = self.stripFromBothSides(contents) #if self.dictated.strip(): # contents, leftTextDict, rightTextDict = self.stripFromBothSides(self.dictated) #elif self.dictated: # # the case of only a space-bar: # leftTextDict = self.dictated # #lSpacing = leftText + leftTextDict #rSpacing = rightTextDict + rightText # #if lSpacing: # keystroke(lSpacing) keystroke(pleft) if contents: #print 'contents: |%s|'% repr(contents) keystroke('{ctrl+v}') keystroke(pright) #if rSpacing: # keystroke(rSpacing) if not contents: # go back so you stand inside the brackets: nLeft = len(pright) keystroke('{ExtLeft %s}' % nLeft)
def gotResults_variable(self, words, fullResults): cmdVariable = self.hasCommon(words[0], 'Variable') cmdMethod = self.hasCommon(words[0], 'Method') c = self.getNumberFromSpoken(words[-1]) if c: keystroke('{Shift+Ctrl+ExtLeft %s}' % c) else: action("HW select that") natqh.Wait(0.1) keystroke('{ctrl+x}') natqh.Wait(0.1) t = natlink.getClipboard() # put spaces if they were collected on the clipboard: while t and t[0] == " ": t = t[1:] keystroke(" ") t = t.strip() if not t: print 'no variable to compress!' return # split words into a list: w = t.split() if cmdVariable or cmdMethod: # uppercase each command word: w = map(self.capit, w) T = ''.join(w) if cmdVariable: T = T[0].lower() + T[1:] # add words to vocabulary! if natqh.getDNSVersion() >= 11: backslashes = '\\\\' else: backslashes = '\\' if len(w) > 1: natqh.addWordIfNecessary(T + backslashes + t) else: natqh.addWordIfNecessary(T) keystroke(T)
def gotResults_variable(self,words,fullResults): cmdVariable = self.hasCommon(words[0], 'Variable') cmdMethod = self.hasCommon(words[0], 'Method') c = self.getNumberFromSpoken(words[-1]) if c: keystroke('{Shift+Ctrl+ExtLeft %s}' % c) else: action("HW select that") natqh.Wait(0.1) keystroke('{ctrl+x}') natqh.Wait(0.1) t = natlink.getClipboard() # put spaces if they were collected on the clipboard: while t and t[0] == " ": t = t[1:] keystroke(" ") t = t.strip() if not t: print 'no variable to compress!' return # split words into a list: w = t.split() if cmdVariable or cmdMethod: # uppercase each command word: w = map(self.capit, w) T = ''.join(w) if cmdVariable: T = T[0].lower() + T[1:] # add words to vocabulary! if natqh.getDNSVersion() >= 11: backslashes = '\\\\' else: backslashes = '\\' if len(w) > 1: natqh.addWordIfNecessary(T+backslashes+t) else: natqh.addWordIfNecessary(T) keystroke(T)
def gotResults_convertfile(self, words, fullResults): """copy file and change \n\r in \n or vice versa mark cursor cut all convert clipboard paste goto home goto cursor """ actions.putCursor() action("CLIPSAVE") action("<<selectall>><<cut>>") t = natlink.getClipboard() t = self.convertString(t, words[-1]) natqh.setClipboard(t) action("<<paste>>") action("<<topdocument>>") actions.findCursor() action("<<filesave>>")
def gotResults(self, words, fullResults): # see of something selected, leave clipboard intact natqh.saveClipboard() action('<<cut>>') # keystroke('{ctrl+x}') # try to cut the selection contents = natlink.getClipboard().replace('\r','') natqh.restoreClipboard() leftText = rightText = leftTextDict = rightTextDict = "" if contents: # strip from clipboard contents: contents, leftText, rightText = self.stripFromBothSides(contents) if self.dictated.strip(): contents, leftTextDict, rightTextDict = self.stripFromBothSides(self.dictated) elif self.dictated: # the case of only a space-bar: leftTextDict = self.dictated lSpacing = leftText + leftTextDict rSpacing = rightTextDict + rightText if lSpacing: keystroke(lSpacing) keystroke(self.pleft) if contents: #print 'contents: |%s|'% repr(contents) keystroke(contents) keystroke(self.pright) if rSpacing: keystroke(rSpacing) if not contents: # go back so you stand inside the brackets: nLeft = len(self.pright) + len(rSpacing) keystroke('{ExtLeft %s}'% nLeft)