How can it work? You don’t know the object instance of the listener as it is known by ST only.
The class1
you’ve created is a class not an object. If your plugin is loaded by ST, the core creates an object of class1
and stores it in sublime_plugin.view_event_listeners
dictionary. Without hacking that, you don’t have access to that object being created for your package. Therefore you can’t call read()
from any other object.
The only way to do so was to add an on_text_command()
handler to class1
and call read from that, if the command_string matches. But even this is bad practice.
import sublime_plugin
class class1(sublime_plugin.EventListener):
def __init__(self):
self.test = "hello world"
def on_text_command(self, view, command, args):
if command == 'my_text_command':
self.read()
def on_post_save(self, view):
self.test = "hello you"
def read(self):
print(self.test)
print(self)
The EventListener is a standalone interface class. You can use it to call your functions on certain events but you should/must not use it as class being accessed by your functions!