def playString(keys, hooks=None): """insert {shift} as workaround for losing keystrokes does not work. revert to normal playString not if hooks (like systemkeys) are used... """ if not keys: return #elif hooks not in (None, 0x100) or keys.startswith("{shift}"): # # special hooks or startig with {shift} already... # pass #elif keys.startswith("{"): # print 'playString, do shift + pause' # natlink.playString("{shift}") # time.sleep(1) #else: # print 'playString, insert shift before keys' # keys = "{shift}" + keys if hooks is None: print 'keystrokes no hooks: "%s"'% keys natlink.playString(keys, 0x100) else: natlink.playString(keys, hooks)
def gotResults_kbMacro(self, words, fullResults): lenWords = len(words) # global macros if lenWords == 1: macro=self.kbMacros[words[0]] natlink.playString(macro.string,macro.flags) # terminal application-specific (when ms OS running Dragon is not aware # of application context) elif lenWords > 1: macro=self.kbMacros[' '.join(words)] # process application specific macro newmacro = macro.string newflags = macro.flags if words[0] == 'screen': # screen command prefix is c-a, 0x04 modifier newflags = 0x04 newmacro = ''.join(['a',str(newmacro)]) elif words[0] == 'vim': # vim command mode entered with 'esc 'key, command line # commands entered with : prefix and require 'enter' to # complete. No modifier on initial command character. # 0xff signifies partial command, don't append "enter" newflags = 0x00 if macro.string.startswith(':') and macro.flags != 0xff: newmacro=''.join([str(newmacro),'{enter}']) newmacro = ''.join(['{esc}',str(newmacro)]) #logger.debug('vim resultant macro: %s'% newmacro) natlink.playString(newmacro,newflags)
def gotResults_setFont(self, words, fullResults): keywords = { 'bold': "output = '{Alt+y}Bold'", 'italic': "output = '{Alt+y}italic'", 'regular': "output = '{Alt+y}Regular'", 'bold italic': "output = '{Alt+y}Bold italic'", 'plain': "output = '{Alt+y}Regular'", 'underline': "output = '{Alt+u}'", 'strikeout': "output = '{Alt+k}'" } if self.sawResults: return None self.sawResults = 1 rulesFound = convertResults(fullResults) # this brings up the font format dialog natlink.playString('{Alt+o}f') if rulesFound.has_key('fontFace'): # set the font face if found natlink.playString('{Alt+f}' + rulesFound['fontFace'][0]) if rulesFound.has_key('fontStyle'): # handle the font style if found exec keywords[rulesFound['fontStyle'][0]] natlink.playString(output) if rulesFound.has_key('fontSize'): # set the font size if found natlink.playString('{Alt+s}' + rulesFound['fontSize'][0]) # close the font format dialog natlink.playString('{Enter}')
def log(self, t, doPlaystring=None): # displayTest seems not to work: natlink.displayText(t, 0) if doPlaystring: natlink.playString(t+'\n') # do the global log function: log(t)
def gotResults_iphoneselect(self, words, fullResults): """ Gives coordinates of an entry in a list on the iPhone. Receives the number of entries in the list (actually how many entries, given the size on the screen, would fit into the screen dimensions), the offset index of the first usable entry from top (how many entries Could fit above the first usable entry, give the index of the first usable entry) and the index of the desired entry. TODO: click on contact buttons on the right of entries """ cmdwords= words[:3] self.gotResults_iphonetap(cmdwords, fullResults) # now target window should be in focus and ready # static variables: appName = "iphoneWin"; num_entries = 14; offset_index = 3; select_int = 1 select_int=(int(words[3])) # can use global variables populated by iphonetap hwin = self.windows.appDict[appName].winHandle if hwin: x,y,x1,y1 = wg.GetWindowRect(hwin) logging.debug('window Rect: %d,%d,%d,%d'% (x,y,x1,y1)) if len(words) > 4 and str(words[4]) == 'details': # selectable blue Arrow on the right side of the contact x_ofs = x + 17*(x1 - x)/18 else: # otherwise click in the centre (horizontal) x_ofs = x + (x1 - x)/2 y_inc = (y1 - y)/num_entries y_ofs = y + y_inc/2 + (select_int + offset_index - 1)*y_inc logging.debug('horizontal: %d, vertical: %d, vertical increments: %d'% (x_ofs,y_ofs,y_inc)) if (select_int + offset_index - num_entries - 1) <= 0: # if entering search text,hide keypad natlink.playString('{enter}',0) self.click('leftclick',x=x_ofs,y=y_ofs,appName=appName) return
def log(self, t, doPlaystring=None): # displayTest seems not to work: natlink.displayText(t, 0) if doPlaystring: natlink.playString(t + '\n') # do the global log function: log(t)
def playString(keys, hooks=None): """do smarter and faster playString than natlink.playString If useMarkSendInput is set to 1 (True) (top of this file): the SendInput module of Mark Lillibridge is used. Disadvantage: does not work in elevated windows. This behaviour can be circumvented by adding a hook in the call, or by using SendDragonKeys, SendSystemKeys or SSK (Unimacro). If useMarkSendInput is set to 0 (False), or a hook is added (0x100 for normal behaviour, 0x200 for systemkeys behaviour) then natlink.playString is used, but a {shift} in front of the keystrokes is inserted, in order to prevent doubling or losing keystrokes. (if default behaviour is wanted, you can call natlink.playString directly) """ if not keys: return keys = utilsqh.convertToBinary(keys) if hooks is None and useMarkSendInput: SendInput.send_input( ExtendedSendDragonKeys.senddragonkeys_to_events(keys)) else: if hooks not in (None, 0x100): natlink.playString(keys, hooks) else: shiftkey = natlinkmain.shiftkey natlink.playString(shiftkey + keys)
def gotResults_kbMacro(self, words, fullResults): lenWords = len(words) # global macros if lenWords == 1: macro = self.kbMacros[words[0]] natlink.playString(macro.string, macro.flags) # terminal application-specific (when ms OS running Dragon is not aware # of application context) elif lenWords > 1: macro = self.kbMacros[' '.join(words)] # process application specific macro newmacro = macro.string newflags = macro.flags if words[0] == 'screen': # screen command prefix is c-a, 0x04 modifier newflags = 0x04 newmacro = ''.join(['a', str(newmacro)]) elif words[0] == 'vim': # vim command mode entered with 'esc 'key, command line # commands entered with : prefix and require 'enter' to # complete. No modifier on initial command character. # 0xff signifies partial command, don't append "enter" newflags = 0x00 if macro.string.startswith(':') and macro.flags != 0xff: newmacro = ''.join([str(newmacro), '{enter}']) newmacro = ''.join(['{esc}', str(newmacro)]) #logger.debug('vim resultant macro: %s'% newmacro) natlink.playString(newmacro, newflags)
def playString(keys, hooks=None): """insert {shift} as workaround for losing keystrokes does not work. revert to normal playString not if hooks (like systemkeys) are used... """ if not keys: return #elif hooks not in (None, 0x100) or keys.startswith("{shift}"): # # special hooks or startig with {shift} already... # pass #elif keys.startswith("{"): # print 'playString, do shift + pause' # natlink.playString("{shift}") # time.sleep(1) #else: # print 'playString, insert shift before keys' # keys = "{shift}" + keys if hooks is None: print 'keystrokes no hooks: "%s"' % keys natlink.playString(keys, 0x100) else: natlink.playString(keys, hooks)
def gotResults_secondRule(self,words,fullResults): colors = words[3:] if len(colors) == 1: color = colors[0] natlink.playString('The color is "%s"{enter}'% color) else: natlink.playString('The color are "%s"{enter}'% ', '.join(colors))
def gotResults_setFont(self,words,fullResults): keywords = { 'bold': "output = '{Alt+y}Bold'", 'italic': "output = '{Alt+y}italic'", 'regular': "output = '{Alt+y}Regular'", 'bold italic': "output = '{Alt+y}Bold italic'", 'plain': "output = '{Alt+y}Regular'", 'underline': "output = '{Alt+u}'", 'strikeout': "output = '{Alt+k}'" } if self.sawResults: return None self.sawResults = 1 rulesFound = convertResults(fullResults) # this brings up the font format dialog natlink.playString('{Alt+o}f') if rulesFound.has_key('fontFace'): # set the font face if found natlink.playString('{Alt+f}' + rulesFound['fontFace'][0]) if rulesFound.has_key('fontStyle'): # handle the font style if found exec keywords[ rulesFound['fontStyle'][0] ] natlink.playString(output) if rulesFound.has_key('fontSize'): # set the font size if found natlink.playString('{Alt+s}' + rulesFound['fontSize'][0]) # close the font format dialog natlink.playString('{Enter}')
def do_flush(functional_context, buffer): if functional_context: raise VocolaRuntimeError( 'attempt to call Unimacro, Dragon, or a Vocola extension ' + 'procedure in a functional context!') if buffer != '': natlink.playString(convert_keys(buffer)) return ''
def gotResults_button(self,words,fullResults): action = { 'press me':'{alt+p}', 'speech works':'{alt+s}', 'do nothing':'{alt+d}', 'click this button':'{alt+c}', 'turn mic off':'{alt+t}', 'close window':'{alt+w}' } natlink.playString(action[string.join(words)])
def gotResults_dgndictation(self, words, fullResults): """format the words with nsformat and print. With more commands in succession, the lastState is used to fix spacing and capitalization of words. """ formatted_words, self.lastState = nsformat.formatWords( words, self.lastState) # text = ' '.join(words) self.lenOfWords = len(formatted_words) natlink.playString(formatted_words)
def gotResults_copy(self , words,fullResults): # print words keys = { "copy" : "{ctrl+c}", "move" : "{ctrl+x}", } action = keys [words [0]] natlink.playString(action) self.openFolder(words [2]) natlink.playString("{ctrl+v}")
def gotResults_copy(self, words, fullResults): # print words keys = { "copy": "{ctrl+c}", "move": "{ctrl+x}", } action = keys[words[0]] natlink.playString(action) self.openFolder(words[2]) natlink.playString("{ctrl+v}")
def gotResults_dgnletters(self, words, fullResults): """the formatting is also done via nsformat but... the "commented out" trick works in practice equally well. """ print(f'words for dgnletters: {words}') # words = map(lambda x: x[:1], words) # text = ''.join(words) letters = nsformat.formatLetters(words) self.lenOfWords = len(letters) natlink.playString(letters)
def playString(keys, hooks=None): """insert {shift} as workaround for losing keystrokes only if no special hooks are asked for: insert a {shift} in front of the keystrokes. (if default behaviour is wanted, call natlink.playString directly) """ if not keys: return if hooks not in (None, 0x100): natlink.playString(keys, hooks) else: shiftkey = natlinkmain.shiftkey natlink.playString(shiftkey + keys)
def gotResults_verb(self,words,fullResults): keywords = { 'cut': "output = '{Ctrl+x}'", 'copy': "output = '{Ctrl+c}'", 'bold': "output = '{Ctrl+b}'", 'italicize': "output = '{Ctrl+i}'", 'underline': "output = '{Ctrl+u}'", 'center': "output = '{Ctrl+e}'", 'left align': "output = '{Ctrl+l}'", 'right align': "output = '{Ctrl+r}'", 'delete': "output = '{Del}'", 'restore': "output = '{Alt+o}f{Alt+y}Regular{Enter}'" } if keywords.has_key(words[0]): exec keywords[words[0]] natlink.playString(output)
def onTimer(self): if self.lastClock: diff = int( (time.time() - self.lastClock) * 1000 ) self.lastClock = time.time() if self.curMode == 1: moduleInfo = natlink.getCurrentModule() if natlink.getMicState() == 'on' and moduleInfo == self.moduleInfo: self.setTrayIcon(1) # Note: it is often during a playString operation that the # "stop moving" command occurs natlink.playString('{'+self.curDirection+'}') else: self.cancelMode() elif self.curMode == 2: self.moveMouse(self.curDirection,self.curPixels)
def onTimer(self): if self.lastClock: diff = int( (time.clock() - self.lastClock) * 1000 ) self.lastClock = time.clock() if self.curMode == 1: moduleInfo = natlink.getCurrentModule() if natlink.getMicState() == 'on' and moduleInfo == self.moduleInfo: self.setTrayIcon(1) # Note: it is often during a playString operation that the # "stop moving" command occurs natlink.playString('{'+self.curDirection+'}') else: self.cancelMode() elif self.curMode == 2: self.moveMouse(self.curDirection,self.curPixels)
def call_Dragon(function_name, argument_types, arguments): global dragon_prefix def quoteAsVisualBasicString(argument): q = argument q = string.replace(q, '"', '""') q = string.replace(q, "\n", '" + chr$(10) + "') q = string.replace(q, "\r", '" + chr$(13) + "') return '"' + q + '"' script = "" for argument in arguments: argument_type = argument_types[0] argument_types = argument_types[1:] if argument_type == 'i': argument = str(to_long(argument)) elif argument_type == 's': if function_name == "SendDragonKeys" or function_name == "SendKeys" \ or function_name == "SendSystemKeys": argument = convert_keys(argument) argument = quoteAsVisualBasicString(str(argument)) else: # there is a vcl2py.pl bug if this happens: raise VocolaRuntimeError("Vocola compiler error: unknown data type " + " specifier '" + argument_type + "' supplied for a Dragon procedure argument") if script != '': script += ',' script += ' ' + argument script = dragon_prefix + function_name + script dragon_prefix = "" #print '[' + script + ']' try: if function_name == "SendDragonKeys": natlink.playString(convert_keys(arguments[0])) elif function_name == "ShiftKey": dragon_prefix = script + chr(10) else: natlink.execScript(script) except Exception, e: m = "when Vocola called Dragon to execute:\n" \ + ' ' + script + '\n' \ + ' Dragon reported the following error:\n' \ + ' ' + type(e).__name__ + ": " + str(e) raise VocolaRuntimeError, m
def testCopyClipboardWord(self): """test the copying of the clipboard word documents """ ## open the txtFiles (are closed in tearDown) for docxFile in docxFiles: hndle = self.openTestFile(os.path.join(thisDir, 'test_clipboardfiles', docxFile), waitingTime=0.5) if hndle: self.allWindows[hndle] = docxFile else: print 'could not open test file %s' % docxFile cb = natlinkclipboard.Clipboard(save_clear=True) ## empty file: expTextPrev = "" nCycles = 2 # make it 10 or 50 to do a longer test for i in range(nCycles): for hndle, docxFile in self.allWindows.iteritems(): print 'trying %s (%s) (cycle %s)' % (hndle, docxFile, i + 1) natlinkutilsqh.SetForegroundWindow(hndle) time.sleep( 0.2 ) # word needs a little time before keystrokes are accepted... natlink.playString( "{ctrl+home}{shift+end}{shift+down 3}{ctrl+c}") # cb.copy_from_system(waiting_interval=0.005) # natlinkutilsqh.SetForegroundWindow(self.thisHndle) gotall = cb.get_text(waiting_interval=0.05) lengotall = len(gotall) got = gotall expText = u"A small word document.\n\nWith only a few lines\n\n" if not got: print 'no text, file: %s' % docxFile self.assert_equal( expText, got, "testing docx file %s, result not as expected" % docxFile) # also test the class method (direct call) got = natlinkclipboard.Clipboard.get_system_text() self.assert_equal( expText, got, "testing docx file %s, with class method, result not as expected" % docxFile) pass
def call_Dragon(function_name, argument_types, arguments): global dragon_prefix def quoteAsVisualBasicString(argument): q = argument q = string.replace(q, '"', '""') q = string.replace(q, "\n", '" + chr$(10) + "') q = string.replace(q, "\r", '" + chr$(13) + "') return '"' + q + '"' script = "" for argument in arguments: argument_type = argument_types[0] argument_types = argument_types[1:] if argument_type == 'i': argument = str(to_long(argument)) elif argument_type == 's': if function_name == "SendDragonKeys" or function_name == "SendKeys" \ or function_name == "SendSystemKeys": argument = convert_keys(argument) argument = quoteAsVisualBasicString(str(argument)) else: # there is a vcl2py.pl bug if this happens: raise VocolaRuntimeError( "Vocola compiler error: unknown data type " + " specifier '" + argument_type + "' supplied for a Dragon procedure argument") if script != '': script += ',' script += ' ' + argument script = dragon_prefix + function_name + script dragon_prefix = "" #print '[' + script + ']' try: if function_name == "SendDragonKeys": natlink.playString(convert_keys(arguments[0])) elif function_name == "ShiftKey": dragon_prefix = script + chr(10) else: natlink.execScript(script) except Exception, e: m = "when Vocola called Dragon to execute:\n" \ + ' ' + script + '\n' \ + ' Dragon reported the following error:\n' \ + ' ' + type(e).__name__ + ": " + str(e) raise VocolaRuntimeError, m
def gotResults_verb(self, words, fullResults): keywords = { 'cut': "output = '{Ctrl+x}'", 'copy': "output = '{Ctrl+c}'", 'bold': "output = '{Ctrl+b}'", 'italicize': "output = '{Ctrl+i}'", 'underline': "output = '{Ctrl+u}'", 'center': "output = '{Ctrl+e}'", 'left align': "output = '{Ctrl+l}'", 'right align': "output = '{Ctrl+r}'", 'delete': "output = '{Del}'", 'restore': "output = '{Alt+o}f{Alt+y}Regular{Enter}'" } if keywords.has_key(words[0]): exec keywords[words[0]] natlink.playString(output)
def tttestCopyClipboardCautious(self): """test the copying of the clipboard, with waiting times """ ## open the txtFiles (are closed in tearDown) for txtFile in txtFiles: hndle = self.openTestFile( os.path.join(thisDir, 'test_clipboardfiles', txtFile)) if hndle: self.allWindows[hndle] = txtFile else: print 'could not open %s' % txtFile cb = natlinkclipboard.Clipboard(save_clear=True) ## empty file: expTextPrev = "" for hndle, txtFile in self.allWindows.iteritems(): filePath = os.path.join(thisDir, 'test_clipboardfiles', txtFile) encoding, bom, expText = readwritefile.readAnything(filePath) if txtFile == "emptytest.txt": # now the clipboard remains unchanged... expText = expTextPrev else: # now save for empty file: expTextPrev = expText natlinkutilsqh.SetForegroundWindow(hndle) time.sleep(0.5) if txtFile == "emptytest.txt": time.sleep(3) natlink.playString("{ctrl+a}{ctrl+c}") # cb.copy_from_system(waiting_interval=0.05) # natlinkutilsqh.SetForegroundWindow(self.thisHndle) # print 'cb text: %s'% cb got = cb.get_text(waiting_interval=0.05) if txtFile == "emptytest.txt": self.assert_equal( expTextPrev, got, "testing empty txt file %s, result not as expected" % txtFile) else: self.assert_equal( expPrev, got, "testing txt file %s, result not as expected" % txtFile)
def send_keys(s, system = 0): """simulates keystroke input **INPUTS** *STR s* -- keys to send, in Dragon (DDWIN/Natspeak scripting language (pre-v6)) notation *BOOL system* -- if true, send the keystrokes as system keys (necessary for proper interpretation of Alt+Tab, windows hot keys, etc.) **OUTPUT** *none* """ flags = 0 if system: flags = hook_f_systemkeys natlink.playString(s, flags)
def send_keys(s, system=0): """simulates keystroke input **INPUTS** *STR s* -- keys to send, in Dragon (DDWIN/Natspeak scripting language (pre-v6)) notation *BOOL system* -- if true, send the keystrokes as system keys (necessary for proper interpretation of Alt+Tab, windows hot keys, etc.) **OUTPUT** *none* """ flags = 0 if system: flags = hook_f_systemkeys natlink.playString(s, flags)
def tttestCopyClipboardQuick(self): """test the copying of the clipboard, without waiting times """ ## open the txtFiles (are closed in tearDown) for txtFile in txtFiles: hndle = self.openTestFile( os.path.join(thisDir, 'test_clipboardfiles', txtFile)) if hndle: self.allWindows[hndle] = txtFile else: print 'did not open testfile: %s' % txtFile cb = natlinkclipboard.Clipboard(save_clear=True) ## empty file: expTextPrev = "" for hndle, txtFile in self.allWindows.iteritems(): filePath = os.path.join(thisDir, 'test_clipboardfiles', txtFile) encoding, bom, expText = readwritefile.readAnything(filePath) if txtFile == "emptytest.txt": expText = expTextPrev else: expTextPrev = expText natlinkutilsqh.SetForegroundWindow(hndle) natlink.playString("{ctrl+a}{ctrl+c}") cb.copy_from_system() # natlinkutilsqh.SetForegroundWindow(self.thisHndle) # print 'cb text: %s'% cb got = cb.get_text() self.assert_equal( expText, got, "testing txt file %s, result not as expected" % txtFile) # also test the class method (direct call) got = natlinkclipboard.Clipboard.get_system_text() self.assert_equal( expText, got, "testing txt file %s, with class method, result not as expected" % txtFile) cb.restore()
def playString(keys, hooks=None): """insert {shift} as workaround for losing keystrokes does not work. revert to normal playString not if hooks (like systemkeys) are used... use send_input module from Mark Lillibridge. Remove references to "ext" keyboard {ext..} and {ctrl+ext...} """ if not keys: return #elif hooks not in (None, 0x100) or keys.startswith("{shift}"): # # special hooks or startig with {shift} already... # pass #elif keys.startswith("{"): # print 'playString, do shift + pause' # natlink.playString("{shift}") # time.sleep(1) #else: # print 'playString, insert shift before keys' # keys = "{shift}" + keys if hooks in [None, 0x100]: if useMarkSendInput: if keys.find("{ext") >= 0: keys = keys.replace("{ext", "{") if keys.find("+ext") >= 0: keys = keys.replace("+ext", "+") # the Vocola extension, code by Mark Lillibridge: #print 'send_input and senddragonkeys_to_events: %s'% keys if keys.find('\n') > 0: keys = keys.replace('\n', '{enter}') print 'send_input, change keys to: %s'% repr(keys) send_input(senddragonkeys_to_events(keys)) else: natlink.playString(keys, 0x100) else: natlink.playString(keys, hooks)
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 playString(keys, hooks=None): """insert {shift} as workaround for losing keystrokes does not work. revert to normal playString not if hooks (like systemkeys) are used... use send_input module from Mark Lillibridge. Remove references to "ext" keyboard {ext..} and {ctrl+ext...} """ if not keys: return #elif hooks not in (None, 0x100) or keys.startswith("{shift}"): # # special hooks or startig with {shift} already... # pass #elif keys.startswith("{"): # print 'playString, do shift + pause' # natlink.playString("{shift}") # time.sleep(1) #else: # print 'playString, insert shift before keys' # keys = "{shift}" + keys if hooks in [None, 0x100]: if useMarkSendInput: if keys.find("{ext") >= 0: keys = keys.replace("{ext", "{") if keys.find("+ext") >= 0: keys = keys.replace("+ext", "+") # the Vocola extension, code by Mark Lillibridge: #print 'send_input and senddragonkeys_to_events: %s'% keys if keys.find('\n') > 0: keys = keys.replace('\n', '{enter}') print 'send_input, change keys to: %s' % repr(keys) send_input(senddragonkeys_to_events(keys)) else: natlink.playString(keys, 0x100) else: natlink.playString(keys, hooks)
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 processFile(fileName): # this create a decoder object sx96 = mobiletools.SX96Codec() # open the file and get the header information again (this has the side # effect of skipping past the header) sriFile = open(fileName,'rb') year,month,day,hour,minute,second,packetCount = decodeHeader(sriFile) # compute the size of the data for the output file frameCount = packetCount * 9 outDataSize = frameCount * wavFrameSize # open an output wave file and write out a header tempFileName = tempfile.mktemp() + '.wav' wavFile = open(tempFileName,'wb') writeHeader(wavFile,outDataSize) # iterate over each packet (9 frames) in the input file, convert the data # and write the converted data into the output file for i in range(packetCount): for j in range(9): frame = sriFile.read(sriFrameSize) wavData = sx96.decode(frame) wavFile.write(wavData) # discard the extra packet descriptor byte sriFile.read(1) wavFile.close() wavFile = None sriFile.close() sriFile = None # now we transcribe this file in NatSpeak natlink.execScript('AppBringUp "NatSpeak"') natlink.playString(formatDate(year,month,day,hour,minute,second)) natlink.inputFromFile(tempFileName)
def gotResults_iphoneselect(self, words, fullResults): """ Gives coordinates of an entry in a list on the iPhone. Receives the number of entries in the list (actually how many entries, given the size on the screen, would fit into the screen dimensions), the offset index of the first usable entry from top (how many entries Could fit above the first usable entry, give the index of the first usable entry) and the index of the desired entry. TODO: click on contact buttons on the right of entries """ cmdwords = words[:3] self.gotResults_iphonetap(cmdwords, fullResults) # now target window should be in focus and ready # static variables: appName = "iphoneWin" num_entries = 14 offset_index = 3 select_int = 1 select_int = (int(words[3])) # can use global variables populated by iphonetap hwin = self.windows.appDict[appName].winHandle if hwin: x, y, x1, y1 = wg.GetWindowRect(hwin) logging.debug('window Rect: %d,%d,%d,%d' % (x, y, x1, y1)) if len(words) > 4 and str(words[4]) == 'details': # selectable blue Arrow on the right side of the contact x_ofs = x + 17 * (x1 - x) / 18 else: # otherwise click in the centre (horizontal) x_ofs = x + (x1 - x) / 2 y_inc = (y1 - y) / num_entries y_ofs = y + y_inc / 2 + (select_int + offset_index - 1) * y_inc logging.debug( 'horizontal: %d, vertical: %d, vertical increments: %d' % (x_ofs, y_ofs, y_inc)) if (select_int + offset_index - num_entries - 1) <= 0: # if entering search text,hide keypad natlink.playString('{enter}', 0) self.click('leftclick', x=x_ofs, y=y_ofs, appName=appName) return
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_reloadEverything(self, words, fullResults): # bring window to front #[logger.info(k) for k in self.kbMacros.keys)] self.windows.winDiscovery(beginTitle=self.msgPy) natlink.playString('{alt}{down}',0)
def gotResults_fontRule(self, words, fullResults): natlink.playString('Saw <fontRule>')
def gotResultsInit(self,words,fullResults): natlink.playString('# INIT "%s" {enter}'%words)
def do_flush(functional_context, buffer): if functional_context: raise VocolaRuntimeError('attempt to call Unimacro, Dragon, or a Vocola extension procedure in a functional context!') if buffer != '': natlink.playString(convert_keys(buffer)) return ''
def gotResults_mainRule(self, words, fullResults): natlink.playString('Saw <mainRule>')
def gotResults_dgndictation(self,words,fullResults): natlink.playString('Saw <dgndictation> = %s{enter}' % "_".join(words))
def gotResults_dgnletters(self,words,fullResults): words = map(lambda x: x[:1], words) text = string.join(words, '') natlink.playString(' ' + text)
def gotResults_firstRule(self,words,fullResults): natlink.playString('# Say "demo sample two {ctrl+i}color{ctrl+i}"{enter}')
def gotResults_dgndictation(self,words,fullResults): natlink.playString('__%s__' % "_".join(words))
def winAction(self, actionKey='', appName='iphoneWin'): print "action" # concatenate actionKey if getattr(actionKey, 'insert'): actionKey = ' '.join(actionKey) print(str(self.__module__) + "debug: action Key of command concatenated: %s"% actionKey) # assuming the correct window is in focus # wake. Recognition mimic doesn't seem to be a good model. Something to # do with speed ofplayback etc. Grammar not always recognised as a # command. natlink.playString('{space}', 0x00) app = self.windows.appDict[str(appName)] gramList = [] if str(actionKey) in app.mimicCmds: # we want to get out of grid mode aftermouse positioning # special cases first. if str(actionKey) == 'home': natlink.recognitionMimic(['mouse', 'window']) natlink.recognitionMimic(['go']) self.click('rightclick',appName=appName) elif str(actionKey) == 'wake': natlink.recognitionMimic(['mouse', 'window']) natlink.recognitionMimic(['go']) self.click('rightclick',appName=appName) actionKey = 'drag right' natlink.recognitionMimic(['mouse', 'window']) gramList = app.mimicCmds[actionKey] print(str(self.__module__) + "debug: Grammer list for action '{0}': {1}".format( actionKey, gramList)) natlink.recognitionMimic(gramList) natlink.recognitionMimic(['go']) self.drag(dragDirection=actionKey.split()[1], dist=2) elif str(actionKey) == 'personal hotspot toggle': if app.vert_offset: app.vert_offset = 0 else: app.vert_offset = app.TOGGLE_VOFFSET print(str(self.__module__) + "debug: Toggled vertical offset, before: %d, after: %d"% (old, app.vert_offset)) elif str(actionKey).startswith("select"): pass # function continued in its own handler elif str(actionKey).startswith("show"): pass elif str(actionKey).startswith("drag"): natlink.recognitionMimic(['mouse', 'window']) gramList = app.mimicCmds[actionKey] print(str(self.__module__) + "debug: Grammer list for action '{0}': {1}".format( actionKey, gramList)) natlink.recognitionMimic(gramList) natlink.recognitionMimic(['go']) self.drag(dragDirection=actionKey.split()[1]) else: natlink.recognitionMimic(['mouse', 'window']) gramList = app.mimicCmds[actionKey] print(str(self.__module__) + "debug: Grammer list for action '{0}': {1}".format( actionKey, gramList)) natlink.recognitionMimic(gramList) natlink.recognitionMimic(['go']) self.click('leftclick',appName=appName) return 0 else: print(str(self.__module__) + 'error:unknown actionKey') return 1
def gotResults_mainRule(self,words,fullResults): natlink.playString('Saw <mainRule> = %s{enter}' % repr(words))
def gotResults_ruleTwo(self, words, fullResults): natlink.playString('Saw <ruleTwo> = %s{enter}' % repr(words))
def onCommand_DeleteThat(self, words): natlink.playString('{Del}')
def gotResults_ruleTwo(self,words,fullResults): natlink.playString('Saw <ruleTwo> = %s{enter}' % repr(words))
def onCommand_DeleteThat(self,words): natlink.playString('{Del}')
def gotResults_dgndictation(self,words,fullResults): words.reverse() text = string.join(words) natlink.playString(' ' + text)
def gotResults_mainRule(self, words, fullResults): natlink.playString('Saw <mainRule> = %s{enter}' % repr(words))
def gotResults_secondRule(self,words,fullResults): natlink.playString('# The color is "%s" {enter}'%words[len(words)-1])
def gotResults_start(self,words,fullResults): natlink.playString('Heard macro "sample one"{enter}')
def gotResults(self,words,fullResults): natlink.playString('# FINAL "%s" {enter}'%words)