diff --git a/src/unimacro/natlinkutilsbj.py b/src/unimacro/natlinkutilsbj.py index 65153e5..e1afd0b 100644 --- a/src/unimacro/natlinkutilsbj.py +++ b/src/unimacro/natlinkutilsbj.py @@ -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 @@ -392,7 +392,6 @@ 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 @@ -400,7 +399,7 @@ def ControlSetExclusiveGrammar(self, value): return if self.LoadedControlGrammars[0] is self: return - self.LoadedControlGrammars[0].setExclusive(1) + self.LoadedControlGrammars[0].setExclusive(value) def getRegisteredGrammarNames(self): @@ -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): diff --git a/tests/test_grammar_control.py b/tests/test_grammar_control.py index 7898857..2bd2c91 100644 --- a/tests/test_grammar_control.py +++ b/tests/test_grammar_control.py @@ -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") @@ -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 @@ -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() @@ -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")