我想处理一个事件,当我为我正在为 Sublime Text 2 编写的插件更改位于 Preferences.sublime-settings
内的 color_scheme
设置时,该事件会触发。
我已经 read 使用 EventListener
的 on_window_command
但它似乎没有触发。
class MyPluginEvents(sublime_plugin.EventListener):
def on_window_command(self, window, command_name, args):
print " --- FIRE! --- "
我也尝试过 post_window_command
但没有成功。有什么方法可以检测偏好设置何时发生变化吗?
最佳答案
您链接到的那些文档适用于 ST3。 Here是 ST2 的文档。请注意,没有 on_window_command
。除此之外,您可能需要查看Settings#add_on_change
。我以前从未在 API 中使用过该方法,但根据描述,它应该可以执行您想要的操作。
编辑
知道您已经有了解决方案,但请为其他人添加此解决方案。
您可能会绑定(bind)到一个事件,例如 on_load
或 on_new
,以便该命令将在任何新创建的 View 上运行。
import sublime_plugin
class TestCommand(sublime_plugin.TextCommand):
def run(self, edit):
settings = self.view.settings()
settings.add_on_change("color_scheme", self.callback)
def callback(self):
print(self.view.settings().get("color_scheme"))
关于python - 如何在 Sublime Text 2 中检测 set_user_setting 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19879612/