Skip to content

Commit

Permalink
some progress in _control grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
quintijn committed Feb 23, 2023
1 parent 3d36c47 commit e05ce8b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
9 changes: 5 additions & 4 deletions src/unimacro/UnimacroGrammars/_clickbyvoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ThisGrammar(ancestor):

def initialize(self):
self.prevHandle = -1
self.ActiveHndle = None
self.load(self.gramSpec)

def gotBegin(self,moduleInfo):
Expand All @@ -98,15 +99,15 @@ def gotBegin(self,moduleInfo):
print(f'_clickbyvoice ({self.name}, prog: {prog}, checking the inifile')
self.checkInifile()
self.switchOnOrOff(window=winHandle)
if not self.isActive == winHandle:
if not self.ActiveHndle == winHandle:
print(f'activate _clickbyvoice, {prog}, hndle: {winHandle}')
self.activateAll(window=winHandle)
self.isActive = winHandle
self.ActiveHndle = winHandle
else:
if self.isActive:
if self.isActive():
print("deactivate _clickbyvoice")
self.deactivateAll()
self.isActive = False
self.ActiveHndle = False


def gotResultsInit(self,words,fullResults):
Expand Down
11 changes: 6 additions & 5 deletions src/unimacro/_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# _control.py, adapted version of_gramutils.py
# Author: Bart Jan van Os, Version: 1.0, nov 1999
# starting new version Quintijn Hoogenboom, August 2003
# starting new version Quintijn Hoogenboom, August 2003, for python3 2023
#pylint:disable=C0115, C0116, W0702, R0904, R0911, R0912, R0914, R0915, W0201, W0613, W0107, C0209, E0601, W0602
#pylint:disable=E1101

Expand Down Expand Up @@ -303,7 +303,7 @@ def switch(self, gram, gname, switchOn):
"""
if gram == self:
print(f'should not be here, do not switch on of off _control {gram}')
return
return None
if switchOn:
self.checkInifile()
gram.ini.set('general', 'initial on', 1)
Expand Down Expand Up @@ -331,7 +331,7 @@ def gotResults_showexclusive(self,words,fullResults):
else:
Start=()
# fix state at this moment (in case of Active grammars popup)

print(f'_control, showexclusive, exclusiveGrammars: {natbj.exclusiveGrammars}')
if natbj.exclusiveGrammars:
Exclusive = 1
self.BrowsePrepare(Start, All, Exclusive)
Expand Down Expand Up @@ -393,8 +393,8 @@ def gotResults_show(self,words,fullResults):
return
if self.hasCommon(words, 'exclusive'):
G = self.getExclusiveGrammars()
exclNames = [g for g in G if G[g].isExclusive()]
print('exclusive grammars (+ control) are: {exclNames}')
exclNames = [gname for gname, gram in G.items() if gram.isExclusive()]
print(f'exclusive grammars (+ control) are: {exclNames}')
self.gotResults_showexclusive(words, fullResults)
return

Expand Down Expand Up @@ -434,6 +434,7 @@ def gotResults_show(self,words,fullResults):
else:
Start=()
# fix state at this moment (in case of Active grammars popup)
Exclusive = 0
self.BrowsePrepare(Start, All, Exclusive)
if All or Active:
#print 'collect and show active, non-active and non-Unimacro grammars'
Expand Down
4 changes: 3 additions & 1 deletion src/unimacro/natlinkutilsbj.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def RegisterGrammarObject(self):
def SetGrammarsChangedFlag(self):
self.GrammarsChanged.append(True)
def GetGrammarsChangedFlag(self):
return self.GrammarsChanged.pop()
if self.GrammarsChanged:
return self.GrammarsChanged.pop()
return False
def ClearGrammarsChangedFlag(self):
self.GrammarsChanged.clear()

Expand Down
23 changes: 10 additions & 13 deletions src/unimacro/natspeak_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
# grammar activated if a recent folders dialog is brought to the foreground,
# interaction with grammar _folders.
#



import natlink
from natlinkcore import natlinkutils
from dtactions.unimacro import unimacroutils
#pylint:disable=
from dtactions.unimacro import unimacroutils
from dtactions.sendkeys import sendkeys as keystroke
import unimacro.natlinkutilsbj as natbj
from dtactions.unimacro.unimacroactions import doAction as action
from dtactions.unimacro.unimacroactions import doAction as action



ancestor = natbj.IniGrammar
Expand All @@ -40,7 +35,7 @@ def initialize(self):
print("no valid language in grammar "+__name__+" grammar not initialized")
return
self.load(self.gramSpec)
print('loaded: %s'% self.gramSpec)
print(f'loaded: {self.gramSpec}')
self.prevHndle = None

def gotBegin(self,moduleInfo):
Expand All @@ -54,7 +49,7 @@ def gotBegin(self,moduleInfo):
self.prevHndle = hndle
if unimacroutils.matchModule('natspeak'):
# try to reach data from _folders grammar:
self.foldersGram = natbj.GetGrammarObject('folders')
self.foldersGram = self.GetGrammarObject('folders')
#print 'self.foldersGram: %s'% self.foldersGram
if self.foldersGram is None:
return
Expand All @@ -75,14 +70,14 @@ def gotResults_chooserfd(self, words, fullResults):
"""
wNumList = self.getNumbersFromSpoken(words) # returns a string or None
if len(wNumList) != 1:
print('natspeak dialog: error in command, no number found: %s'% wNumList)
print(f'natspeak dialog: error in command, no number found: {wNumList}')
return
chooseNum = wNumList[0]
self.exitDialog()
self.foldersGram.gotoRecentFolder(chooseNum-1) # remember choose is 1 based, the list is 0 based

def gotResults_okcancelrfd(self, words, fullResults):
print('dialog ok cancel: %s, just close the dialog'% words)
print(f'dialog ok cancel: {words}, just close the dialog')
self.exitDialog()

def exitDialog(self):
Expand All @@ -99,6 +94,8 @@ def exitDialog(self):
thisGrammar.initialize()

def unload():
#pylint:disable=W0603
global thisGrammar
if thisGrammar: thisGrammar.unload()
if thisGrammar:
thisGrammar.unload()
thisGrammar = None
22 changes: 20 additions & 2 deletions tests/test_grammar_folders.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
#pylint:disable=E1101
from pathlib import Path
import pytest

from unimacro.UnimacroGrammars._folders import ThisGrammar

thisDir = Path(__file__).parent

def test_fill_folders_list(unimacro_setup):
"""see if (with debugging) the list folders (foldersDict) is filled
"""
from unimacro.UnimacroGrammars._folders import ThisGrammar
# from unimacro.UnimacroGrammars._folders import ThisGrammar
thisGrammar = ThisGrammar()
thisGrammar.startInifile() #modName = '_folders')
thisGrammar.initialize()

def test_folder_remember(unimacro_setup):
"""go through folder remember functions
"""
# from unimacro.UnimacroGrammars._folders import ThisGrammar
thisGrammar = ThisGrammar()
thisGrammar.startInifile() #modName = '_folders')
thisGrammar.initialize()
words = ['this', 'folder', 'remember']
FR = {}
thisGrammar.catchRemember = 'folder'
thisGrammar.wantedFolder = r'C:\Windows'
##TODO Doug ???
##it sucks at getExtendedEnv in extenvvars.py (DT/dtactions/unimacro)

thisGrammar.gotResults_remember(words, FR)



if __name__ == "__main__":
pytest.main(['test_grammar_folders.py'])

0 comments on commit e05ce8b

Please sign in to comment.