Reloading Grammars when using DragonFly + WSR

74 Views Asked by At

I've recently started dabbling in DragonFly (due to mild RSI issues), and I'm using it with WSR and the wsr_module_loader_plus.py script.

One thing that I'm finding really annoying is that, whenever I tweak a grammar, I need to restart the main script. It takes a few seconds to close after I do Ctrl+C (idk why), which just adds to the tedium.

Is it possible to hot-reload the grammars via a command? I've seen a demonstration where the speaker did this, but they were using Dragon NaturallySpeaking, not WSR.

It's I'm missing something obvious here, but I'm a Python noob. If I end up figuring this out, I'll definitely post a solution... Googling hasn't helped ._.

(Alternatively, a voice command just to terminate the script could also work, but this is only making restarts faster, not getting rid of them entirely.)

1

There are 1 best solutions below

0
On

It turns out that this is actually quite simple. By copying the code within the wsr_module_loader_plus.py script and putting that in a its own command, I was able to make dragonfly reload the scripts.

This is the code in question:

import os.path
from dragonfly.loader import CommandModuleDirectory

def reload():
    path = os.path.dirname(__file__)
    directory = CommandModuleDirectory(path, excludes=[__file__])
    directory.load()

Then it's just a matter of making a command call the reload command.

That being said, I do not believe this is a perfect solution. I do not think it actually unloads any of the old grammars. I'll leave this as an answer for now, but I do not think it is the best solution.