对于#1,你是对的。在 Python 中,这意味着继承。派生类定义的语法如下所示class DerivedClass(BaseClassName):
.
Python 中的继承
对于#2,Sublime Text 2 支持三种类型的命令。这run
当您运行命令时会调用方法。除了所需的参数外,您还可以定义任意数量的参数run
。当您运行带有额外参数的命令时,您需要在映射中传递这些参数。
-
ApplicationCommand:整个 Sublime Text 2 的命令。无需参数。
-
WindowCommand:窗口命令。没有必需的参数。
-
TextCommand:查看命令。一个必需的参数,
edit
.
对于#3,如何运行:
-
ApplicationCommand
: sublime.run_command('application_command_name')
. Check run_command
sublime 模块中的函数API参考.
-
WindowCommand
: window.run_command('window_command_name')
. Check run_command
的方法sublime.Window.
-
TextCommand
: view.run_command('text_command_name')
. Check run_command
的方法sublime.View
示例 1:不带额外参数的命令
import sublime, sublime_plugin
class TestApplicationCommand(sublime_plugin.ApplicationCommand):
def run(self):
print("running TestApplicationCommand")
import sublime, sublime_plugin
class TestWindowCommand(sublime_plugin.WindowCommand):
def run(self):
print("running TestWindowCommand")
import sublime, sublime_plugin
class TestTextCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("running TestTextCommand")
运行这些命令:
>>> sublime.run_command('test_application')
running TestApplicationCommand
>>> window.run_command('test_window')
running TestWindowCommand
>>> view.run_command('test_text')
running TestTextCommand
示例 2:带有额外参数的命令
import sublime, sublime_plugin
class TestApplicationCommand(sublime_plugin.ApplicationCommand):
def run(self, arg1, arg2):
print("running TestApplicationCommand")
print("arg1: " + arg1)
print("arg2: " + arg2)
import sublime, sublime_plugin
class TestWindowCommand(sublime_plugin.WindowCommand):
def run(self, arg1, arg2):
print("running TestWindowCommand")
print("arg1: " + arg1)
print("arg2: " + arg2)
import sublime, sublime_plugin
class TestTextCommand(sublime_plugin.TextCommand):
def run(self, edit, arg1, arg2):
print("running TestTextCommand")
print("arg1: " + arg1)
print("arg2: " + arg2)
运行这些命令:
>>> sublime.run_command('test_application', {'arg1' : '1', 'arg2' : '2'})
running TestApplicationCommand
arg1: 1
arg2: 2
>>> window.run_command('test_window', {'arg1' : '1', 'arg2' : '2'})
running TestWindowCommand
arg1: 1
arg2: 2
>>> view.run_command('test_text', {'arg1' : '1', 'arg2' : '2'})
running TestTextCommand
arg1: 1
arg2: 2