Skip to content

Editor callback function does not get cleared if used as bound method in a class #153

@Ekopalypse

Description

@Ekopalypse

Consider the following script

from Npp import editor, notepad, SCINTILLANOTIFICATION, NOTIFICATION

class X:

    def __init__(self):
        notepad.callback(self.on_buffer_activated, [NOTIFICATION.BUFFERACTIVATED])
        editor.callbackSync(self.on_double_click, [SCINTILLANOTIFICATION.DOUBLECLICK])
        editor.callbackSync(self.on_focus_out, [SCINTILLANOTIFICATION.FOCUSOUT])


    @staticmethod
    def on_double_click(args):
        # this one does get cleared
        print('on_double_click')


    def on_focus_out(self, args):
        # this doesn't get cleared :-(
        # differece to on_double_click is that this is a bound method,
        # whereas on_double_click is, basically, a function.
        print('on_focus_out')


    def on_buffer_activated(self, args):
        # Now the cofusing part, this is also a bound method but does get cleared
        # Difference: this is a notepad object callback.
        print('on_buffer_activated')


    def clear(self):
        notepad.clearCallbacks(self.on_buffer_activated, [NOTIFICATION.BUFFERACTIVATED])
        editor.clearCallbacks(self.on_double_click, [SCINTILLANOTIFICATION.DOUBLECLICK])
        editor.clearCallbacks(self.on_focus_out, [SCINTILLANOTIFICATION.FOCUSOUT])
       
try:
    active_instance
    active_instance.clear()
    del(active_instance)
except NameError:
    active_instance = X()

On first run it will register three callbacks. On next run, two out of the three callbacks get cleared but the on_focus_out callback remains active.

Happens with PythonScript version 3.0.3 as well as with 1.5.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions