dictation-toolbox / natlink

Natlink provides the interface between Dragon and python
Other
25 stars 17 forks source link

DPI 16: Deactivating one rule of a grammar can deactivate all the rules of that grammar #179

Closed LexiconCode closed 6 months ago

LexiconCode commented 8 months ago

mdbridge (Mark) "There is a Dragon bug where deactivating one rule of a grammar can deactivate all the rules of that grammar. I have worked around this in Vocola 2.9 by first determining if any deactivation's are needed, and if so deactivating all rules in that case before doing any activations. I expect this bug also affects dragonfly."

quintijn commented 7 months ago

This should be examined with some pytest test scripts in either https://github.com/dictation-toolbox/natlink/tree/master/pythonsrc/tests or in https://github.com/dictation-toolbox/natlinkcore/tree/main/tests (this latter directory seems preferable to me).

quintijn commented 7 months ago

Possibly I have a way to work around the deactivate issue.

Quick and dirty, and not able to test just now, as (1) I work on Dragon 15 (2) I have no test environment ready. But here it runs as it seems. See attached my komodo file (.vcl and generated .py).

In my scripts komodo_vcl.py with modified "activate_rule", seems to be running fine with Dragon 15. Note the switch dpi16trick!

When you want to try, please patch attached natlinkutils.py into the natlinkcore directory

The changes are in attached image.

With these changes I got (again with Dragon 15) the things running.

    def activate_rule(self, rule, window, status):
        current = self.rule_state.get(rule)
        active = (current == window)
        if status == active: return
        print(f'current: {current}, window: {window}, active: {active}, status: {status}, activeRules: {list(self.activeRules.keys())}')
        if current:
            print(f'current: {current}, deactivate rule {rule}')
            self.deactivate(rule, dpi16trick=True)
            self.rule_state[rule] = None
        if status:
            try:
                print(f'new: {window}, activate rule {rule}')

                self.activate(rule, window)
                self.rule_state[rule] = window
            except natlink.BadWindow:
                pass #

here the results of Messages from Natlink, with comments.

So modified def deactivate in grammarBase, natlinkutils.py line 750.

and above function in komodo_vcl.py file:

reloading module: komodo_vcl loading module: natspeak_vcl

first command (with .txt file in focus)

current: None, window: 131534, active: False, status: True, activeRules: [] new: 131534, activate rule sequence

switch to .py file:

current: None, window: 131534, active: False, status: True, activeRules: ['sequence'] new: 131534, activate rule sequence_set2

back to .txt file, with "new" trick sequence_set2 is deactivated:

current: 131534, window: 131534, active: True, status: False, activeRules: ['sequence', 'sequence_set2'] current: 131534, deactivate rule sequence_set2

once more, with .py file in focus:

current: None, window: 131534, active: False, status: True, activeRules: ['sequence'] new: 131534, activate rule sequence_set2

and finish with .txt file

current: 131534, window: 131534, active: True, status: False, activeRules: ['sequence', 'sequence_set2'] current: 131534, deactivate rule sequence_set2

Again, I lack the possibilities of running the unittests, as I want to convert the tests one by one to pytest. If anybody can do a quick patch, we can see if this is a chance to fix this issue. It is only 1 function, around line 750, renamed the python file to .txt

Greetings, Quintijn

changes natlinkutils py_2024-01-04 natlinkutils - Copy.txt komodo_vcl - Copy.txt komodo - Copy.vcl.txt

quintijn commented 7 months ago

And I should study markdown...

quintijn commented 7 months ago

I made good progress to solving this issue, in a way, that the code also works for Dragon 15 (and therefore probably back to 13).

I will do a few more testing, and then make a new version of natlinkcore. (a pip install --upgrade natlinkcore will do)

quintijn commented 7 months ago

Succes seems to be there!!!

I am about to accept my own PR into the natlinkcore repository...

quintijn commented 7 months ago

All committed to natlinkcore, new pip release natlinkcore 5.3.8

quintijn commented 6 months ago

I think we can safely close this issue as solved!!!