def getInputcontrol(self): """get the Click by Voice input control""" keystroke("{shift+ctrl+space}") unimacroutils.Wait() ## longer: unimacroutils.Wait(visiblePause) for i in range(10): progInfo = unimacroutils.getProgInfo() if progInfo.topchild == 'child': if i: print('found input window after %s steps' % i) break unimacroutils.Wait() else: print("_clickbyvoice failed to reach input window") # print("found input window of clickbyvoice") unimacroutils.visibleWait()
def gotResults(self, words, fullResults): # step 5, in got results collect the number: # only necessary in this grammar for collecting the choose command if not self.hadPick: return self.collectNumber() if not self.number: print('collected no number') return self.getInputcontrol() command = self.number commandparts = [] if self.navOption: if not self.navOption.startswith(":"): command += ":" command += self.navOption if command.find(';') >= 0: print('command: %s' % command) commandparts = command.split(';') command = commandparts.pop(0) print('command: %s, commandparts: %s' % (command, commandparts)) self.doOption(command) for additional in commandparts: unimacroutils.Wait(visiblePause) keystroke(additional) self.finishInputControl()
def gotResults_navigatepages(self, words, fullResults): """go to next or previous page(s) and refresh possibly""" ## print 'navigate pages: %s'% words ## not active at the moment, possibly reactivate... dir = None command = self.getFromInifile(words, 'pagecommands', noWarning=1) if self.hasCommon( words, ['next', 'verder', 'volgende', 'vooruit', 'forward']): dir = 'right' elif self.hasCommon(words, ['previous', 'terug', 'vorige', 'back']): dir = 'left' else: print('no direction found in command: %s' % words) counts = self.getNumbersFromSpoken(words) if counts: count = counts[0] else: count = 1 ## print 'PAGES: dir: %s, count: |%s|, command: |%s|'% (dir, counlinker balkt, command) if dir: while count > 0: count = count - 1 keystroke('{alt+%s}' % (dir)) unimacroutils.Wait( 0.5) #0.3 seem too short for going back pages in chrome if command: action(command)
def gotResults_navigatetabs(self, words, fullResults): """go to next or previous tab(s) (documents) and refresh possibly""" print(f'navigate tabs: {words}') dir = None command = self.getFromInifile(words, 'tabcommands', noWarning=1) if self.hasCommon( words, ['next', 'verder', 'volgende', 'vooruit', 'forward']): dir = 'tab' elif self.hasCommon(words, ['previous', 'terug', 'vorige', 'back']): dir = 'shift+tab' else: print(f'no direction found in command: {words}') counts = self.getNumbersFromSpoken(words) if counts: count = counts[0] else: count = 1 ## print 'tabs: dir: %s, count: |%s|, command: |%s|'% (dir, counlinker balkt, command) if dir: while count > 0: count -= 1 keys = '{ctrl+' + dir + '}' keystroke(keys) unimacroutils.Wait( 0.5) #0.3 seem too short for going back tabs in chrome if command: action(command)
def gotResults_resetexclusive(self, words, fullResults): print('reset exclusive') if natbj.exclusiveGrammars: T = ['exclusive grammars:'] for e in natbj.exclusiveGrammars: T.append(e) T.append(self.name) T.append('... reset exclusive mode') self.DisplayMessage(' '.join(T)) natbj.GlobalResetExclusiveMode() unimacroutils.Wait(1) self.DisplayMessage('reset exclusive mode OK') else: self.DisplayMessage('no exclusive grammars')
def switch(self, gram, gramName, funcName): """switch on or off grammar, and set in inifile, """ func = getattr(gram, funcName) # in case manual changes were done: #gram.checkInifile() if funcName == 'switchOn': self.checkInifile() if not gram.mayBeSwitchedOn: gram.ini.set('general', 'initial on', 1) #gram.mayBeSwitchedOn = 1 gram.ini.write() unimacroutils.Wait(0.1) else: print('reload grammar "%s"' % gram.getName()) gram.unload() gram.initialize() # modName = gram.__module__ # modPath = gram.__module__.__file__ # natlinkmain.unload_module(modName) # natlinkmain.load_or_reload_module(modPath, force_load=True) #print 'reloaded "%s"'% modName return 1 if funcName == 'switchOff': if gram.mayBeSwitchedOn: gram.ini.set('general', 'initial on', 0) gram.ini.writeIfChanged() gram.mayBeSwitchedOn = 0 gram.unload() print('grammar "%s" switched off' % gram.getName()) return 1 print('grammar "%s" switched off (again)' % gram.getName()) return 1 raise ValueError( 'switching on/off should have as function "switchOn" or "switchOff", not: %s' % func)
def Wait(self, t=None): if not t: unimacroutils.Wait(self.pause * pauzesDelta + minPause) else: unimacroutils.Wait(t)