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_quickStart(self, words, fullResults): """Bottom QuickStart item can be approximated by 56 pixels above the bottom of the screen (because this depends on the fixed size text date which doesn't scale much with screen resolution). Bottom QuickStart item = y obtained from screen dimension-getScreenSize())-56. when selecting an icon to operate on the QuickStart corner iterate from bottom left (row 1:1) """ self.windows.nullTitles.append(' '.join(words)) # screen dimensions (excluding taskbar) x, y = natlink.getScreenSize() # number of pixels between bottom of screen and bottom row of QuickStart icons row_initial = QS_ROW_INITIAL #56g # number of pixels between left side of taskbar and first column of icons col_initial = QS_COL_INITIAL #14 # separation between subsequent QuickStart rows andcolumns col_sep = row_sep = QS_COL_ROW_SEP #25 # coordinate calculated using row and column numbers ofpress QuickStart icon x, y = x + col_initial, y - row_initial x, y = x + (col_sep * (int(words[5]) - 1)), y - (row_sep * (int(words[3]) - 1)) # get the equivalent event code of the type of mouse event to perform # leftclick, rightclick, rightdouble-click event = self.kmap[str(str(words[1]) + 'click')] # play events down click and then release (for left double click # increment from left button up event which produces no action # then when incremented, performs the double-click) playEvents = iou.sanitise_movement(natlink.playEvents) # @sanitise_movement playEvents([(wm_mousemove, x, y), (event, x, y), (event + 1, x, y)])
def moveMouse(self, direction, count): xPos, yPos = natlink.getCursorPos() if direction == 'up': yPos = yPos - count elif direction == 'down': yPos = yPos + count elif direction == 'left': xPos = xPos - count elif direction == 'right': xPos = xPos + count xSize, ySize = natlink.getScreenSize() if xPos < 0: xPos = 0 if xPos >= xSize: xPos = xSize - 1 if yPos < 0: yPos = 0 if yPos >= ySize: yPos = ySize - 1 natlink.playEvents([(natlinkutils.wm_mousemove, xPos, yPos)])
def moveMouse(self,direction,count): xPos,yPos = natlink.getCursorPos() if direction == 'up': yPos = yPos - count elif direction == 'down': yPos = yPos + count elif direction == 'left': xPos = xPos - count elif direction == 'right': xPos = xPos + count xSize,ySize = natlink.getScreenSize() if xPos < 0: xPos = 0 if xPos >= xSize: xPos = xSize - 1 if yPos < 0: yPos = 0 if yPos >= ySize: yPos = ySize - 1 natlink.playEvents([(wm_mousemove,xPos,yPos)])
def onTrainSpecial(self,nID,code): Names=[] Keys=D_train.SpecialTraining.keys() for name in Keys: Names.append((name)) (x,y)=natlink.getScreenSize() Size=(int(x*0.20),int(y*0.30)) dlg = ListDialog('Select Special Training', Names, 'Grammar',size=Size,okButton='Train') if dlg.DoModal()==win32con.IDOK: Selection=dlg.Selection ToTrain=[] for k in Selection: ToTrain.extend(D_train.SpecialTraining[k]) ToTrain.sort(caseIndependentSort) RemoveDuplicatesOfSortedList(ToTrain) self.goTrain(ToTrain)
def onTrainSpecial(self, nID, code): Names = [] Keys = D_train.SpecialTraining.keys() for name in Keys: Names.append((name)) (x, y) = natlink.getScreenSize() Size = (int(x * 0.20), int(y * 0.30)) dlg = ListDialog('Select Special Training', Names, 'Grammar', size=Size, okButton='Train') if dlg.DoModal() == win32con.IDOK: Selection = dlg.Selection ToTrain = [] for k in Selection: ToTrain.extend(D_train.SpecialTraining[k]) ToTrain.sort(caseIndependentSort) RemoveDuplicatesOfSortedList(ToTrain) self.goTrain(ToTrain)
def gotResults_androidSC(self, words, fullResults): print 'Screen dimensions: ' + str(natlink.getScreenSize()) print 'Mouse cursor position: ' + str(natlink.getCursorPos()) print 'Entire recognition result: ' + str(fullResults) print 'Partial recognition result: ' + str(words)
def gotResults_windowFocus(self, words, fullResults): """ Vertical taskbar window titles are spreadstarting from 150 pixels from the taskbar. Each subsequent icon is roughly 25 pixels between.this is assumed the same between subsequent rows. If 'from bottom'modifier supplied to command string, calculate the offset from the first window title. This technique is an alternative to be able to determine a phrase that would be recognised as a window title (e.g. explicitly setting each programs window title) TODO: need to fix, inaccurate when counting from bottom. Windows not filtered properly? (Extra "Windows" which do not have physical component). EDIT: 291013 - modified to perform close""" # Detect the optional word to specify offset for variable component if words[1] == 'on': repeat_modifier_offset = 3 else: repeat_modifier_offset = 2 # screen dimensions (excluding taskbar) x, y = natlink.getScreenSize() # number of pixels between top of screen and top row of taskbar icons row_initial = TB_ROW_INITIAL #35 #75 # number of pixels between left side of taskbar and first column of icons col_initial = TB_COL_INITIAL #14 # separation between subsequent rows row_sep = TB_ROW_SEP #23 #32 # coordinate calculated, vertical offset is from top, horizontal offset # from the left edge of the taskbar (maximum horizontal value of the # screen visible size (which excludes taskbar)) calculated earlier. x, y = x + col_initial, row_initial # initial position # argument to pass to callback contains words used in voice command # (this is also a recognised top-level window?) And dictionary of # strings: handles. (Window title: window handle) # selecting index from bottom window title on taskbar # enumerate all top-level windows and send handles to callback wins={} try: # Windows dictionary returned assecond element of tuple wins=self.windows.winDiscovery(skipTitle=' '.join(words))[1] #logger.debug('enumerate Windows: %s'% wins) except: logger.error('cannot enumerate Windows') logger.error(tb.format_exc()) return # after visible taskbar application windows have been added to # dictionary (second element of wins tuple), we can calculate # relative offset from last taskbar title. total_windows = len(wins) # print('Number of taskbar applications: {0};'.format( total_windows)) # print wins.keys() # enumerate child windows of visible desktop top-level windows. # we want to use the dictionary component of wins and create a map of # parent to child Window handles. if words[4:5]: # get desired index "from bottom" (negative index) from_bottom_modifier = int(words[ repeat_modifier_offset]) # maximum number of increments is total_Windows -1 relative_offset = total_windows - from_bottom_modifier #- 1 else: # get the index of window title required, add x vertical offsets # to get right vertical coordinate(0-based) relative_offset = int(words[repeat_modifier_offset]) - 1 if 0 > relative_offset or relative_offset >= total_windows: print('Specified taskbar index out of range. ' '{0} window titles listed.'.format(total_windows)) return 1 y = y + (row_sep * relative_offset) # move mouse to 00 first then separate mouse movement from click events # this seems to avoid occasional click failure natlink.playEvents([(wm_mousemove, x, y),]) if words[0] == 'close': event = self.kmap['rightclick'] natlink.playEvents([(event, x, y), (event + 1, x, y)]) natlink.playString('{up}{enter}') else: event = self.kmap['leftclick'] natlink.playEvents([(event, x, y), (event + 1, x, y)])
def gotResults_windowFocus(self, words, fullResults): """ Vertical taskbar window titles are spreadstarting from 150 pixels from the taskbar. Each subsequent icon is roughly 25 pixels between.this is assumed the same between subsequent rows. If 'from bottom'modifier supplied to command string, calculate the offset from the first window title. This technique is an alternative to be able to determine a phrase that would be recognised as a window title (e.g. explicitly setting each programs window title) TODO: need to fix, inaccurate when counting from bottom. Windows not filtered properly? (Extra "Windows" which do not have physical component). EDIT: 291013 - modified to perform close""" # Detect the optional word to specify offset for variable component if words[1] == 'on': repeat_modifier_offset = 3 else: repeat_modifier_offset = 2 # screen dimensions (excluding taskbar) x, y = natlink.getScreenSize() # number of pixels between top of screen and top row of taskbar icons row_initial = TB_ROW_INITIAL #35 #75 # number of pixels between left side of taskbar and first column of icons col_initial = TB_COL_INITIAL #14 # separation between subsequent rows row_sep = TB_ROW_SEP #23 #32 # coordinate calculated, vertical offset is from top, horizontal offset # from the left edge of the taskbar (maximum horizontal value of the # screen visible size (which excludes taskbar)) calculated earlier. x, y = x + col_initial, row_initial # initial position # argument to pass to callback contains words used in voice command # (this is also a recognised top-level window?) And dictionary of # strings: handles. (Window title: window handle) # selecting index from bottom window title on taskbar # enumerate all top-level windows and send handles to callback wins = {} try: # Windows dictionary returned assecond element of tuple wins = self.windows.winDiscovery(skipTitle=' '.join(words))[1] #logger.debug('enumerate Windows: %s'% wins) except: logger.error('cannot enumerate Windows') logger.error(tb.format_exc()) return # after visible taskbar application windows have been added to # dictionary (second element of wins tuple), we can calculate # relative offset from last taskbar title. total_windows = len(wins) # print('Number of taskbar applications: {0};'.format( total_windows)) # print wins.keys() # enumerate child windows of visible desktop top-level windows. # we want to use the dictionary component of wins and create a map of # parent to child Window handles. if words[4:5]: # get desired index "from bottom" (negative index) from_bottom_modifier = int(words[repeat_modifier_offset]) # maximum number of increments is total_Windows -1 relative_offset = total_windows - from_bottom_modifier #- 1 else: # get the index of window title required, add x vertical offsets # to get right vertical coordinate(0-based) relative_offset = int(words[repeat_modifier_offset]) - 1 if 0 > relative_offset or relative_offset >= total_windows: print( 'Specified taskbar index out of range. ' '{0} window titles listed.'.format(total_windows)) return 1 y = y + (row_sep * relative_offset) # move mouse to 00 first then separate mouse movement from click events # this seems to avoid occasional click failure natlink.playEvents([ (wm_mousemove, x, y), ]) if words[0] == 'close': event = self.kmap['rightclick'] natlink.playEvents([(event, x, y), (event + 1, x, y)]) natlink.playString('{up}{enter}') else: event = self.kmap['leftclick'] natlink.playEvents([(event, x, y), (event + 1, x, y)])