Skip to content

Commit

Permalink
fixed #35 and a few other things.
Browse files Browse the repository at this point in the history
  • Loading branch information
quintijn committed Dec 22, 2022
1 parent 778f74e commit c22ecbd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
73 changes: 37 additions & 36 deletions src/unimacro/UnimacroGrammars/_clickbyvoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@
in the foreground
"""
#pylint:disable=


import natlink
from dtactions.unimacro import unimacroutils
from natlinkcore import natlinkutils as natut
from unimacro import natlinkutilsbj as natbj
from dtactions.unimacro import unimacroutils
import unimacro.natlinkutilsbj as natbj
from dtactions.unimacro.unimacroactions import doAction as action
from dtactions.unimacro.unimacroactions import doAction as action
from dtactions.unimacro.unimacroactions import doKeystroke as keystroke

# use extension Click by Voice
visiblePause = 0.4
Expand Down Expand Up @@ -78,13 +75,14 @@ def initialize(self):
self.load(self.gramSpec)

def gotBegin(self,moduleInfo):
if not language: return
if not language:
return
if self.checkForChanges:
self.prevHandle = None

winHandle = moduleInfo[2]
if not winHandle:
print('no window handle in %s'% self.name)
print(f'no window handle in {self.name}')
return
if self.prevHandle == winHandle:
return
Expand All @@ -94,14 +92,14 @@ def gotBegin(self,moduleInfo):
prog = progInfo.prog
chromiumBrowsers = {'chromium', 'chrome', 'msedge', 'safari', 'brave'}
if prog in chromiumBrowsers:
if progInfo.topchild == 'child':
print('in child window, the clickbyvoice window?')
if progInfo.toporchild == 'child':
print(f'in child window, of a clickbyvoice program {prog}')
if self.checkForChanges:
print('_clickbyvoice (%s), prog: %s, checking the inifile'% (self.name, prog))
print(f'_clickbyvoice ({self.name}, prog: {prog}, checking the inifile')
self.checkInifile()
self.switchOnOrOff(window=winHandle)
if not self.isActive == winHandle:
print("activate _clickbyvoice, %s, %s"% (prog, winHandle))
print(f'activate _clickbyvoice, {prog}, hndle: {winHandle}')
self.activateAll(window=winHandle)
self.isActive = winHandle
else:
Expand Down Expand Up @@ -135,9 +133,10 @@ def gotResults_shownumbers(self, words, fullResults):
additionalOptions = False
while 1:
additional = self.getFromInifile(words[-1], 'additionalonoroff', noWarning=1)
if additional is None: break
if additional is None:
break
if additional == '-':
print('%s: hide the numbers'% self.name)
print(f'{self.name}: hide the numbers')
self.gotResults_hidenumbers(words, fullResults)
return
words.pop() # remove last word of list.
Expand All @@ -148,7 +147,7 @@ def gotResults_shownumbers(self, words, fullResults):
additionalOptions = True

if additionalOptions:
print('%s: showNumbers command: %s, set as new default for the current session.'% (self.name, showNumbers))
print(f'{self.name}: showNumbers command: {showNumbers}, set as new default for the current session.')
# set new chosen string:
# self.setInInifile("general", "show numbers", showNumbers)

Expand All @@ -162,7 +161,7 @@ def gotResults_hidenumbers(self, words, fullResults):
"""hide the numbers
"""
wordFound, position = self.hasCommon(words, "after", withIndex=True)
wordFound, _position = self.hasCommon(words, "after", withIndex=True)
if wordFound:
print("setting timer later")

Expand Down Expand Up @@ -194,13 +193,13 @@ def gotResults_numberedtabs(self,words,fullResults):
def gotResults_navigatetabs(self,words,fullResults):
"""go to next or previous tab(s) (documents) and refresh possibly"""
print(f'navigate tabs: {words}')
dir = None
direction = None
command = self.getFromInifile(words, 'tabcommands',noWarning=1)

if self.hasCommon(words, ['next', 'verder', 'volgende', 'vooruit', 'forward']):
dir = 'tab'
direction = 'tab'
elif self.hasCommon(words, ['previous', 'terug', 'vorige', 'back']):
dir = 'shift+tab'
direction = 'shift+tab'
else:
print(f'no direction found in command: {words}')

Expand All @@ -209,12 +208,12 @@ def gotResults_navigatetabs(self,words,fullResults):
count = counts[0]
else:
count = 1
## print 'tabs: dir: %s, count: |%s|, command: |%s|'% (dir, counlinker balkt, command)
## print 'tabs: direction: %s, count: |%s|, command: |%s|'% (direction, counlinker balkt, command)

if dir:
if direction:
while count > 0:
count -= 1
keys = '{ctrl+' + dir + '}'
keys = '{ctrl+' + direction + '}'
keystroke(keys)
unimacroutils.Wait(0.5) #0.3 seem too short for going back tabs in chrome

Expand All @@ -225,15 +224,15 @@ 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
direction = None
command = self.getFromInifile(words, 'pagecommands',noWarning=1)

if self.hasCommon(words, ['next', 'verder', 'volgende', 'vooruit', 'forward']):
dir = 'right'
direction= 'right'
elif self.hasCommon(words, ['previous', 'terug', 'vorige', 'back']):
dir = 'left'
direction= 'left'
else:
print('no direction found in command: %s'% words)
print(f'no direction found in command: {words}')

counts = self.getNumbersFromSpoken(words)
if counts:
Expand All @@ -242,10 +241,10 @@ def gotResults_navigatepages(self,words,fullResults):
count = 1
## print 'PAGES: dir: %s, count: |%s|, command: |%s|'% (dir, counlinker balkt, command)

if dir:
if direction:
while count > 0:
count= count -1
keystroke('{alt+%s}'%(dir))
keystroke('{alt+%s}'%(direction))
unimacroutils.Wait(0.5) #0.3 seem too short for going back pages in chrome

if command:
Expand All @@ -270,10 +269,10 @@ def gotResults(self,words,fullResults):
command += ":"
command += self.navOption
if command.find(';') >= 0:
print('command: %s'% command)
print(f'command: {command}')
commandparts = command.split(';')
command = commandparts.pop(0)
print('command: %s, commandparts: %s'% (command, commandparts))
print(f'command: {command}, commandparts: {commandparts}')
self.doOption(command)
for additional in commandparts:
unimacroutils.Wait(visiblePause)
Expand All @@ -288,8 +287,9 @@ def getInputcontrol(self):
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)
if progInfo.toporchild == 'child':
if i:
print(f'found input window after {i} steps')
break
unimacroutils.Wait()
else:
Expand All @@ -314,14 +314,14 @@ def fillInstanceVariables(self):
"""
self.showNumbers = self.ini.get('general', 'show numbers') or ':+'
if not self.showNumbers.find(":") == 0:
if self.showNumbers.find(":") != 0:
if self.showNumbers.find(":") == -1:
self.showNumbers = ":" + self.showNumbers
else:
print('%s, "+" sign missing in inifile, "general", "show numbers": "%s", replace by default: "%s"'% (self.name, self.showNumbers, ":+"))
print(f'{self.name}, "+" sign missing in inifile, "general", "show numbers": "{self.showNumbers}", replace by default: ":+"')
self.showNumbers = ":+"
if self.showNumbers.find("+") != 1:
print('%s, "+" sign missing or in wrong position in inifile, "general", "show numbers": "%s", replace by default: "%s"'% (self.name, self.showNumbers, ":+"))
print('{self.name}, "+" sign missing or in wrong position in inifile, "general", "show numbers": "{self.showNumbers}", replace by default: ":+"')
self.showNumbers = ":+"
# not in inifile:
self.hideNumbers = ":-"
Expand All @@ -338,6 +338,7 @@ def fillInstanceVariables(self):
def unload():
#pylint:disable=W0603
global thisGrammar
if thisGrammar: thisGrammar.unload()
if thisGrammar:
thisGrammar.unload()
thisGrammar = None

3 changes: 1 addition & 2 deletions src/unimacro/UnimacroGrammars/_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,9 @@ def cancelMode(self):
self.hadRepeat = 0
self.repeatStuff = None
self.lastResults = []
print('_repeat, return to normal state, non exclusive')
self.activateSet(normalSet, exclusive=0)

resetExclusiveMode = cancelMode

## def waitMode(self):
## if self.waiting:
## debugPrint('in timer, already waiting')
Expand Down
4 changes: 3 additions & 1 deletion src/unimacro/enabledictation/_enabledictation.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def onTextBegin(self,moduleInfo):
dct = self.dictObj
dct.deactivate()
self.dctactive = 0
prog, title, topchild, hndle = unimacroutils.getProgInfo(moduleInfo)
progInfo = unimacroutils.getProgInfo(moduleInfo)

_progpath, prog, title, _toporchild, _classname, _hndle = progInfo
print('changing app to: "%s", %s'% (prog, hndle))
self.app, self.ctrl = None, None
if prog in self.WindowsParameters:
Expand Down
5 changes: 2 additions & 3 deletions src/unimacro/natlinkutilsbj.py
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,7 @@ def searchFailed(self, progInfo=None):
if not progInfo:
return None # no information
# old info:
_progpath, prog, title, topchild, _classname, _hndle = progInfo
_progpath, prog, title, toporchild, _classname, _hndle = progInfo
nprogInfo = unimacroutils.getProgInfo() # for checking if window or title changed
if (prog == 'natspeak' and title.find('dragonpad') >= 0) or \
(prog == 'notepad' and title.find('notepad') >= 0) or \
Expand All @@ -2991,7 +2991,7 @@ def searchFailed(self, progInfo=None):
if progInfo != nprogInfo:
print('%s: window changed, cancel search'% prog)
return -2 # cancelMode, because window title changed
elif (prog == 'winword' and topchild == 'top' and nprogInfo[2] == 'child'):
elif (prog == 'winword' and toporchild == 'top' and nprogInfo[2] == 'child'):
print('%s: search failed, cancel search'% prog)
return -2 # cancelMode, because window title changed
return None
Expand Down Expand Up @@ -3065,7 +3065,6 @@ def getTopOrChild(self, progInfo=None, childClass=None):
if self.debug:
print('getTopOrChild: child mode, because of className "%s"'% childClass)
istop = False
# IamChild32770 = topchild, hndle == 'child' and win32gui.GetClassName(hndle) == '#32770'
else:
if actions.childWindowBehavesLikeTop( progInfo ):
if self.debug:
Expand Down

0 comments on commit c22ecbd

Please sign in to comment.