对于#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')
。API参考中run_command
有关sublime模块的检查功能。WindowCommand
:window.run_command('window_command_name')
。的检查run_command
方法sublime.Window
。TextCommand
:view.run_command('text_command_name')
。检查run_command
方法sublime.View
示例1:不带额外参数的命令
import sublime, sublime_pluginclass TestApplicationCommand(sublime_plugin.ApplicationCommand): def run(self): print("running TestApplicationCommand")import sublime, sublime_pluginclass TestWindowCommand(sublime_plugin.WindowCommand): def run(self): print("running TestWindowCommand")import sublime, sublime_pluginclass 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_pluginclass TestApplicationCommand(sublime_plugin.ApplicationCommand): def run(self, arg1, arg2): print("running TestApplicationCommand") print("arg1: " + arg1) print("arg2: " + arg2)import sublime, sublime_pluginclass TestWindowCommand(sublime_plugin.WindowCommand): def run(self, arg1, arg2): print("running TestWindowCommand") print("arg1: " + arg1) print("arg2: " + arg2)import sublime, sublime_pluginclass 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 TestApplicationCommandarg1: 1arg2: 2>>> window.run_command('test_window', {'arg1' : '1', 'arg2' : '2'})running TestWindowCommandarg1: 1arg2: 2>>> view.run_command('test_text', {'arg1' : '1', 'arg2' : '2'})running TestTextCommandarg1: 1arg2: 2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)