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 gotBegin(self, moduleInfo): if self.checkForChanges: self.checkInifile() # refills grammar lists and instance variables if self.winkeyDown: className = natqh.getClassName() if className != 'TaskListThumbnailWnd': print('tasks, call cancelmode from gotBegin') self.cancelMode() if self.makeTaskNamesPythonw and moduleInfo and moduleInfo[0].endswith( "pythonw.exe"): wTitle = moduleInfo[1] if wTitle.find(" --- ") > 0: self.addTaskNameToDict(moduleInfo)
def doWinKey(self, keys, keepdown=None): """do a winkey and return the window info of the resulting window """ winkey = win32con.VK_LWIN # 91 keyup = win32con.KEYEVENTF_KEYUP # 2 win32api.keybd_event(winkey, 0, 0, 0) # key down try: actions.do_SSK(keys) actions.do_VW() classInfo = natqh.getClassName() finally: if classInfo == 'TaskListThumbnailWnd': #print 'keep logo key down' self.winkeyDown = 1 else: win32api.keybd_event(winkey, 0, keyup, 0) # key up
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 gotoTask(self, countOrApp): """go to the specified task, by number or application name, return proginfo, or None if task was not found """ self.lastTaskCount = None if type(countOrApp) in (bytes, str): countBack = self.getNumberFromSpoken( countOrApp, self.taskCounts) # returns a string or None elif isinstance(countOrApp, int): countBack = countOrApp hasMousePos = 0 appList = self.ini.get('application') ## print 'appList: %s'% appList if type(countOrApp) in (bytes, str) and self.hasCommon( countOrApp, 'back'): action('SSK {Alt+Tab}') return 1 elif countOrApp in self.namedtaskDict: hndle = self.namedtaskDict[countOrApp] result = natqh.SetForegroundWindow(hndle) if not result: print('switch to %s failed, delete name: %s' % (hndle, countOrApp)) del self.namedtaskDict[countOrApp] self.setList('namedtask', list(self.namedtaskDict.keys())) return else: return result elif countBack: t = time.time() self.lastTaskCount = countBack if self.doTasksWithWindowsKey: self.goto_task_winkey(countBack) else: action('TASK %s' % countBack) result = natqh.getProgInfo() #print 'after action task %s, time: %.2f'% (countBack, (time.time()-t)) return result elif countOrApp in appList: value = self.ini.getList('application', countOrApp) if len(value) == 1: app = value[0] self.app = app result = action("BRINGUP %s" % app) return result ## print 'after bringup: %s'% app elif len(value) == 2: #application is known, but click by number!! appName = value[0] countBack = value[1] self.lastTaskCount = countBack if self.doTasksWithWindowsKey: self.goto_task_winkey(countBack) else: action('TASK %s' % countBack) for i in range(30): # 40 x 0.1: 4 seconds... prog, title, topchild, classname, hndle = natqh.getProgInfo( ) if prog == appName: break className = natqh.getClassName() if className == "TaskListThumbnailWnd": return 1 # more items already available natqh.Wait() else: print('application not detected in foreground: %s' % appName) return else: print('_tasks, no valid entry for gotoTask: %s' % countOrApp) return result = natqh.getProgInfo()