Sublime Forum

How to move listeners to another file?

#1

I’m both new to Python and modding for Sublime Text so please forgive me if this is an obvious question.

I have a plugin located in:

Sublime Text/Data/Packages/test_plugin

With the code:

test_plugin.py

[code]import sublime, sublime_plugin

from .listeners import *

class ExampleCommand(sublime_plugin.TextCommand):

def run(self, edit):
    sublime.message_dialog("test")[/code]

I have a listener inside the following path:

Sublime Text/Data/Packages/test_plugin/listeners

completion.py

[code]import sublime_plugin
import sublime

class OnQueryCompletions(sublime_plugin.EventListener):

def on_query_completions(self, view, prefix, locations):
    sublime.message_dialog("test")[/code]

on_query_completions will fire if I copy/paste the OnQueryCompletions class into test_plugin.py but it does not work if it’s in another file that I import. How do I make this listener work from another file?

0 Likes