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 goto_task_winkey(self, number): """switch to task with number, via the windows key""" ## print 'action: goto task: %s'% number prog, title, topchild, classname, hndle = natqh.getProgInfo() if prog == 'explorer' and not title: keystroke('{esc}') natqh.shortWait() try: count = int(number) except ValueError: print('goto_task_winkey, invalid number: %s' % number) return if not count: print('goto_task_winkey, invalid number: %s' % number) return elif count == 10: count = 0 elif count > 10: print('goto_task_winkey, pass on to "TASK %s", number > 9' % count) return action('TASK %s' % count) self.doWinKey('b') actions.do_VW() self.doWinKey(str(number)) print('self.winkeyDown: %s' % self.winkeyDown)
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 update(self, newProgInfo=None): if newProgInfo is None: newProgInfo = natqh.getProgInfo() if newProgInfo == self.progInfo: return print 'allactions: new prog info, overload for your specific program: %s'% self.prog self.progInfo = newProgInfo self.prog, self.topTitle, self.topOrChild, self.topHandle = newProgInfo
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 rule_getdocumentposition(self, words): """ #commands for recording a document position, application specific get document position {documentcount} """ # getting the task positions (use with 1 and with another number) # position mouse on task number or clock and speak the command # first time only, or after changes of taskbar position prog, title, topchild, classname, hndle = natqh.getProgInfo() if not prog: print( '%s, no valid program for setting document position: %s (title:%s)' % (self.name, prog, title)) return count = self.getNumberFromSpoken(words[-1]) x, y = natlink.getCursorPos() if count in self.documentCounts: print('%s, setting document position %s for program: %s' % (self.name, count, prog)) else: print( '%s, cannot set document position "%s" for program: %s (invalid count)' % (self.name, count, prog)) return if count == 1: print('setting mouseX1: ', x) print('setting mouseY1: ', y) setPosition('mousex1', x, prog=prog) setPosition('mousey1', y, prog=prog) else: mousex1 = getPosition('mousex1', prog=prog) mousey1 = getPosition('mousey1', prog=prog) mouseXdiff = int((x - mousex1) / (count - 1)) mouseYdiff = int((y - mousey1) / (count - 1)) print('setting mouseXdiff: ', mouseXdiff) print('setting mouseYdiff: ', mouseYdiff) setPosition('mousexdiff', mouseXdiff, prog=prog) setPosition('mouseydiff', mouseYdiff, prog=prog)
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()
def __init__(self, progInfo): if progInfo is None: progInfo = natqh.getProgInfo() self.prog, self.topTitle, self.topOrChild, self.topHandle = progInfo self.progInfo = progInfo
def reset(self, progInfo=None): if progInfo is None: progInfo = natqh.getProgInfo() self.prog, self.topTitle, self.topOrChild, self.topHandle = progInfo self.progInfo = None
def checkForChanges(self, progInfo=None): """return 1 if book, sheet or position has changed since previous call """ progInfo = progInfo or natqh.getProgInfo() changed = 0 if not self.app: self.progInfo = progInfo self.connect() if not self.app: return title = self.topTitle = progInfo[1] if not self.isInForeground(app=self.app, title=title, progInfo=progInfo): print 'not in foreground, excel' if self.prevBook: changed = 8 # from foreground into background self.prevBook = self.prevSheet = self.prevPosition = None self.book = self.sheet = self.Position = None self.currentRow = self.currentLine = None self.currentColumn = None self.progInfo = progInfo return self.book = self.app.ActiveWorkbook if self.book is None: print 'ExcelAction, no active workbook' self.bookName = '' self.sheetName = '' self.sheet = None else: self.bookName = str(self.book.Name) self.sheet = self.app.ActiveSheet self.sheetName = str(self.sheet.Name) if self.prevBook != self.bookName: self.prevBook = self.bookName changed += 4 if self.prevSheet != self.sheetName: self.prevSheet = self.sheetName changed += 2 if changed: # print 'excel-actions: update book and/or sheet variables' self.positions.setdefault(self.bookName,{}) self.positions[self.bookName].setdefault(self.sheetName, []) self.columns.setdefault(self.bookName,{}) self.columns[self.bookName].setdefault(self.sheetName, []) self.rows.setdefault(self.bookName,{}) self.rows[self.bookName].setdefault(self.sheetName, []) self.currentPositions = self.positions[self.bookName][self.sheetName] self.currentColumns = self.columns[self.bookName][self.sheetName] self.currentRows = self.rows[self.bookName][self.sheetName] if self.sheet: #print 'excel-actions: %s, update current position'% self.sheet cr = self.savePosition() self.currentPosition = cr self.currentRow = self.currentLine = cr[1] self.currentColumn = cr[0] #print 'currentColumn: %s, currentRow: %s, currentLine: %s'% (self.currentColumn, self.currentRow, self.currentLine) if cr != self.prevPosition: self.prevPosition = cr changed += 1 #else: # print 'same position: %s'% repr(cr) else: print 'excel-actions, no self.sheet.' #print 'return code checkForChanges: %s'% changed return changed