Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using default choices #208

Open
simonireilly opened this issue Jan 19, 2020 · 2 comments
Open

Error when using default choices #208

simonireilly opened this issue Jan 19, 2020 · 2 comments

Comments

@simonireilly
Copy link

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
Copy link
Member

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
Copy link
Author

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants