1.背景
2.使用
"control+alt+p": pause or stop timer
"control+alt+z": make zero
3.制作过程
(1)环境
(2)自带example
1、通过Tools -> New Plugin...来打开一个初始化的插件编辑文件,它将有如下的内容:
import sublime, sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World!")
2、通过Preferences -> Browse Packages...打开Packages文件夹,在该文件夹下建立个子文件夹,名字为你想开发的插件名字,如:KeymapManager。回到插件开发的初始化编辑器页面,通过ctrl+s (Windows/Linux) orcmd+s (OS X)保存这个文件,并放到你建立的子文件夹下,文件名如:KeymapManager.py
3、通过ctrl+`快捷键打开SublimeText的控制台,执行如下的命令:
view.run_command('example')
如果你在当前文件最前面看到插入了Hello, Word!,那表明插件执行成功了。
4、ExampleCommand名字改为你想要的插件名字,如: KeymapmanagerCommand,然后就可以开发该插件对应的功能了。
5、通过官方的API文档查找你需要的接口,文档见:http://www.sublimetext.com/docs/2/api_reference.html
(3)sublime-timer
import sublime, sublime_plugin
import threading
import time
i=0
class timer(threading.Thread): #The timer class is derived from the class threading.Thread
def __init__(self, num, interval):
threading.Thread.__init__(self)
self.thread_num = num
self.interval = interval
self.thread_stop = False
def run(self): #Overwrite run() method, put what you want the thread do here
global i
while not self.thread_stop:
sublime.set_timeout(write_time,1)
i+=1
time.sleep(self.interval)
def pause(self):
self.thread_stop = True
def zero(self):
global i
i=0
thread1 = timer(1, 1)
class gtimerCommand(sublime_plugin.TextCommand):
def run(self, edit):
global thread1
thread=timer(1,1)
if thread1.isAlive():
live=True
else:
thread.start()
thread1=thread
class gtimerpauseCommand(sublime_plugin.TextCommand):
def run(self, edit):
global thread1
thread1.pause()
class gtimerzeroCommand(sublime_plugin.TextCommand):
def run(self, edit):
global thread1
thread1.zero()
def write_time():
sublime.status_message(time_manage(i))
def time_manage(time_number):
time_str='time:'+str(time_number/60)+'min '+str(time_number%60)+'s'
return time_str
(4)发布
/********************************
* 本文来自博客 “李博Garvin“
* 转载请标明出处:http://blog.csdn.net/buptgshengod
******************************************/

本文介绍了一款为Sublime Text开发的实时计时器插件。该插件能够帮助用户在编辑器内准确记录时间,适用于写作等场景。文中详细讲解了插件的使用方法及开发步骤。
1952

被折叠的 条评论
为什么被折叠?



