Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

key callback not registering

Help
prozaker
2010-11-18
2013-01-25
  • prozaker
    prozaker
    2010-11-18

    Hello I'm trying to register a call back but neither of these ways work:

    def keypressed(args):
        console.write(str(args))
    notepad.callback(keypressed, [SCINTILLANOTIFICATION.KEY])
    editor.callback(keypressed, [SCINTILLANOTIFICATION.KEY])
    

    Thanks in advance

     
  • The one you mean is

    editor.callback(keypressed, [SCINTILLANOTIFICATION.KEY])
    

    notepad.callback uses the NOTIFICATION enum, not the SCINTILLANOTIFICATION.  But, I expect that's not the notification you wanted - according to the scintilla documentation - (http://www.scintilla.org/ScintillaDoc.html)

    SCN_KEY
    Reports all keys pressed but not consumed by Scintilla. Used on GTK+ because of some problems with keyboard focus and is not sent by the Windows version. SCNotification.ch holds the key code and SCNotification.modifiers holds the modifiers. This notification is sent if the modifiers include SCMOD_ALT or SCMOD_CTRL and the key code is less than 256.

    So, you'll only get keys that don't have any effect in Scintilla…  I'm assuming that's not what you wanted?

    Take a look at SCINTILLANOTIFICATION.CHARADDED  (SCN_CHARADDED in the Scintilla documentation).   Of course without knowing what you're trying to achieve, it's difficult to say :)

    Be aware that clearing events is unstable when called from within an event handler in 0.7.  This is fixed in 0.8.

    Cheers,
    Dave.

     
  • prozaker
    prozaker
    2010-11-18

    Hi Dave, well let me give you an insight of what I i'm trying to do.

    I have a py file that holds 2 clases, one for filepositions and filepositioncollection

    fileposition collection gets the line # of the bufferid and stores that as a fileposition object, everytime a new line is modified it saves the line #.

    what i want to do (which happens in eclipse, and used to happen in npp with changemarkers) is to jump through the lines i've have modified.

    since change markers is unstable in current npp…

    https://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Plugin_Central

    maybe i should do a script for forward and backward keys, and then set those up as shortcuts, i was thinking of alt+up and alt+down?

     
  • Yes, the best way to do this is to create two new scripts, and assign them shortcuts.

    Incidentally, Change Markers is only "unstable" if you use Save-All, or "replace in all open documents".

    Dave.

     
  • arntof
    arntof
    2010-11-20

    hi,
    I tried this

    console.show()
    notepad.clearCallbacks([SCINTILLANOTIFICATION.CHARADDED])
    def do_sth(args):
        console.write("args: " + str(args))
    notepad.callback(do_sth, [SCINTILLANOTIFICATION.CHARADDED])
    

    but as I am typing nothing happens.
    I'm a brand new n++ python script user - am I overlooking something here?

    thanks in advance.

     
  • You need to use

    editor.callback(do_sth, [SCINTILLANOTIFICATION.CHARADDED])
    

    editor is the Scintilla object, so anything to do with the text area is normally the editor object.  Notepad object is for things like opening and saving files, running menu options and so on.  The notepad.callback function also uses the NOTIFICATION enum, not the SCINTILLANOTIFICATION enum.

    Cheers,
    Dave.

     
  • arntof
    arntof
    2010-11-20

    thanks!