dictation-toolbox / aenea

Client-server library for using voice macros from Dragon NaturallySpeaking and Dragonfly on remote/non-windows hosts.
GNU Lesser General Public License v3.0
211 stars 62 forks source link

Error when using default choices #208

Open simonireilly opened 4 years ago

simonireilly commented 4 years ago

When attempting to provide a default value for a choice object in a mapping rule, The following error is observed on the remote machine running in the virtual box.

Backedtrace

Error loading _terminal from C:\NatLink\NatLink\MacroSystem\_terminal.py
Traceback (most recent call last):
  File "C:\NatLink\NatLink\MacroSystem\core\natlinkmain.py", line 322, in loadFile
    imp.load_module(modName,fndFile,fndName,fndDesc)
  File "C:\NatLink\NatLink\MacroSystem\_terminal.py", line 15, in <module>
    import cli_typescript
  File "C:\NatLink\NatLink\MacroSystem\cli_typescript.py", line 17, in <module>
    class TypescriptRule(MappingRule):
  File "C:\NatLink\NatLink\MacroSystem\cli_typescript.py", line 25, in TypescriptRule
    Choice('modifiercommand', modifiercommand, None, None)
TypeError: __init__() takes at most 4 arguments (5 given)

Inclusion

_terminal.py

# Dragonfly module for controlling the Linux terminal
# The context of this file will be strictly for terminal use

from aenea import *

import cli_typescript

terminal_context = aenea.wrappers.AeneaContext(
    ProxyAppContext(match='regex', title='(?i).*simon@simon.*'), # app_id='Terminal'
    AppContext(executable='Terminal')
    )

grammar = Grammar("terminal", context=terminal_context)

....
grammar.add_rule(cli_typescript.TypescriptRule())

Grammar

cli_typescript.py

# The rules for the typescript command line

from aenea import *

tsccommand = {
    "version": "-v ",
    "watch": "-w ",
}

modifiercommand = {
    "default": " ",
    "all": "*.ts",
}

class TypescriptRule(MappingRule):
    mapping = {
            'typescript <tsccommand> <modifiercommand>': Text('tsc %(tsccommand)s'),
        }
    extras = [
        Dictation("text"),
        IntegerRef("n", 1, 100),
        Choice('tsccommand', tsccommand),
        Choice('modifiercommand', modifiercommand, None, "default")
    ]
    defaults = {
        "n": 1,
    }
calmofthestorm commented 4 years ago

Nothing obvious is jumping out at me here. Both the old and new Dragonfly's Choice takes four arguments (plus implicit self), as do the testing mock and aenea's, so I'd expect this to work. Might try adding logging to see what exactly is being imported as Choice (I think you can just use print Choice before the crash and it should print to the Natlink window messages?) That should give you the filename where Choice is coming from, which would give more information. I don't know of a version in Aenea or related projects that takes 4 arguments (including self).

Most likely a configuration or install issue, though it's been awhile since I've worked actively on this. May also be worth asking on the dictation-toolbox Gitter.

simonireilly commented 4 years ago

Thanks for the response. I have a work around as: https://github.com/simonireilly/aenea/blob/master/dragonfly_grammars/cli_typescript.py.

Using the defaults of the mapping rule and with the Choice being optional. Not pretty but works.

I expected it was probably an import issue but I setup my remote vdi last year and just restore it from the cloud on new machines.

Love this project, kept me in a job during 5 months of RSI, thanks for your work 👍