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 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 != '': natlinkutils.playString(convert_keys(buffer)) return ''
def hasSelection(self): """returns the text if text is selected, otherwise None """ natqh.saveClipboard() playString("{ctrl+c}") t = natqh.getClipboard() or None natqh.restoreClipboard() return t
def metaaction_makeunicodestrings(self, dummy=None): """for doctest testing, put u in front of every string """ print 'metaaction_makeunicodestrings, for Komodo' natut.playString("{ctrl+c}") t = natqh.getClipboard() print 'in: %s' % t t = replaceStringToUnicode(t) natqh.setClipboard(t) natut.playString("{ctrl+v}{down}")
def getPrevLine(self, n=1): """get line preceding the cursor more lines possible, if n > 1 """ playString("{shift+up %s}{ctrl+c}" % n) natqh.Wait() result = natqh.getClipboard() ndown = result.count('\n') if ndown: playString("{shift+down %s}" % ndown) return result
def getNextLine(self, n=1): """get line following the cursor n > 1, take more lines down for a larger range """ playString("{shift+down %s}{ctrl+c}" % n) natqh.Wait() result = natqh.getClipboard() nup = result.count('\n') if nup: playString("{shift+up %s}" % nup) return result
def getPrevNext(self, n=1): """return character to the left and to the right of the cursor assume no selection active. normally return cursor in same position """ natqh.saveClipboard() playString("{left %s}" % n) playString("{shift+right %s}" % (n * 2, )) playString("{ctrl+c}") playString("{left}{right %s}" % n) result = natqh.getClipboard() natqh.restoreClipboard() if len(result) == 2: return result[0], result[1] elif result == '\n': print 'getPrevNext, assume at end of file...' # assume at end of file, could also be begin of file, but too rare too handle playString("{right}") return result, result else: # print 'getPrevNext, len not 2: %s, (%s)'% (len(result), repr(result)) return "", result
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")