Sublime Forum

Trigger InputHandler implemented in other package

#1

Hi all,
I am developing a plugin (foobar.py) that I would like to separate into two different plugins.

In foo.py:

class FooCommand(sublime_plugin.WindowCommand):
    def run(self, foo_arg):
        pass

    def input(self, args):
        return FooArgInputHandler()

FooArgInputHandler() would also be implemented in foo.py.

In bar.py, I would like to implement something like this:

class BarCommand(sublime_plugin.WindowCommand):

    def run(self, bar_arg):
        # does something with bar_arg
        self.window.run_command('foo')

    def input(self, args):
        return BarArgInputHandler()

because no args are provided when calling run_command, then I would expect Sublime to instantiate and display FooArgInputHandler. Instead, I get an error:

run() missing 1 required positional argument: 'foo_arg'

My workaround is that BarArgInputHandler() has a next_input() to return FooArgInputHandler(), then BarCommand.run takes two arguments (bar_arg, foo_arg) and I can run foo command with foo_arg.

But then I cannot separate foobar.py into two different plugins, because I don’t know how to import FooArgInputHandler() from bar.py.

I think that this use case should be very common, and most probably I am doing something obviously wrong. Can you help me?

Many thanks!

0 Likes

#2

Did you make sure that the foo command is available in the command palette ? One of the requirements to successfully implement an InputHandler is to make sure that the command invoking it’s instance via input method should be present in the command palette i.e. an entry in the .sublime-commands file adding the foo command to the palette.

1 Like

#3

Ok, so that was it. I added foo command to the palette and now it works as expected.
Thank you very much for your help. I knew there should be an easy way!

0 Likes