-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiline.py
61 lines (53 loc) · 1.83 KB
/
multiline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#-*- coding:utf-8 -*-
"""
出来れば、tkinterの部分をバックグラウンドプロセスとして処理して
"""
import weechat as w
import Tkinter as tk
import re
SCRIPT_NAME = "multiline"
SCRIPT_AUTHOR = "oidu7"
SCRIPT_VERSION = "1.0"
SCRIPT_LICENSE = "GPL"
SCRIPT_DESC = "assist to use multi line comment"
ml_font = 'KGCG-W4_NAA' # as much as possible, use font supported AA
ml_text = ""
ml_flag = False
ml_t = ml_root = None
def multi_line_text():
global ml_root, ml_t
ml_root = tk.Tk()
ml_root.option_add('*font', (ml_font, 12))
ml_root.title('multi line text')
ml_t = tk.Text(ml_root,width=30,height=10,state=tk.NORMAL)
ml_t.pack(expand=True)
b = tk.Button(ml_root,text='say (press Space)',command=ml_destroy)
b.pack(expand=True)
ml_t.focus_set()
ml_root.mainloop()
def ml_destroy():
global ml_text, ml_flag
ml_text = ml_t.get("1.0",tk.END)
ml_flag = True
ml_root.destroy()
def multi_line_cb(data,buffer,args):
global ml_text,ml_flag
if args == "test" or args=="":
multi_line_text()
if ml_flag:
ml_text = re.sub("\s+$","",ml_text)
if args == "test":
w.prnt_date_tags(w.current_buffer(), 0, "no_log", ml_text.encode('utf-8'))
elif args == "":
w.command(w.current_buffer(), ml_text.encode('utf-8'))
ml_text = ""
ml_flag = False
else:
w.prnt_date_tags(w.current_buffer(), 0, "no_log", "%smultiline: args '%s' is not defined" % (w.prefix('error'),args))
return w.WEECHAT_RC_OK
if __name__ == '__main__':
if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
w.hook_command("ml",SCRIPT_DESC,
"[test]","",
"test","multi_line_cb","")