-
Notifications
You must be signed in to change notification settings - Fork 0
/
describe.py
executable file
·87 lines (70 loc) · 1.78 KB
/
describe.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/python
from description import describe
import db
import sys,os,tempfile
from mmap import mmap
from delete import findId
if len(sys.argv) > 1:
which = findId(sys.argv[1])
import subprocess as s
@describe(which,manual=True)
def _(oldblurb,changed):
temp = tempfile.NamedTemporaryFile(suffix=".html")
if oldblurb:
print("old",oldblurb)
temp.write(oldblurb.encode("utf-8"))
temp.flush()
editor = os.environ.get("EDITOR","emacs")
s.call([editor,temp.name])
buf = mmap(temp.fileno(),0)
temp.close()
with buf:
changed(buf[:])
raise SystemExit
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib, Gdk, Gio
def edit(which):
@describe(which,manual=True)
def _(oldblurb,changed):
temp = tempfile.NamedTemporaryFile(suffix=".html")
if oldblurb:
print("old",oldblurb)
temp.write(oldblurb.encode("utf-8"))
temp.flush()
editor = os.environ.get("EDITOR","emacs")
s = Gio.Subprocess.new([editor,temp.name],
Gio.SubprocessFlags.NONE)
@partial(s.wait_async,None)
def _(s, res):
buf = mmap(temp.fileno(),0)
temp.close()
with buf:
changed(buf[:])
from functools import partial
input = lambda p: None
win = Gtk.Window()
loop = GLib.MainLoop()
win.connect("delete-event", lambda *a: loop.quit())
grid = Gtk.Grid()
win.add(grid)
entry = Gtk.Entry()
grid.add(entry)
b = Gtk.Button(label="Paste")
grid.add(b)
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
def gotclip(c,text):
try: entry.set_text('%x'%findId(text))
except ValueError: pass
@partial(b.connect,"clicked")
def _(b):
clipboard.request_text(gotclip)
# initial guess
clipboard.request_text(gotclip)
b = Gtk.Button(label="Edit")
grid.add(b)
@partial(b.connect,"clicked")
def _(b):
edit(int(entry.get_text(),0x10))
win.show_all()
loop.run()