Errors with Notepad++ application

I am trying to use the Notepad++ (free programming editor), but I keep getting the following error when I try to dictate into it. Note that it doesn't prevent me from dictating into notepad++, it just produces this annoying error all the time.

I'm not sure it's a problem with natlink or vocola or both.

Traceback (most recent call last):
  File "C:\PROGRA~1\NatLink\macrosystem\_vocola_main.py", line 240, in vocolaBeginCallback
    beginCallback(moduleInfo)
  File "C:\PROGRA~1\NatLink\macrosystem\core\natlinkmain.py", line 273, in beginCallback
    loadModSpecific(moduleInfo,1)
  File "C:\PROGRA~1\NatLink\macrosystem\core\natlinkmain.py", line 251, in loadModSpecific
    findAndLoadFiles(curModule)
  File "C:\PROGRA~1\NatLink\macrosystem\core\natlinkmain.py", line 192, in findAndLoadFiles
    pat = re.compile(r"""
  File "C:\Python23\Lib\sre.py", line 179, in compile
    return _compile(pattern, flags)
  File "C:\Python23\Lib\sre.py", line 230, in _compile
    raise error, v # invalid expression
sre_constants.error: multiple repeat

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

natlinkmain does not accept

natlinkmain does not accept "+" in filenames, therefore notepad++ is not accepted.

I changed this on sourceforge (natlink project), you could try the new natlinkmain.py from there (put it in the macrosystem/core folder and restart natspeak.

I am not sure however notepad++ is accepted. But you could try this.

Quintijn

thanks for your reply. I did

thanks for your reply. I did as you direct, but it didn't help. FYI,
I did get the following new error:

Traceback (most recent call last):
  File "C:\PROGRA~1\NatLink\macrosystem\core\natlinkmain.py", line 330, in changeCallback
    beginCallback(moduleInfo, checkAll=1)
  File "C:\PROGRA~1\NatLink\macrosystem\core\natlinkmain.py", line 312, in beginCallback
    loadModSpecific(moduleInfo)  # in checkAll or checkForGrammarChanges mode each time
  File "C:\PROGRA~1\NatLink\macrosystem\core\natlinkmain.py", line 288, in loadModSpecific
    findAndLoadFiles(curModule)
  File "C:\PROGRA~1\NatLink\macrosystem\core\natlinkmain.py", line 224, in findAndLoadFiles
    pat = re.compile(r"""
  File "C:\Python23\Lib\sre.py", line 179, in compile
    return _compile(pattern, flags)
  File "C:\Python23\Lib\sre.py", line 230, in _compile
    raise error, v # invalid expression
sre_constants.error: multiple repeat

so we better forget about

so we better forget about filenames with "+" in it. Must be a workaround, eg renaming the exe file.

Quintijn

The problem here is another

The problem here is another bug in NatLink; in the original code:

def findAndLoadFiles(curModule=None):
    global loadedFiles

    if curModule:
        pat = re.compile(r"""
            ^(%s        # filename must match module name
            (_\w+)?)    # optional underscore followed by text
            [.]py$      # extension .py
          """%curModule, re.VERBOSE|re.IGNORECASE)
    else:

(sorry, I don't know how to keep the indentation.)

Note that curModule, an arbitrary string, is being treated as a regular expression rather than a verbatim string. Hence the crash when it is an invalid regular expression like "++".

Fixing this requires quoting the special characters in curModule. An example of how to do this can be found in the new version of Vocola, 2.5.5:

    # Load command files for specific application
    def loadSpecificFiles(self, module):
        special = re.compile(r'([][()^$.+*?{\\])')
        pattern = "^" + special.sub(r'\\\1', module)
        pattern += "(_[^@]*)?(@" + special.sub(r'\\\1', self.machine)
        pattern += ")?\.vcl$"
        p = re.compile(pattern)

It shouldn't be too hard to adapt this to the NatLink case.

I made the changes you

I made the changes you indicated. For reference, here is the changed module (I can't indent either):

    if curModule:
        special = re.compile(r'([][()^$.+*?{\\])')
        pattern = "^(" + special.sub(r'\\\1', curModule)+"(_\w+)?)"
        pattern += "[.]py$"
        pat = re.compile(pattern,re.VERBOSE|re.IGNORECASE)

Just for future reference, how do you debug natlink code? I just keep trying and occasionally put in a displayText call every now and then, but there's got to be a better way.

admin's picture

reckoner wrote: I made the

reckoner wrote:

I made the changes you indicated. For reference, here is the changed module (I can't indent either):

    if curModule:
        special = re.compile(r'([][()^$.+*?{\\])')
        pattern = "^(" + special.sub(r'\\\1', curModule)+"(_\w+)?)"
        pattern += "[.]py$"
        pat = re.compile(pattern,re.VERBOSE|re.IGNORECASE)

Just for future reference, how do you debug natlink code? I just keep trying and occasionally put in a displayText call every now and then, but there's got to be a better way.

For future reference, you can use the <pre> and </pre> tags (which retain formatting) instead of the <code> and </code> tags.

Using it, your above code looks like this:

    if curModule:
        special = re.compile(r'([][()^$.+*?{\\])')
        pattern = "^(" + special.sub(r'\\\1', curModule)+"(_\w+)?)"
        pattern += "[.]py$"
        pat = re.compile(pattern,re.VERBOSE|re.IGNORECASE)

You will notice that it retained the original indentation and the blank line you had at the bottom.

Hope that helps!
Skip

Thanks! Like Q., I also

Thanks! Like Q., I also mostly use print's to debug.

Thanks reckoner, I will test

Thanks reckoner, I will test them on my system also.

Testing: unimacro has some unittest things now. unittest unimacro

Testing natlink is also brought under unittest procedures, look in the PyTest folder of natlink on sourceforge.

Debugging mostly by inserting print statements or a debug options. Look in natlinkmain.py for examples, eg debugLoad = 0 (or 1, 2, ...).

Other debugging methods are very hard to do.

Quintijn

Debugging Natlink

I did find a way to debug Natlink with breakpoints and the ability to attach to process. Unfortunately it costs money. I'm considering buying it but if anyone knows an open-source alternative I'd be interested. The method I've discovered is as follows:

1. Install Wing IDE http://www.wingware.com/, you can get a 30 day trial but after that it costs $35.

2. Install perl (required for changes to vocola generator)

3. Add the line: import wingdbstub, to the file:

C:\Program Files\NatLink\Vocola\Exec\vcl2py.pl

sub emit_file_header

...
import wingdbstub #add this
import win32api
import win32com.client
import natlink
...

4. Change the file
C:\Program Files\NatLink\macrosystem\_vocola_main.py

The line: usePerl = 0 needs to be changed to:

usePerl = 1

5. Make a few settings changes in Wing IDE.

Table of Contents >> Wing IDE Personal Reference Manual >> Advanced Debugging Topics >> Debugging Externally Launched Code

6. Restart Dragon, and you should be able to use wingdb.

It really isn't that difficult, and can be very helpful.

Again, if anyone has any open source ways to do this... I'd love to know.

Derek

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.




view recent posts