def rule_taskaction(self, words): '(<taskswitch> | <subtask> | task)({taskaction}| "give name" <dgndictation>|<closemultiple>)' # do a taskaction to the current task, or one of the # numbered/named tasks or task back #print 'got taskaction: %s'% words actions = self.ini.get('taskaction') act = self.hasCommon(words, actions) giveName = self.hasCommon(words, "give name") #if self.app == "messages": # print 'action for messages: %s'% act # if act == 'refresh': # self.doTaskAction('close') # print 'new messages window' # return if giveName: hndle = natlink.getCurrentModule()[2] self.giveName = hndle elif act: self.doTaskAction(act) else: print('thistask in _general, no valid action', words) prog, title, topchild, classname, hndle = natqh.getProgInfo() if prog == 'explorer' and not title: return # no centermouse! if self.centerMouse: natqh.doMouse(1, 5, 0.3, 0.3, 0, 0)
def subrule_closemultiple(self, words): """close (all|other) | (all|other) close """ # note the grammar alternatives, eg in Dutch the translation of # all close (alles sluiten) is more convenient. if not self.lastTaskCount: print( '_tasks, close all | close multiple only works with a numbered task' ) return all = self.hasCommon(words, "all") multiple = self.hasCommon(words, "multiple") if all: action("MP 2, 0, 0, right; VW; {up}{enter}; VW") self.gotoTask("back") elif multiple: # close as long as special stacked window is found mousePos = natqh.getMousePosition() if mousePos is None: raise ValueError("could not get mouse position") x, y = mousePos className = natqh.getClassName() wNum = -1 # last window of stacked windows... #print 'tasks, subtask: %s'% wNum while className == "TaskListThumbnailWnd": #print 'got subtask, alternative window: %s'% words self.doAlternativeClick(className, wNum) action("<<windowclose>>") action("VW; MP 0, %s, %s" % mousePos) className = natqh.getClassName() self.gotoTask(self.lastTaskCount) if self.centerMouse: natqh.doMouse(1, 5, 0.3, 0.3, 0, 0)
def rule_numbereddocument(self, words): """# go to a numbered document document ({documentcount} [{documentaction}] | {documentaction}) """ count = self.getNumberFromSpoken(words[1]) # returns a string or None if count: #print 'goto task, countOrApp: %s'% countOrApp result = self.gotoDocument(count) if result: if self.centerMouse: natqh.Wait() natqh.doMouse(1, 5, 0.3, 0.3, 0, 0) # relative in client area, no clicking else: prog, title, topchild, classname, hndle = natqh.getProgInfo() print( '_tasks, could not switch to document: %s (program: %s)' % (count, prog)) if words[1] == words[-1]: return Act = self.getFromInifile(words[-1], 'documentaction') print('words[-1]: %s, Action: %s' % (words[-1], Act)) if Act: action(Act)
def tttest_getPositions(self): """test setting and getting positions in all possible ways use action RMP to go to the wanted position. then each time get a position (absolute/relative, absorrel, screen, active window or client area (0, 1, 5), and relative to one of the corners (0, 1, 2, 3)) setting it again and see if same position is found get with: getMousePosition set with: doMouse """ #absorrel = 0 # absolute #which = 0 # whole screen #corner = 0 # top left action("RMP(5, 0.3, 0.4, noclick)" ) # relative in foreground window, tune to your testing! initialPosition = natlink.getCursorPos() for absorrel in (0, 1): for which in (0, 1, 5): for cornerPos in range(4): #absorrel, which, cornerPos = 1, 0, 0 #absorrel = 1 # each test, little shifting for relative allowed if absorrel: epsilon = 0 # relative, position may shift a bit... else: epsilon = 0 # absolute, caculations must fit if absorrel == 0 and which == 0 and cornerPos > 0: print 'invalid combination to test: absorrel: %s, which: %s, cornerPos: %s' % ( absorrel, which, cornerPos) continue initialPosition = natlink.getCursorPos() mousePos = natlinkutilsqh.getMousePosition( absorrel, which, cornerPos) if mousePos is None: self.fail( 'getMousePosition in test suite should not result in None (absorrel: %s, which: %s, cornerPos: %s)' % (absorrel, which, cornerPos)) x, y = mousePos natlinkutilsqh.doMouse(absorrel, which, x, y, mouse="noclick") finalPosition = natlink.getCursorPos() log('command: %s, %s, %s, %s, initial: %s, final: %s' % (absorrel, which, x, y, repr(initialPosition), repr(finalPosition))) self.assert_equal( initialPosition, finalPosition, "position of mouse after simple action should be the same\n" "absorrel: %s, which: %s, cornerPos: %s" % (absorrel, which, cornerPos), epsilon=epsilon)
def gotResults_searchinothertask(self, words, fullResults): ## rule for searching in another task, activated only if ... t = time.time() searchWord = self.getSelectedText() print('searchWord from getSelectedText: %s' % searchWord) if not searchWord: searchWord = action("SELECTWORD") if not searchWord: print('_tasks, searchinothertask: could not select text') return t1 = time.time() print('searchword: %s (%.2f)' % (searchWord, t1 - t)) countOrApp = words[1] #print 'switch to task: %s'% countOrApp result = self.gotoTask(countOrApp) if result is None: print('_tasks, could not switch to task: %s' % countOrApp) return print('result after taskswitch: %s' % repr(result)) t2 = time.time() prog, title, topchild, classname, hndle = progInfo = result #print 'switched to "%s" (%.2f)'% (prog, t2-t1) if prog == 'explorer' and not title: return # no centermouse! if self.centerMouse: natqh.Wait() natqh.doMouse(1, 5, 0.3, 0.3, 0, 0) # relative in client area, no clicking natqh.Wait() # now do the postprocessing print('postprocessing for search: %s in app: %s' % (searchWord, prog)) if prog in ['chrome', 'firefox', 'iexplore']: phrase = '"%s" site:nl' % searchWord keystroke("{ctrl+k}") keystroke(phrase + "{enter}") elif prog == 'dictionaryworkbench': # hardcoded for Arnoud keystroke('{ctrl+f}') action("SCLIP %s" % searchWord) keystroke('{enter}') else: #t3 = time.time() action("<<startsearch>>", progInfo=progInfo) #t4 = time.time() keystroke(searchWord, progInfo=progInfo) #t5 = time.time() action("<<searchgo>>", progInfo=progInfo)
def tttest_getOutsideWindow(self): """try to position on the taskbar and get the position """ action("RMP(5, 1, 0.5, noclick)") # relative in foreground window, tune to your testing! action("MP(2, 500, 0, noclick)") # move a bit to the right initialPosition = natlink.getCursorPos() mousePos = natlinkutilsqh.getMousePosition() # abs, screen, corner not relevant if mousePos is None: self.fail("could not get mouse position") x, y = mousePos absorrel, which = 0, 0 natlinkutilsqh.doMouse(absorrel, which, x, y, mouse="noclick") finalPosition = natlink.getCursorPos() log('command outside window(?): %s, %s, %s, %s, initial: %s, final: %s'% (absorrel, which, x, y, repr(initialPosition), repr(finalPosition))) self.assert_equal(initialPosition, finalPosition, "position of mouse after move outside the current window should be the same\n" "absorrel: %s, which: %s"% (absorrel, which))
def rule_monitorfocus(self, words): 'monitor {monitors}' # put focus on monitor # target is the index of the MONITOR_HNDLES list of monitorfunctions.py. # for 3 monitors 0, 1 or 2. Which is which has to be tried, hopefully the # list is consistent monitorIndex = int(self.getFromInifile(words[1], 'monitors')) # print 'ask for monitor: %s'% monitorIndex WORK AREA rect = monitorfunctions.get_monitor_rect_work(monitorIndex) # print 'rect: %s'% repr(rect) if not rect: print('rule_monitorfocus, no position rectangle found') return mx, my = natqh.relToCoord(0.5, rect[0], rect[2]), natqh.relToCoord( 0.01, rect[1], rect[3]) natqh.doMouse(0, 0, mx, my, mouse='left') natqh.visibleWait() # relative and relative to current monitor work area: natqh.doMouse(1, 4, 0.5, 0.5, mouse="noclick") natqh.visibleWait()
def rule_subtask(self, words): """# commands for going to a subtask in a stacked taskbar window {n1-10} | {firstlast} window """ className = natqh.getClassName() wNumList = self.getNumbersFromSpoken(words) # returns a string or None if wNumList: wNum = wNumList[0] else: wNum = self.getFromInifile(words, 'firstlast') if not wNum: print('tasks, rule subtaks, no window number found') return #print 'tasks, subtask: %s'% wNum if className == "TaskListThumbnailWnd": #print 'got subtask, alternative window: %s'% wNum self.doAlternativeClick(className, wNum) if self.centerMouse and not self.nextRule: # so last rule of the recognition natqh.doMouse(1, 5, 0.3, 0.3, 0, 0)
def rule_taskswitch(self, words): """#commands for switching tasks: task ({taskcount}|{taskcount}<subtask>|{application}|{application}<subtask>|back|{namedtask}) """ #print 'got taskswitch: %s'% words #switch to a task by number, application or Back #leave the mouse at 0.3 0.3 relative to the top countOrApp = words[1] #print 'goto task, countOrApp: %s'% countOrApp result = self.gotoTask(countOrApp) if result: prog, title, topchild, classname, hndle = natqh.getProgInfo() if prog == 'explorer' and not title: return # no centermouse! if self.centerMouse and not self.nextRule: natqh.Wait() natqh.doMouse(1, 5, 0.3, 0.3, 0, 0) # relative in client area, no clicking else: print('_tasks, could not switch to task: %s' % countOrApp)
def test_doMouse(self): """problem with doMouse (natlinkutilsqh) with second screen LEFT of first""" natqh.doMouse(0, 0, 35, 188, 0) pass