Sublime Forum

[SOLVED]run_command in mulitple files?

#1

Is it possible to have classes the respond to the run_command spread across multiple files?

For example, if I had a directory structure like this:

plugin_dir/
    - commands_dir/
          - __init__.py
          - bootstrap.py      # import all files into this file so plugin.py only has one import statement
          - command_1.py
          - command_2.py
          - etc...
    - plugin.py
    - menus & settings...

Could I, somehow, still call view.run_command(‘command_1’)? I’m still new to Sublime plugins and Python in general so if I’m missing something obvious, please let me know.

An alternative that I thought of was to have the commands in the command_dir just be standard classes and then (again, somehow) call a command in the plugin.py file that would use that class based on the input from the menu item. Is that a better route?

The reason I want to structure the plugin this way is because the plugin could, potentially, have a hundred commands and I don’t want the plugin.py littered with command classes.

0 Likes

#2

Take a look at how Package Control is implemented. Essentially you have from myplugin.commands import * and each command in a separate file in the commands subpackage. It’ll be slightly different if you are supporting ST3 or ST3.

0 Likes

#3

Thanks for the response. That’s exactly what I needed! I probably looked through 20 different packages looking for someone that did something similar, but couldn’t find anything. I should have known that Package Control would have what I needed :smile:

0 Likes