def gotResults_changeMoving(self, words, fullResults): if self.nDir or self.Count or self.nSpeed != None: self.flush() b = r = '' for w in words: if b and r: natlinkutils.playString("{" + r + b + "}") b = r = '' if w in ['go on', 'ga door', 'ga verder', 'verder']: debugPrint('going on') self.waiting = 0 elif w in ['move', 'beweeg']: if self.state != 'selecting': self.state = 'moving' self.waiting = 0 elif w in ['select', 'selecteer']: self.state = 'selecting' self.waiting = 0 elif w in ['begin']: b = 'Home' elif w in ['einde', 'end']: b = 'End' elif w in ['line', 'regel']: r = 'ext' elif w in ['document']: r = 'ctrl+ext' if b and r: natlinkutils.playString("{" + r + b + "}") b = r = ''
def tearDown(self): for hndle in self.tempFileHndles: if not win32gui.IsWindow(hndle): print("???window does not exist: %s"% hndle) continue if hndle == self.thisHndle: # print('window hndle %s may not match "thisHndle": %s'% (hndle, self.thisHndle)) continue # print('close window with hndle: %s'% hndle) natlinkutilsqh.SetForegroundWindow(hndle) curHndle = natlinkutilsqh.GetForegroundWindow() if hndle == curHndle: if hndle in self.killActions: # natlinkutilsqh.SetForegroundWindow(self.thisHndle) # place to break in debug mode # natlinkutilsqh.SetForegroundWindow(curHndle) action(self.killActions[hndle], modInfo=self.modInfos[hndle]) else: natlinkutils.playString("{alt+f4}") natlinkutilsqh.SetForegroundWindow(self.thisHndle) self.disconnect() # disabled, natConnect notClosedHndles = [] for hndle in self.tempFileHndles: if hndle and win32gui.IsWindow(hndle): notClosedHndles.append(hndle) if self.frescHndle: if self.frescHndle in notClosedHndles: notClosedHndles.remove(self.frescHndle) else: raise TestError('Fresobaldi should not be closed after the test') if notClosedHndles: raise TestError('Hndles not close, but should: %s'% notClosedHndles)
def gotResults_pasthistory(self, words, fullResults): """possibility to "manually" update the styles list""" L = [''] for w in words: ## print 'got phword: %s'% w # including the trigger words! L.append(w) natlinkutils.playString(' '.join(L))
def test_Should_BringUp_DragonPad(self): actions.UnimacroBringUp("dragonpad") time.sleep(2) self.assert_mod_partoftitle('natspeak', 'DragonPad', " when bringing up DragonPad") natlinkutils.playString("this should last 2 seconds") time.sleep(2) actions.do_KW()
def onTextChange(self,delStart,delEnd,newText,selStart,selEnd): D('win dict, text change:%s, %s, %s, %s, %s'% ( delStart, delEnd, newText, selStart, selEnd)) self.dictObj.setLock(1) if self.ctrl: self.ctrl.SetSel(delStart,delEnd) self.ctrl.ReplaceSel(newText) self.ctrl.SetSel(selStart,selEnd) else: natlinkutils.playString(newText) self.dictObj.setLock(0)
def doAction(self): ## debugPrint('start doAction state: %s, dir: %s, count: %s'% \ ## (self.state, self.curDir, self.Count)) if self.state in ['moving', 'selecting', 'searching']: if not self.curDir: debugPrint('do action, no direction specified') return key = 'ext' + self.curDir if self.minorState == 'page': if self.curDir == 'down': key = 'extpgdn' elif self.curDir == 'up': key = 'extpgup' else: debugPrint('invalid direction for minorState page: %s' % self.curDir) elif self.minorState in ['word', 'paragraph']: key = 'ctrl+' + key if self.waiting and self.Count: nowCount = " " + repr(self.Count) else: nowCount = "" if self.state == 'moving': if self.startScroll: keyBefore = '' if self.curDir == 'up': keyBefore = 'extpgup' elif self.curDir == 'down': keyBefore = 'extpgdn' elif self.curDir == 'left': keyBefore = 'ctrl+extpgdn' elif self.curDir == 'right': keyBefore = 'ctrl+extpgup' else: debugPrint('invalid direction in scrollcommand: %s' % self.curDir) if keyBefore: natlinkutils.playString("{" + keyBefore + "}") self.startScroll = 0 self.setTrayIcon(1) natlinkutils.playString("{" + key + nowCount + "}") elif self.state == 'selecting': self.setTrayIcon(1) natlinkutils.playString("{shift+" + key + nowCount + "}") elif self.state == 'repeating': self.setTrayIcon(1) self.repeatNow() elif self.state == 'searching': self.setTrayIcon(1) if not self.curDir: print('searching, no current direction: %s, assume down' % self.curDir) self.curDir = self.getLastSearchDirection() or 'down' self.insideCommand = 1 count = self.Count or 1 for i in range(count): res = self.searchForText(self.curDir) self.curDir = self.getLastSearchDirection() if res == -2: # missing search, did cancel mode return unimacroutils.visibleWait() self.insideCommand = 0 elif self.state == 'mousing': self.setTrayIcon(1) if self.Count: self.moveMouse(self.curDir, self.Count * self.mouseJumps) else: self.moveMouse(self.curDir, self.mouseSteps) elif self.state == 'dragging': self.setTrayIcon(1) if self.Count: self.moveMouse(self.curDir, self.Count * self.mouseJumps) else: self.moveMouse(self.curDir, self.mouseSteps) else: return self.lastClock = time.time() return 1 # good exit
def tttestCopyClipboardSwitching(self): """test the copying of the clipboard with empty, small and larger .txt file. .docx does not run smooth """ print("testCopyClipboardSwitching") # self.setupDocxFile() # self.setupWindows() # self.setupThunderbirdNewWindow() self.setupFrescobaldiNewPane() self.setupTextFiles() cb = natlinkclipboard.Clipboard(save_clear=True, debug=2) # debug flag can be set or omitted (or set to 0) return ## longer test: for i in range(1, 10, 5): waitTime = 0.001/i print('---- round: %s, waitTime %.4f '% (i, waitTime)) ## first clear the clipboard: cb.clear_clipboard() got = cb.get_text(waitTime) print('after clear_clipboard, text: %s (cb: %s)'% (got, cb)) self.assert_equal("", got, "should have no text now, waitTime: %s (times 4)"% waitTime) print("now testempty.txt -----------------") # empty file: natlinkutilsqh.SetForegroundWindow(self.text0Hndle) natlinkutils.playString("{ctrl+a}{ctrl+c}") got = cb.get_text(waitTime) print('after select all copy of empty file, no change should have happened:') # print('got: %s, (cb: %s)'% (got, cb)) self.assert_equal("", got, "should have no text now, waitTime: %s"% waitTime) natlinkutilsqh.SetForegroundWindow(self.thisHndle) print("now testsmall.txt -----------------") natlinkutilsqh.SetForegroundWindow(self.text1Hndle) natlinkutils.playString("{ctrl+a}{ctrl+c}") got = cb.get_text(waitTime) print('after select all copy of testsmall.txt') # print('got: %s, (cb: %s)'% (got, cb)) exp = self.text1Txt self.assert_equal(exp, got, "testsmall should have two lines of text, waitTime: %s"% waitTime) # test large.txt print("now testlarge.txt -----------------") natlinkutilsqh.SetForegroundWindow(self.text2Hndle) natlinkutils.playString("{ctrl+a}{ctrl+c}") cb.get_text(waiting_interval=waitTime) got = cb.get_text() if got: lengot = len(got) else: print('testlarge, no result from get_text: %s'% cb) exp = len(self.text2Txt) self.assert_equal(exp, lengot, "should have long text now, waitTime: %s"% waitTime) # empty for the next round: # cb.set_text("") time.sleep(waitTime) natlinkutilsqh.SetForegroundWindow(self.thisHndle) # test natlink.docx print("now natlink.docx (%s)-----------------"% self.docx2Hndle) if not self.docx2Hndle: print("word document not available: %s"% (self.docx2Hndle)) continue natlinkutilsqh.SetForegroundWindow(self.docx2Hndle) natlinkutils.playString("{ctrl+a}{ctrl+c}") cb.get_text(waiting_interval=waitTime) got = cb.get_text() if got: lengot = len(got) else: print('testlarge, no result from get_text: %s'% cb) exp = len(self.text2Txt) self.assert_equal(exp, lengot, "should have long text now, waitTime: %s"% waitTime) # empty for the next round: # cb.set_text("") time.sleep(waitTime) del cb got_org_text = natlinkclipboard.Clipboard.get_system_text() self.assert_equal(self.org_text, got_org_text, "restored text from clipboard not as expected")
def playAltEsc(self): natlinkutils.playString('{alt+esc}', hook_f_systemkeys)
def clearWindow(self): natlinkutils.playString( '{ctrl+end}x{ctrl+a}{ctrl+c}{ctrl+end}{backspace}')
def playString(self, t): """send through to natlinkutils.self.playString """ natlinkutils.playString(t)
def gotResults_scratch(self, words, fullResults): print('heard command: %s '% words) i,j = self.txt.GetSel() if i < j: natlinkutils.playString("{backspace}")
def gotResults_OK(self, words, fullResults): print('heard command: %s '% words) natlinkutils.playString("{tab}{enter}")