Skip to content

Commit

Permalink
test_grammar_control.py works sofar, also exclusive grammars (making …
Browse files Browse the repository at this point in the history
…_control also exclusive).
  • Loading branch information
quintijn committed Jan 14, 2023
1 parent 599689f commit 3d36c47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/unimacro/natlinkutilsbj.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def GetGrammarObject(self, grammarName):
return self.allGrammarXObjects[grammarName]
return None

def ControlResetExclusiveGrammar(self):
def ControlResetExclusiveGrammar(self):
"""resets the exclusive flag of the _control grammar
If the exclusive state of a/the last grammar is reset (becoming
Expand Down Expand Up @@ -392,15 +392,14 @@ def ControlSetExclusiveGrammar(self, value):
In this way, the commands of the _control grammar remain accessible when
other (Unimacro) grammars are exclusive
"""
value = value or 1
exclGr = self.getExclusiveGrammars()
if not exclGr:
return
if not self.LoadedControlGrammars:
return
if self.LoadedControlGrammars[0] is self:
return
self.LoadedControlGrammars[0].setExclusive(1)
self.LoadedControlGrammars[0].setExclusive(value)


def getRegisteredGrammarNames(self):
Expand Down Expand Up @@ -531,9 +530,11 @@ def setExclusive(self,exclusive):
self.__inherited.setExclusive(self,exclusive)
self.exclusive = exclusive

if self.LoadedControlGrammars and self is self.LoadedControlGrammars[0]:
return
self.ControlSetExclusiveGrammar(exclusive)
if self.LoadedControlGrammars:
if self is self.LoadedControlGrammars[0]:
# no extra setting if self is _control
return
self.ControlSetExclusiveGrammar(exclusive)


def cancelMode(self):
Expand Down
8 changes: 5 additions & 3 deletions tests/test_grammar_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def rule_gramoff(self, words):
"""grammar off"""
print(f'got gramoff: {words}')

def tttest_getAllGrammars(unimacro_setup):
def test_getAllGrammars(unimacro_setup):
"""see if we can get all the grammars
"""
gramon = GramOn(inifile_stem="_gramon")
Expand Down Expand Up @@ -110,6 +110,8 @@ def test_ExclusiveMode(unimacro_setup):
gramon.initialize()
gramoff = GramOff(inifile_stem="_gramoff")
gramoff.initialize()
# just to be sure (should have been done when unloading _control (utilGrammar))
gramon.UnregisterControlObject()
assert gramon.isLoaded() is True
assert gramon.isActive() is True
assert gramoff.isLoaded() is False
Expand All @@ -118,7 +120,7 @@ def test_ExclusiveMode(unimacro_setup):
gramon.setExclusive(1)
# set exclusive
gramon.setExclusive(1)
exclGr = gramon.getExclusiveGrammars()
exclGr = gramon.getExclusiveGrammars()
assert len(exclGr) == 1
gramon.setExclusive(0)
exclGr = gramon.getExclusiveGrammars()
Expand Down Expand Up @@ -150,7 +152,7 @@ def test_ExclusiveMode(unimacro_setup):



def tttest_show_all_grammars(unimacro_setup):
def test_show_all_grammars(unimacro_setup):
gramon = GramOn(inifile_stem="_gramon")
gramon.initialize()
gramoff = GramOff(inifile_stem="_gramoff")
Expand Down

0 comments on commit 3d36c47

Please sign in to comment.